Skip to main content
The text-to-music endpoint uses an asynchronous “submit + query” model: first create a generation task and obtain a task_id, then poll the task status until it reaches the SUCCESS or FAILED terminal state.
Music generation is a long-running autoregressive task. Generating a complete song usually takes from tens of seconds to a few minutes.

Endpoint

POST https://api.stepfun.ai/v1/audio/music

Capabilities

Three task types are provided, covering four use cases: When text_to_music is used without lyrics, the server generates the lyrics automatically.

Common Conventions

Request Headers

Unified Error Response

All non-2xx responses use the following structure:
Clients should branch programmatically on error.type and should not match against the message text. The response also returns an x-should-retry header:
  • Parameter, authentication, and resource errors (400 / 401 / 404): false
  • Rate limiting and transient service failures (429 / 500 / 503): true
  • Quota-related 429s cannot be resolved by retrying and must still be handled separately based on error.type.
Audio input fields use the Base64 string of the raw file bytes, without the data: prefix.

Submit a Music Generation Task

POST https://api.stepfun.ai/v1/audio/music/submit

Request Parameters

  • task string required
    Task type. Supports text_to_music, music_cover, and vocal_to_music.
  • model_id string required
    Music model identifier. Fixed to stepaudio-3-music-preview.
  • caption string required
    Style description such as genre, vocals, emotion, and key.
  • lyrics string optional
    Lyrics, with support for song-structure tags. Required for music_cover and vocal_to_music; for text_to_music, the server writes the lyrics automatically when omitted.
  • instrumental boolean optional
    Whether to generate a pure instrumental. Default false. Only supported by text_to_music.
  • song_audio string optional
    Base64 encoding of the complete reference song. Required for music_cover.
  • vocal_audio string optional
    Base64 encoding of the dry vocal without accompaniment. Required for vocal_to_music.
  • response_format string optional
    Output format. Supports wav, flac, opus, mp3, and pcm. Default wav.
  • sample_rate integer optional
    Output sampling rate. Default 48000; when omitted or set to 0, the model’s native sampling rate is kept.
  • bit_rate integer optional
    MP3 / Opus bit rate, in kbps.
  • lyrics_rewrite boolean optional
    Whether to rewrite the provided lyrics. Default false.
  • disable_caption_rewrite boolean optional
    Whether to skip automatic rewriting of caption. Default false.
  • max_tokens integer optional
    Upper limit on generated tokens. Default 16000.
  • temperature number optional
    Sampling temperature. Default 0.85; 0 is not currently supported.
  • top_k integer optional
    Sampling parameter. Default 80.
  • top_p number optional
    Sampling parameter. Default 0.92.
  • repetition_penalty number optional
    Repetition penalty. Default 1.08.

Parameter Applicability Matrix

Parameter Notes

Instrumental and Lyrics

When instrumental=true, lyrics must not be passed at the same time. The [Instrumental] tag in lyrics indicates only a local instrumental section and cannot replace the top-level instrumental=true.

Cover

For music_cover, the melody follows the reference song, while caption controls the style, timbre, arrangement, and emotion. Providing lyrics consistent with the sung content of the original song is recommended.

Vocal-to-Music

For vocal_to_music, the melody mainly follows the dry vocal and preserves the vocal timbre of the input. The actual sung content of the dry vocal must be a subset or the full set of lyrics.

Caption Rewriting

By default, the server rewrites caption into a normalized English style prompt and returns it as rewritten_caption in the query endpoint. disable_caption_rewrite=true cannot be used together with lyrics_rewrite=true; when used in a non-instrumental text_to_music scenario, lyrics must be provided explicitly.

Output Duration

The output duration is determined by the model and cannot be controlled precisely via parameters. The duration may differ across multiple generations from the same input, and is typically 1 to 3 minutes.

Lyric Structure Tags

Each lyric structure tag must be on its own line. Common tags:
  • [Intro]
  • [Verse 1]
  • [Pre-Chorus]
  • [Chorus 1]
  • [Bridge]
  • [Instrumental]
  • [Hook]
  • [Break]
  • [Drop]
  • [Ad-lib]
  • [Outro]

Caption Writing Tips

caption supports Chinese or English. Describing the following dimensions is recommended:

Response

task_id is used to query the task result and for troubleshooting.

Error Codes

Content moderation may return 451 synchronously at the submission stage, or return FAILED with error.stage=censor during task execution.

Call Examples

Query the Task Result

POST https://api.stepfun.ai/v1/audio/music/query Polling once every 5 seconds until status reaches a terminal state is recommended; save the audio promptly once it succeeds.

Request Parameters

Task Status

In-Progress Response

Success Response

Failure Response

FAILED is a business terminal state; the HTTP status code is still 200.

Response Fields

Failure Stages

Query Error Codes

Query Example

Audio and Output Constraints

Using MP3 output to reduce the response size is recommended. PCM is a headerless raw stream and must be parsed as 48 kHz, 16-bit, stereo on your own.

Compliance Notice

When generated content is distributed, published, or used for commercial purposes externally, the caller should add an AI-generated-content label in accordance with applicable laws and regulations.