Skip to main content

Complete Workflow

This guide walks through the full flow of generating music with sunor: authenticate, create a task, poll until it completes, and use the audio output.

Prerequisites

  • A sunor account with an API key
  • Credits in your account (music costs 10 credits)

Step 1: Create a task

Submit a music generation request:
The example below uses Suno’s input shape (gpt_description_prompt, make_instrumental). Udio uses a different shape (prompt, lyrics_type) — see /models/udio before adapting this snippet to "model": "udio".
The response returns a task_id with status "pending". Credits are frozen immediately. Before that point, Sunor validates the body and the selected model/task input. A 400 validation response happens before any credit freeze, task insert, or upstream-provider call. Record the response’s X-Request-Id header so an individual attempt can be correlated across agent logs and Sunor support.
If the create request ends with a network error or an uncertain 5xx response, do not submit the same payload again automatically. The current create endpoint does not yet provide Idempotency-Key replay semantics. If you received a task_id, continue polling that task.

Step 2: Poll for results

Tasks take 30 seconds to 5 minutes to complete. Poll every 5-10 seconds until the status is terminal (success, failure, or timeout).

Step 3: Use the output

On success, the output.result contains an array of generated clips:

Downloading the audio

Audio URLs point to the generated audio file. Take the file extension from the response’s Content-Type rather than hard-coding one — the container format is determined upstream and has changed before. You can download them directly:

Full example

Putting it all together:

Next steps

Music generation modes

Learn about inspiration, custom, and continuation modes.

Error handling

Handle errors and implement retries.

Rate limits

Stay within rate limits with smart polling.

API Reference

Full endpoint documentation.