Skip to main content
Music generation

Music generation API reference(Fun-Music)

API parameters for the Fun-Music music generation model.

User guide: For model overview and selection guidance, see Music generation.
This model is currently in limited preview. Apply for access on the Model Gallery before use. This model is available only in the China (Beijing) region.

Prerequisites

An API key is required. To get one, see Get an API key.

Endpoint

POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/music/generation, Replace WorkspaceId with your actual workspace ID. Protocol: HTTPS. For streaming output, set the X-DashScope-SSE request header to enable SSE (Server-Sent Events).
Alibaba Cloud Model Studio has released workspace-specific domains for the China (Beijing) and Singapore regions. The new dedicated domains deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
  • China (Beijing): from https://dashscope.aliyuncs.com to https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com
  • Singapore: from https://dashscope-intl.aliyuncs.com to https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
{WorkspaceId} is your workspace ID, which can be found on the Workspace Details page in the Alibaba Cloud Model Studio console. The existing domain remains fully functional.

Request headers

Parameter

Type

Required

Description

Authorization

string

Yes

Bearer {api-key}. Replace {api-key} with your API key.

Content-Type

string

Yes

application/json

X-DashScope-SSE

string

No

Set to enable to enable SSE streaming output.

Request body

modelstring(required)Model name. Allowed values:
  • fun-music-v1
  • fun-music-preview
inputobject(required)Input parameters.

Properties

promptstring(conditionally required)A text prompt. The model automatically composes and generates music based on this prompt.
  • fun-music-v1: Either lyrics or prompt must be provided.
  • fun-music-preview: Required.
Character limits:
  • Non-streaming: 1–2,000 characters
  • Streaming: 5–1,000 Chinese characters or English words
If both prompt and lyrics are provided, only lyrics takes effect and prompt is ignored.
lyricsstring(conditionally required)Lyrics for the generated song.
  • fun-music-v1: Either prompt or lyrics must be provided.
  • fun-music-preview: Optional.
Character limits:
  • Non-streaming: 5–350 Chinese characters, 5–2,000 English characters
  • Streaming: 300–350 Chinese characters, 200–250 English words
If both lyrics and prompt are provided, only lyrics takes effect and prompt is ignored.
genderstring(optional) Default: femaleVocal gender. Only supported by the fun-music-v1 model. Valid values:
  • male: Male voice
  • female: Female voice
formatstring(optional) Default: mp3Audio encoding format. Valid values:
  • mp3: Suitable for network transfer and storage
  • wav: Suitable for post-processing and high-quality playback
enable_aigc_watermarkboolean(optional) Default: falseAIGC watermark switch. When enabled, a Morse code audio signal representing "AI" (·— ··) is appended to the end of the generated audio to identify the content as AI-generated. Enabling the watermark increases the audio duration.
curl -X POST 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/music/generation' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "fun-music-v1",
    "input": {
        "prompt": "Fresh summer folk song, acoustic guitar and harmonica accompaniment, upbeat tempo, suitable as background music for travel vlogs",
        "gender": "female"
    }
}'

Response object

request_id stringRequest ID, used for troubleshooting and log tracing.outputobjectModel output.

Properties

audio objectAudio output from the model.

Properties

data stringBase64-encoded audio chunks in streaming mode. Empty string in non-streaming mode.url stringOSS URL of the complete audio file, valid for 24 hours. Present in all non-streaming responses and in the final streaming message only.id stringAudio file ID.expires_at integerUnix timestamp indicating when the audio URL expires.
extra_info objectAdditional metadata about the generated audio.

Properties

channels integerNumber of audio channels. For example, 2 indicates stereo.sample_rate stringAudio sample rate. For example, "48000".lyrics stringLyrics of the generated song.
finish_reason stringGeneration status:
  • null: Generation is in progress
  • stop: Generation is complete
usage objectBilling information for this request.

Properties

duration integerMusic duration in seconds, used for billing.
{
    "output": {
        "audio": {
            "data": "",
            "expires_at": 1774936147,
            "id": "audio_46c51288-7ed6-95cc-a119-xxxxxxxxxxxx",
            "url": "http://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/pre/fun-music/20260330/xxxxxxxx/a8db24cc-d35f-961b-af81-a9e8d8b01f67.mp3?xxx"
        },
        "extra_info": {
            "channels": 2,
            "lyrics": "[verse]\nMorning sunlight slips through the curtain,\nCoffee aroma fills up the room.\nOpen the book left unfinished yesterday,\nTime quietly drifts by this way.\n\n[chorus]\nTake it slow, there's no hurry,\nLife should be this carefree.\nToss your worries into the wind,\nEmbrace every sunny day and rainy season.",
            "sample_rate": "48000"
        },
        "finish_reason": "stop"
    },
    "usage": {
        "duration": 200
    },
    "request_id": "46c51288-7ed6-95cc-a119-xxxxxxxxxxxx"
}