ACE Music Song Generation API Integration Guide

ACE Music can generate songs based on a creative inspiration sentence or custom lyrics, and also supports importing reference audio, covering existing works, and blending two references. This article introduces the complete process from obtaining an API Token to submitting requests, querying tasks, previewing, and downloading.

Generation, covering, and blending each deliver a set of two candidate songs, while reference uploads import one audio track at a time. You can first complete the initial call using inspiration mode, then choose other creation methods as needed.

Application Process

  1. Open the AI 聚合|元宪智能 Console. If you are not logged in, please register or log in first.
  2. Find API Key in the General Applications area. If you do not have a key yet, click Create API Key; if you already have a key, you can directly use the copy button to obtain the API Token.
  3. To create, view, or adjust keys, go to the Manage Keys page. When using a restricted key, please confirm that it allows access to ACE Music and the required song, lyrics, and task interfaces.
  4. Fill in Authorization: Bearer YOUR_API_TOKEN in the request header, replacing YOUR_API_TOKEN with the complete copied Token. Song generation, reference upload, and lyrics generation consume credits. When the balance is insufficient, you can recharge at General Balance.

API Key and API Token refer to the same credential used to call the API in this article. General application credentials can be reused within the permission scope, and there is no need to create a new key for every request in this guide. Please store the Token on the server side, and do not place it in web frontends or public repositories.

Complete interface parameters and online debugging: ACE Music Song Generation API.

Basic Usage

The first call only needs to provide a song description prompt. The following uses “a warm folk song about taking the last bus home” as an example, using the default model acemusic-v1.1 to generate two candidates.

Set Request Headers and Request Body

The request URL is POST https://api.yxai-tech.top/acemusic/audios. Set the request headers as follows:

Request Header Value Description
Authorization Bearer YOUR_API_TOKEN Use the Token obtained in the previous step, keeping the space after Bearer
Content-Type application/json The request body uses JSON
Accept application/json Receive JSON results

This request uses the following parameters:

Parameter Value for This Request Description
action generate Generate a new song; this operation is also used when omitted
model acemusic-v1.1 Default model; you can also select acemusic-v1
custom false Inspiration mode; the model creates based on the description
prompt Song description You can describe language, theme, style, instruments, and mood
async true Obtain the task ID after submission, then query the result

cURL Example

curl --request POST 'https://api.yxai-tech.top/acemusic/audios' \
  --header 'Authorization: Bearer YOUR_API_TOKEN' \
  --header 'Content-Type: application/json' \
  --header 'Accept: application/json' \
  --data '{
    "action": "generate",
    "model": "acemusic-v1.1",
    "custom": false,
    "prompt": "一首关于坐末班车回家的中文民谣,木吉他伴奏,温暖而充满希望",
    "async": true
  }'

Python Example

First install requests (pip install requests), save the Token as the environment variable ACEDATACLOUD_API_TOKEN, and then run the following code:

import os
import requests

response = requests.post(
    "https://api.yxai-tech.top/acemusic/audios",
    headers={"Authorization": f"Bearer {os.environ['ACEDATACLOUD_API_TOKEN']}"},
    json={
        "action": "generate",
        "model": "acemusic-v1.1",
        "custom": False,
        "prompt": "一首关于坐末班车回家的中文民谣,木吉他伴奏,温暖而充满希望",
        "async": True,
    },
    timeout=30,
)
response.raise_for_status()
submitted = response.json()
print("请保存任务 ID:", submitted["task_id"])

cURL and Python demonstrate two ways of writing the same operation; choose either one. Each new submission creates a song task. Do not repeatedly run the submission code while waiting for results.

Submission Response

After an asynchronous request is accepted, it returns HTTP 202. The following is the response from an actual request:

{
  "task_id": "ae17781e-b4cd-4ad9-869a-34b8cf96b057",
  "trace_id": "3102971e-7f6a-473c-8255-ba1e8eace89e",
  "status": "created"
}
  • task_id: The unique ID of this task, which is required for subsequent queries.
  • trace_id: The tracking ID provided to support staff when troubleshooting issues.
  • status: The current task status; it is usually created when accepted.

At this point, the song is still being processed, and the response does not contain playable audio. Please save the task_id returned by your own request and proceed to the next step.

Query Results and Download Songs

Use the same Token to call POST /acemusic/tasks, replacing id with the task_id you just saved:

curl --request POST 'https://api.yxai-tech.top/acemusic/tasks' \
  --header 'Authorization: Bearer YOUR_API_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
    "action": "retrieve",
    "id": "YOUR_TASK_ID"
  }'

The query interface directly returns the task record. Song results are in response.data, and each element represents one audio track. Below is an excerpt from the real response of a completed task, retaining only the task status and audio delivery fields:

{
  "id": "ae17781e-b4cd-4ad9-869a-34b8cf96b057",
  "type": "audios",
  "state": "succeeded",
  "response": {
    "success": true,
    "status": "succeeded",
    "data": [
      {
        "id": "3966103b-b0e3-4799-aa6d-b90dfc3e30ee",
        "model": "acemusic-v1.1",
        "title": "末班车的温热",
        "state": "succeeded",
        "duration": 182,
        "audio_url": "https://cdn.acedata2.cloud/acemusic/ae17781e-b4cd-4ad9-869a-34b8cf96b057-3966103b-b0e3-4799-aa6d-b90dfc3e30ee.mp3"
      },
      {
        "id": "51b08e57-a990-4aaf-9418-fe3750a833f1",
        "model": "acemusic-v1.1",
        "title": "末班车的温热",
        "state": "succeeded",
        "duration": 174,
        "audio_url": "https://cdn.acedata2.cloud/acemusic/ae17781e-b4cd-4ad9-869a-34b8cf96b057-51b08e57-a990-4aaf-9418-fe3750a833f1.mp3"
      }
    ]
  }
}
Field Description
id / state The task ID and task status of the query record
response.success / response.status Whether the creation result was fully successful, and the final status
response.data Track list; there are two tracks when generation, cover, or mashup fully succeeds, and one track when upload succeeds
response.data[].id Platform track ID, which can be used for subsequent covers or mashups
response.data[].audio_url Playback and download URL of the delivered audio
response.data[].image_url Optional cover URL; its absence does not affect audio playback
response.data[].title / lyric / style Title, lyrics, and music style
response.data[].model / state The model used for this track and its delivery status; uploaded references may not include model
response.data[].duration Actual audio duration, in seconds

When the task is succeeded, audio_url can be used for previewing or downloading. When the task is partial_failed, completed tracks can still be retained and played, and no generation fee is charged for that group. When the task is failed, read response.error to investigate the reason. Continue querying for other statuses; an interval of several seconds and gradual backoff are recommended.

After a browser refresh or network interruption, continue querying the original task. A cover not yet returned does not mean the audio is unavailable; if a track does not yet have audio_url, delivery is still incomplete. For batch queries, history records, and polling code, see the Task Query Guide.

Generate Songs with Custom Lyrics

If you already have lyrics, change custom to true, and provide title, lyric, and style. The request URL and Token are the same as in the basic example; simply replace the request body with the following content:

{
  "action": "generate",
  "model": "acemusic-v1.1",
  "custom": true,
  "title": "回家的路",
  "lyric": "[Verse]\n晚风吹过熟悉的街道\n[Chorus]\n灯火等我回到家",
  "style": "中文民谣,木吉他,温暖人声",
  "async": true
}

Lyrics can contain section labels such as [Verse] and [Chorus]. In custom mode, do not pass the inspiration-mode prompt again. If you do not have lyrics yet, you can first generate a draft through the Lyrics Generation Guide, edit it, and then fill the text from the lyrics result into the lyric of the song request.

Upload Reference Audio

Use the same song endpoint, set action to upload, and fill in the HTTPS URL of the MP3 in audio_url. name is an optional display name. Publicly downloadable HTTPS MP3 links can be submitted directly. Keep the link accessible until the task delivers the preview and download URLs. External-link delivery supports MP3 files up to 32 MiB, with up to 5 public HTTPS redirects, and the file format is determined by the actual audio content.

If the file is local, the external link requires login, or the file exceeds the external import limit, you can use the platform account token to submit the file to POST https://yxai-tech.platform.acedata.cloud/api/v1/files/. Upload the MP3 file using the form field file. The file limit for importing reference audio this way is 64 MiB. Replace the example URL below with the complete file_url from the response.

{
  "action": "upload",
  "audio_url": "https://cdn.acedata.cloud/uploads/00000000-0000-4000-8000-000000000000.mp3",
  "name": "我的参考旋律",
  "async": true
}

This operation does not require model, custom, or lyric fields, and does not automatically generate a new song. After submission, likewise save the task_id and query the task. The response.data of a successful result contains one track; save its id as the reference track ID for subsequent operations.

If you want to use a new reference together with an existing work, you can pass the platform audio_id of that work when uploading. A separate upload fee will be charged after the reference import succeeds. If the original task returns submission_unknown, retain the task_id and trace_id and provide them to support staff for verification, then decide whether resubmission is needed.

Cover an Existing Song

Set action to cover, use a platform track audio_id that you can access, and provide new lyrics and music style:

{
  "action": "cover",
  "model": "acemusic-v1.1",
  "audio_id": "YOUR_TRACK_ID",
  "title": "回家的路·民谣版",
  "lyric": "[Verse]\n晚风吹过熟悉的街道",
  "style": "温暖民谣,木吉他",
  "audio_influence": 60,
  "async": true
}

audio_id comes from response.data[].id of a previously successful task, and is different from the generation task's task_id. Covers use acemusic-v1.1; the title is optional, while lyrics and style are required. audio_influence controls the degree of audio reference, ranging from 1–100, with a default of 60. Existing platform tracks can be reused directly without paying for upload again.

Mash Up Two Reference Songs

Set action to mashup, and fill in exactly two different platform track IDs in mashup_audio_ids:

{
  "action": "mashup",
  "model": "acemusic-v1.1",
  "mashup_audio_ids": ["YOUR_FIRST_TRACK_ID", "YOUR_SECOND_TRACK_ID"],
  "lyric": "[Verse]\nTurn two journeys into one song",
  "style": "Chinese pop, blending the melodies and rhythms of the two references",
  "audio_influence": 60,
  "async": true
}

The two references can come from completed upload or song tasks, and must be works that you can access and that are compatible with each other; incompatible combinations will be rejected. Mashup also uses acemusic-v1.1, lyrics and style are required, and the title is optional.

Cover and mashup do not use custom or inspiration prompt. The current song interface does not provide style strength, instrumental, continuation, stem separation, or timbre parameters; do not directly apply fields from other music services.

Parameter Quick Reference

Parameter Type When to provide Description
action string Optional generate (default), upload, cover, or mashup
model string Generate, cover, mashup Default acemusic-v1.1; generation also supports acemusic-v1; not provided for upload
custom boolean Generation only Default false for inspiration mode, true for custom lyrics mode
prompt string Required for inspiration generation Creative description of the song
title / lyric / style string Required for custom generation Title, lyrics, and style; cover and mashup require only lyrics and style, title is optional
audio_url / name string Upload A publicly downloadable HTTPS MP3 URL, or the MP3 URL returned by the platform file upload. Display name is optional
audio_id string Required for cover; optional for upload Platform audio track ID, can be used during upload to associate an existing reference
mashup_audio_ids string[] Required for mashup Exactly two different and compatible platform audio track IDs
audio_influence number Optional for cover, mashup Reference level 1–100, default 60
async boolean Optional Default true; setting it to false waits for the result, and still returns 202 with the original task ID if the wait time is exceeded
callback_url string Optional HTTPS completion callback URL; asynchronous execution is used after it is provided

Each operation accepts only its corresponding fields; construct requests according to the separate examples above.

Completion Callbacks and Duplicate Requests

Using Completion Callbacks

If you do not want to continuously poll, you can add your own HTTPS callback_url to a song request. After completion, the platform will push the final result to that address. The receiver should deduplicate by task_id and return a success status; callbacks may be retried.

Failure to receive a callback will not regenerate, reimport, or incur additional charges. You can still use the task API to retrieve the original task result.

Using Idempotency Keys

When submitting a request, you can add the Idempotency-Key request header and specify a unique key for the same creation. The same key and the same content return the original task, while the same key with different content causes a conflict. Use a new key for each intentionally initiated new creation, and retain the original key and original content for retries of the same submission.

Please save the key before sending, and save the task_id after acceptance. When the network times out and the acceptance status is unclear, do not automatically resend with a new key; prioritize querying the original task, and if necessary, retain the idempotency key when contacting support.

Pricing Details

Operation Billing Unit When Charged
Generate, cover, mashup One complete set of two candidates Charged once upon complete success; no generation fee for final failure or partial failure
Reference upload One successfully imported reference Charged once upon successful import; no charge for failure
Lyrics generation One successful lyrics task Charged separately; song operations do not implicitly charge an additional lyrics assistant fee
Task query Free Requires a valid Token and corresponding interface permission

For specific unit prices and balance, please see the ACE Music Service and Console. The console uses Credits as the unit, and actual amounts are converted based on the plan used, discounts, site pricing, and exchange rates.

Frequently Asked Questions

What should I do if authentication or permission errors are still shown after obtaining a Token?

Check whether the Token was copied completely, whether there is a space after Bearer, and whether the key has been disabled or restricted from accessing ACE Music interfaces. Do not treat the application ID or task ID as a Token.

The request returns 202; why is there no audio URL?

202 indicates that the task has been accepted. Use the returned task_id to query it, and obtain the audio after completion from response.data[].audio_url. Do not repeatedly submit generation requests to wait for the song.

Does a successful query mean that both songs have been completed?

A successful query HTTP response means that the task was read successfully; you also need to check the task state and the state of each audio track. The task is succeeded when two candidate tracks are delivered in full; it is partial_failed when only part of the delivery is completed in the end.

How should I troubleshoot when a call fails?

HTTP Status Code Recommended Handling
400 Check required fields, parameters corresponding to the operation, reference audio tracks, and compatibility
401 / 403 Check the Token, credential status, and interface access permissions
402 Check balance and credential quota limits
404 Check whether the reference audio track exists and whether the current account can access it
409 The request content for the same idempotency key is different; verify the original request
429 Reduce the call frequency and retry according to the backoff strategy
500 / 503 Retain the existing task ID, query the task first, then determine the next step

Asynchronous execution failures are recorded in the task terminal state and response.error. When contacting support, please provide task_id and trace_id, and do not provide the complete API Token.