Asynchronous Callbacks
When a task takes a long time or you don't want the client to block and wait, pass async=true and webhook_url to create an asynchronous task and receive a terminal-state callback.
Asynchronous callbacks are not a specific business endpoint, but rather the calling pattern of "any /v1 audio task endpoint + async=true + webhook_url". The example below demonstrates it with single-speaker speech POST /v1/audio/speech; other task endpoints work the same way.
Applicable scope
All /v1 audio task endpoints
Applicable scope
Request body carries async and webhook_url
Calling pattern
Create an API Key
Open the API Key management platform, create an API Key, and save it as an environment variable. Do not write the API Key into client-side code or commit it to a repository.
Example export MOSS_API_KEY="<your-api-key>"Prepare the callback receiver
Prepare a publicly accessible HTTPS endpoint to receive the terminal-state
POSTJSON callback for the task.Send a request with async
Add
async=trueandwebhook_urlto the request body of any task endpoint. The endpoint immediately returns a task object, the task moves into asynchronous processing, and the client is not blocked.request.json { "model": "moss-tts", "input": "This is a piece of asynchronously generated speech.", "voice_id": "<voice_id>", "async": true, "webhook_url": "https://example.com/webhook" }Send the request curl https://api.mosi.cn/v1/audio/speech \ -H "Authorization: Bearer $MOSS_API_KEY" \ -H "Content-Type: application/json" \ -d @request.jsonReceive the terminal-state callback
Once the task reaches a terminal state, MOSI sends a single
POSTJSON callback towebhook_url. The callback body is a compact terminal-state notification object (TaskID/TenantID/Status/CallbackURL) and does not contain the full task result; to obtain fields such as the result URL, use theTaskIDfrom the callback to call the task query endpoint. For field details, see Callback Security Rules.Fall back to active polling
If you miss the callback, you can actively query using the
task_idreturned by the server: useGET /v1/audio/tasks/{task_id}for general audio tasks, andGET /v1/audio/transcriptions/{task_id}for transcription tasks.
Next steps
Learn about asynchronous tasks
Learn the conceptual differences among the three states: synchronous response / asynchronous callback / active polling.
Single-speaker speech generation
See the full scenario workflow for the task endpoint used in the example.
Learn about the model
See the positioning of the models available for the task endpoint.