Generate Lyrics Endpoint

Overview

Generates lyrics based on a text prompt. Uses queue management to prevent rate limiting and serializes requests per account.

🔗 Quick Links

Endpoint

POST /api/generate_lyrics
POST /[accountId]/api/generate_lyrics

Request

Headers

Content-Type: application/json

Body (JSON)

prompt (string, required)
Text prompt describing the lyrics to generate

Example Request

curl -X POST https://your-domain.com/api/generate_lyrics \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A love song about summer nights"
  }'
const response = await fetch('/api/generate_lyrics', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: 'A love song about summer nights'
  })
});

Response

Success Response (200 OK)

Returns generated lyrics:

{
  "text": "Verse 1:\nUnder the stars we dance\nSummer nights so sweet\n...",
  "lyrics_a_id": "lyrics-id-12345",
  "status": "complete"
}

Status Code: 200
Content-Type: application/json

Payment Required (402)

When account credits are insufficient:

{
  "error": "Insufficient credits"
}

Status Code: 402
Content-Type: application/json

Internal Server Error (500)

When an error occurs:

{
  "error": "Internal server error: [error details]"
}

Status Code: 500
Content-Type: application/json

Method Not Allowed (405)

When using an unsupported HTTP method:

Status Code: 405
Headers: Allow: POST

Notes

  • Queue Management: Requests are automatically queued per account to prevent rate limiting
  • Serialization: Only one lyrics generation request runs at a time per account
  • Metrics: Request duration and status are tracked for analytics
  • All responses include CORS headers

Rate Limiting

This endpoint uses queue management to prevent 429 (rate limit) errors:

  • Requests for the same account are serialized (one at a time)
  • Automatic delays between requests prevent rate limiting
  • No manual retry logic needed