Music generation API reference(Fun-Music)

更新时间:
复制 MD 格式

API parameters for the Fun-Music music generation model.

User guide: For model overview and selection guidance, see Music generation.

Important

This model is currently in invitational preview. Apply for access in the Models page before use. This feature is available only in the Chinese mainland deployment scope (Beijing region).

Prerequisites

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

Endpoint

POST https://dashscope.aliyuncs.com/api/v1/services/audio/music/generation

Protocol: HTTPS. For streaming output, set the X-DashScope-SSE request header to enable SSE (Server-Sent Events).

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

Non-streaming

curl -X POST 'https://dashscope.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"
    }
}'

Streaming

curl -X POST 'https://dashscope.aliyuncs.com/api/v1/services/audio/music/generation' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
    "model": "fun-music-v1",
    "input": {
        "prompt": "High-energy electronic dance music, synthesizer effects, full of energy, suitable for fitness and workout scenarios",
        "gender": "male"
    }
}'

model string (required)

Model name. Allowed values:

  • fun-music-preview

  • fun-music-v1

input object (required)

Input parameters.

Properties

lyrics string (conditionally required)

Lyrics for the generated song. Required if prompt is not provided.

Character limits:

  • Non-streaming: 5–350 Chinese characters, 5–2,000 English characters

  • Streaming: 300–350 Chinese characters, 200–250 English words

Note

If both lyrics and prompt are provided, lyrics takes effect and prompt is ignored.

prompt string (conditionally required)

A text prompt. The model generates lyrics and a song based on this prompt. Required if lyrics is not provided.

Character limits:

  • Non-streaming: 1–2,000 characters

  • Streaming: 5–1,000 Chinese characters or English words

gender string (optional) Default: female

Vocal gender. Valid values:

  • male: Male voice

  • female: Female voice

format string (optional) Default: mp3

Audio encoding format. Valid values:

  • mp3: Suitable for network transfer and storage

  • wav: Suitable for post-processing and high-quality playback

enable_aigc_watermark boolean (optional) Default: false

AIGC 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.

Response object

Non-streaming

{
    "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"
}

Streaming (intermediate message)

{
    "output": {
        "audio": {
            "data": "Base64-encoded audio data",
            "expires_at": 1774937185,
            "id": "audio_a8db24cc-d35f-961b-af81-xxxxxxxxxxxx"
        },
        "finish_reason": "null"
    },
    "request_id": "a8db24cc-d35f-961b-af81-xxxxxxxxxxxx"
}

Streaming (final message)

{
    "output": {
        "audio": {
            "expires_at": 1774937185,
            "id": "audio_a8db24cc-d35f-961b-af81-xxxxxxxxxxxx",
            "data": "",
            "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,
            "sample_rate": "48000",
            "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."
        },
        "finish_reason": "stop"
    },
    "usage": {
        "duration": 200
    },
    "request_id": "a8db24cc-d35f-961b-af81-xxxxxxxxxxxx"
}

request_id string

Request ID, used for troubleshooting and log tracing.

output object

Model output.

Properties

audio object

Audio output from the model.

Properties

data string

Base64-encoded audio chunks in streaming mode. Empty string in non-streaming mode.

url string

OSS URL of the complete audio file, valid for 24 hours. Present in all non-streaming responses and in the final streaming message only.

id string

Audio file ID.

expires_at integer

Unix timestamp indicating when the audio URL expires.

extra_info object

Additional metadata about the generated audio.

Properties

channels integer

Number of audio channels. For example, 2 indicates stereo.

sample_rate string

Audio sample rate. For example, "48000".

lyrics string

Lyrics of the generated song.

finish_reason string

Generation status:

  • null: Generation is in progress

  • stop: Generation is complete

usage object

Billing information for this request.

Properties

duration integer

Music duration in seconds, used for billing.