API Reference

The GenerateSongs API lets you generate AI-powered songs programmatically. Use it to integrate song generation into your apps, workflows, or creative tools.

Base URL
https://generatesongs.ai/api/v1

Authentication

All API requests require a valid API key passed in the Authorization header.

Header format
Authorization: Bearer gs_your_api_key

Create API keys from the API Keys page. Keep your keys secret — do not share them or expose them in client-side code.

Error Handling

The API returns standard HTTP status codes. Error responses include a JSON body with an error field.

StatusMeaning
400Bad Request — invalid parameters
401Unauthorized — invalid or missing API key
402Payment Required — insufficient credits
404Not Found — resource doesn't exist
500Internal Server Error
Error response
{
  "error": "'style' is required and must be a non-empty string"
}
POST/songs/generate

Generate a new song. Consumes 1 credit.

ParameterTypeRequiredDescription
stylestringYesMusic style, genre, mood (1-1024 chars)
lyricsstringNoSong lyrics (max 3000 chars). Omit for AI-generated.
instrumentalbooleanNoGenerate instrumental only (default: false)
titlestringNoSong title (max 50 chars)
vocalGenderstringNo'male' or 'female' — auto if omitted
referenceFileIdstringNoReference audio file ID from upload
vocalFileIdstringNoVocal reference file ID from upload
melodyFileIdstringNoMelody idea file ID (standalone only)
Request
curl -X POST https://generatesongs.ai/api/v1/songs/generate \
  -H "Authorization: Bearer gs_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"style": "upbeat pop", "title": "Summer Vibes", "vocalGender": "female"}'
Response (201)
{
  "songId": "abc123def456",
  "status": "processing"
}

File reference rules: melodyFileId cannot be combined with referenceFileId or vocalFileId. referenceFileId can be combined with vocalFileId only.

GET/songs/:songId

Get the status and details of a generated song. Poll this endpoint to check if generation is complete.

ParameterTypeRequiredDescription
songIdstringYesSong ID (URL parameter)
Request
curl https://generatesongs.ai/api/v1/songs/abc123 \
  -H "Authorization: Bearer gs_your_api_key"
Response (200)
{
  "id": "abc123def456",
  "status": "completed",
  "title": "Summer Vibes",
  "style": "upbeat pop",
  "lyrics": "[Verse 1]\\nSunshine on my face...",
  "duration": 187,
  "downloadUrl": "https://generatesongs.ai/api/v1/songs/abc123?download",
  "flacDownloadUrl": "https://generatesongs.ai/api/v1/songs/abc123?download&format=flac",
  "isInstrumental": false,
  "createdAt": "2026-02-28T12:00:00Z"
}

Status values

StatusDescription
pendingSong created, waiting to be picked up by the generation provider
processingActively being generated — poll again in 5-10 seconds
completedGeneration finished — audio is ready to download via downloadUrl
failedGeneration failed — credit is automatically refunded
GET/songs/:songId?download

Download the generated audio file. Available in MP3 (default) and FLAC (lossless) formats. Only available for completed songs. Supports Range headers for streaming.

ParameterTypeRequiredDescription
songIdstringYesSong ID (URL parameter)
formatstringNo'mp3' (default) or 'flac' for lossless audio
Download MP3
curl -OJ 'https://generatesongs.ai/api/v1/songs/abc123?download' \
  -H "Authorization: Bearer gs_your_api_key"
Download FLAC (lossless)
curl -OJ 'https://generatesongs.ai/api/v1/songs/abc123?download&format=flac' \
  -H "Authorization: Bearer gs_your_api_key"
GET/songs

List all songs associated with your account, ordered newest first. Supports pagination.

ParameterTypeRequiredDescription
offsetintegerNoPagination offset (default: 0)
limitintegerNoResults per page (default: 20)
Response (200)
{
  "songs": [{
    "id": "abc123",
    "status": "completed",
    "title": "Summer Vibes",
    "style": "upbeat pop",
    "lyrics": "[Verse 1]\\n...",
    "duration": 187,
    "downloadUrl": "...?download",
    "flacDownloadUrl": "...?download&format=flac",
    "isInstrumental": false,
    "createdAt": "2026-02-28T12:00:00Z"
  },
  ...
  ],
  "total": 42,
  "hasMore": true
}
GET/credits

Check your current credit balance.

Response (200)
{
  "balance": 42
}
GET/credits/history

Get your credit purchase history, including remaining credits and expiration dates for each purchase.

Response (200)
{
  "balance": 42,
  "history": [
    {
      "id": 1,
      "amount": 50,
      "remaining": 42,
      "packName": "Popular",
      "purchasedAt": "2026-01-15T10:00:00Z",
      "expiresAt": "2026-07-15T10:00:00Z",
      "isExpired": false
    }
  ]
}
POST/files/upload

Upload an audio file for use as a reference, vocal sample, or melody idea in song generation.

ParameterTypeRequiredDescription
filebinaryYesAudio file (mp3, m4a, mid). Max 10MB.
purposestringYesreference, vocal, melody, or instrumental
Request (multipart form)
curl -X POST https://generatesongs.ai/api/v1/files/upload \
  -H "Authorization: Bearer gs_your_api_key" \
  -F "file=@reference.mp3" \
  -F "purpose=reference"
Response (200)
{
  "id": "file_abc123",
  "filename": "reference.mp3",
  "purpose": "reference"
}
POST/ai/optimize

Improve existing lyrics using AI — fix rhythm, rhyme, flow, and emotional impact. Does not consume credits.

ParameterTypeRequiredDescription
lyricsstringYesLyrics to optimize (max 5000 chars)
stylestringNoStyle hint for optimization context
Response (200)
{
  "lyrics": "[Verse 1]\\nImproved lyrics here..."
}
POST/ai/generate-lyrics

Generate original song lyrics using AI based on a style description. Does not consume credits.

ParameterTypeRequiredDescription
stylestringYesMusic style to write lyrics for
topicstringNoOptional topic or theme
Response (200)
{
  "lyrics": "[Verse 1]\\nGenerated lyrics here..."
}
POST/ai/suggest-tags

Get AI-suggested style tags that complement your current input. Does not consume credits.

ParameterTypeRequiredDescription
inputstringYesCurrent style description
Response (200)
{
  "tags": ["Acoustic", "Dreamy", "Reverb", "Indie"]
}

Code Examples

cURL

Generate and poll
# Generate a song
RESPONSE=$(curl -s -X POST https://generatesongs.ai/api/v1/songs/generate \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"style": "chill lo-fi hip hop"}')

SONG_ID=$(echo $RESPONSE | jq -r '.songId')

# Poll until complete
while true; do
  STATUS=$(curl -s https://generatesongs.ai/api/v1/songs/$SONG_ID \
    -H "Authorization: Bearer $API_KEY" | jq -r '.status')
  [ "$STATUS" = "completed" ] && break
  sleep 10
done

# Download MP3
curl -OJ 'https://generatesongs.ai/api/v1/songs/$SONG_ID?download' \
  -H "Authorization: Bearer $API_KEY"

# Download FLAC (lossless)
curl -OJ 'https://generatesongs.ai/api/v1/songs/$SONG_ID?download&format=flac' \
  -H "Authorization: Bearer $API_KEY"

JavaScript

Node.js / Bun
const API_KEY = process.env.GENERATESONGS_API_KEY;
const BASE = "https://generatesongs.ai/api/v1";

async function generateSong(style) {
  const res = await fetch(`${BASE}/songs/generate`, {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ style }),
  });

  const { songId } = await res.json();

  // Poll for completion
  while (true) {
    const song = await fetch(
      `${BASE}/songs/${songId}`,
      { headers: { "Authorization": `Bearer ${API_KEY}` } }
    ).then(r => r.json());

    if (song.status === "completed") return song;
    if (song.status === "failed") throw new Error("Generation failed");
    await new Promise(r => setTimeout(r, 10000));
  }
}

const song = await generateSong("dreamy synthwave");
console.log(song.downloadUrl);

Python

Python 3
import requests, time, os

API_KEY = os.environ["GENERATESONGS_API_KEY"]
BASE = "https://generatesongs.ai/api/v1"
headers = {"Authorization": f"Bearer {API_KEY}"}

# Generate
res = requests.post(
    f"{BASE}/songs/generate",
    headers=headers,
    json={"style": "ambient electronic"}
)
song_id = res.json()["songId"]

# Poll
while True:
    song = requests.get(
        f"{BASE}/songs/{'{song_id}'}",
        headers=headers
    ).json()
    if song["status"] == "completed":
        break
    time.sleep(10)

# Download
audio = requests.get(song["downloadUrl"], headers=headers)
with open("song.mp3", "wb") as f:
    f.write(audio.content)

Webhooks

Coming Soon

Webhook support for real-time generation status updates is in development. Currently, use polling to check song status.

SDKs

Coming Soon

Official SDKs for JavaScript/TypeScript, Python, and Go are planned. In the meantime, use the REST API directly with any HTTP client.