MUSUBE API REFERENCE
One API.
Every model in the catalog.
The Musube API is OpenAI-compatible. Point an OpenAI SDK at our base URL, use your Musube key, and call any model on the models page.
- BASE URL
https://console.musube.ai/v1- AUTH
Authorization: Bearer msb_live_…
START
Overview
Every endpoint lives under https://console.musube.ai/v1. Requests and responses use JSON, except speech, which returns audio bytes. The request and response shapes follow OpenAI’s, so the official openai SDKs for Python and Node work unchanged once you set the base URL.
| Endpoint | What it does |
|---|---|
GET /v1/models | List models |
GET /v1/models/{model} | Get one model |
POST /v1/chat/completions | Text, streaming, and Gemini image models |
POST /v1/messages | Text, in Anthropic’s Messages format |
POST /v1/responses | Text, in OpenAI’s Responses format |
POST /v1/embeddings | Text embeddings |
POST /v1/images/generations | Generate images |
POST /v1/audio/speech | Text to speech |
POST /v1/videos | Start a video job |
GET /v1/videos/{id} | Video job status |
GET /v1/videos/{id}/content | Download a finished video |
START
Authentication
Create a key at console.musube.ai/dashboard/keys. Keys start with msb_live_. The full key is shown once, when you create it; store it in a secret manager.
Send the key in the Authorization header on every request:
Authorization: Bearer msb_live_...The examples on this page read the key from the MUSUBE_API_KEY environment variable. Never put a key in browser or mobile code: anyone who has it can spend your balance. Call the API from your server.
export MUSUBE_API_KEY="msb_live_..."START
Quickstart
Your first call: one chat message to a fast text model.
curl https://console.musube.ai/v1/chat/completions \
-H "Authorization: Bearer $MUSUBE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.8-flash",
"messages": [{ "role": "user", "content": "Hello" }]
}'To use another model, change model. Each modality has its own endpoint; a model sent to the wrong one gets a 400 wrong_endpoint that names the right one.
ENDPOINTS
Models
GET/v1/models
GET/v1/models/{model}
Lists the models you can call, or returns one. Browse them with prices on the models page. Model ids change as models are added and retired, so read them from this endpoint rather than hard-coding a list.
Each model has OpenAI’s fields plus modality: text, image, video, speech or embedding. The modality tells you which endpoint serves it. created is always 0.
curl https://console.musube.ai/v1/models \
-H "Authorization: Bearer $MUSUBE_API_KEY"
curl https://console.musube.ai/v1/models/qwen3.8-flash \
-H "Authorization: Bearer $MUSUBE_API_KEY"{
"object": "list",
"data": [
{
"id": "qwen3.8-flash",
"object": "model",
"created": 0,
"owned_by": "qwen",
"modality": "text"
}
]
}ENDPOINTS
Chat completions
POST/v1/chat/completions
OpenAI’s chat completions API. Serves every text model, and the Gemini image models (see below). Other OpenAI fields, such as temperature, max_tokens, tools and response_format, are passed to the model; support varies by model. Some models take no sampling parameters, and for those temperature and top_p are dropped.
| Parameter | Type | Description |
|---|---|---|
modelrequired | string | A text model id, or a Gemini image model id. |
messagesrequired | array | The conversation, in OpenAI's message format. Must not be empty. |
stream | boolean | Send the reply as server-sent events. Default false. |
stream_options.include_usage | boolean | With stream, end with a chunk that holds usage and no choices. |
curl https://console.musube.ai/v1/chat/completions \
-H "Authorization: Bearer $MUSUBE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.8-flash",
"messages": [{ "role": "user", "content": "Hello" }]
}'{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1764000000,
"model": "qwen3.8-flash",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "Hello! How can I help?" },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 7,
"total_tokens": 16
}
}usage holds prompt_tokens, completion_tokens and total_tokens, plus prompt_tokens_details.cached_tokens and completion_tokens_details.reasoning_tokens when the model reports them.
Streaming
Set stream: true to get the reply as server-sent events, ending with data: [DONE]. If the stream is cut short, you are charged for the tokens already sent.
curl https://console.musube.ai/v1/chat/completions \
-H "Authorization: Bearer $MUSUBE_API_KEY" \
-H "Content-Type: application/json" \
-N \
-d '{
"model": "qwen3.8-flash",
"stream": true,
"stream_options": { "include_usage": true },
"messages": [{ "role": "user", "content": "Write a haiku about rain." }]
}'Image models in chat
Gemini image models generate through chat completions, not the images endpoint. Send the prompt as a user message. Images come back in choices[0].message.images, and each image is charged.
curl https://console.musube.ai/v1/chat/completions \
-H "Authorization: Bearer $MUSUBE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image",
"messages": [{ "role": "user", "content": "A lighthouse at dusk, film grain" }]
}'"message": {
"role": "assistant",
"content": "",
"images": [
{ "type": "image_url", "image_url": { "url": "data:image/png;base64,..." } }
]
}ENDPOINTS
Messages (Anthropic)
POST/v1/messages
Anthropic’s Messages API, for every text model: Claude, and the others too, which are converted to and from the same format. Point an Anthropic SDK at https://console.musube.ai (without /v1; the SDK adds it) and pass your Musube key as the API key. The SDKs send it as x-api-key; Authorization: Bearer works too. Other Messages fields, such as system, tools and thinking, are passed to the model; support varies by model. For models that take no sampling parameters, temperature, top_p and top_k are dropped.
| Parameter | Type | Description |
|---|---|---|
modelrequired | string | A text model id. |
max_tokensrequired | integer | The most tokens to generate. |
messagesrequired | array | The conversation, in Anthropic's message format. Must not be empty. |
stream | boolean | Send the reply as Anthropic's server-sent events. Default false. |
curl https://console.musube.ai/v1/messages \
-H "x-api-key: $MUSUBE_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-haiku-5-5",
"max_tokens": 1024,
"messages": [{ "role": "user", "content": "Hello" }]
}'{
"id": "msg_...",
"type": "message",
"role": "assistant",
"model": "claude-haiku-5-5",
"content": [{ "type": "text", "text": "Hello! How can I help?" }],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 9,
"output_tokens": 8,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0
}
}usage holds input_tokens and output_tokens, plus the cache counters when the model reports them. Cache writes and reads are charged as input tokens. A stream cut short is charged for the tokens already sent. /v1/messages/count_tokens and the Batches API are not available.
Errors on this endpoint use Anthropic’s shape, with the same statuses as the table in Errors, so the Anthropic SDKs raise their usual exceptions:
{
"type": "error",
"error": {
"type": "authentication_error",
"message": "Invalid API key. Create one at /dashboard/keys."
}
}ENDPOINTS
Responses
POST/v1/responses
OpenAI’s Responses API, streaming or not, for the text models of these families: GPT, Qwen, DeepSeek, GLM, Kimi, Doubao, Hunyuan, MiniMax and MiMo. Claude and Gemini models are not available here and get 400 unsupported_model; call them at chat completions or Messages. Other Responses fields, such as instructions, tools and reasoning, are passed to the model; support varies by model.
| Parameter | Type | Description |
|---|---|---|
modelrequired | string | A text model id from the families above. |
inputrequired | string | array | A prompt, or a list of input items in the Responses format. |
stream | boolean | Send the reply as server-sent events, ending with response.completed. Default false. |
background | boolean | Not supported. Retrieving a stored response by id is not available either. |
curl https://console.musube.ai/v1/responses \
-H "Authorization: Bearer $MUSUBE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"input": "Write a one-line tagline for a bakery."
}'usage holds input_tokens, output_tokens and total_tokens, with input_tokens_details.cached_tokens and output_tokens_details.reasoning_tokens. A response stopped by max_output_tokens ends with status: "incomplete".
ENDPOINTS
Embeddings
POST/v1/embeddings
OpenAI’s embeddings API, for embedding models. You pay per input token; there are no output tokens.
| Parameter | Type | Description |
|---|---|---|
modelrequired | string | An embedding model id. |
inputrequired | string | array | A string, a list of strings, or token arrays. Each item gets one vector. |
dimensions | integer | Vector length, for models that take it. qwen3.7-text-embedding takes 256, 512, 768, 1024, 1536, 2048 or 2560; the Kinfra models return a fixed length. |
encoding_format | string | float (default) or base64 (little-endian float32), for every model. |
curl https://console.musube.ai/v1/embeddings \
-H "Authorization: Bearer $MUSUBE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-text-embedding",
"input": ["The quick brown fox", "jumps over the lazy dog"],
"dimensions": 1024
}'{
"object": "list",
"data": [
{ "object": "embedding", "index": 0, "embedding": [0.0123, -0.0456, ...] },
{ "object": "embedding", "index": 1, "embedding": [0.0789, 0.0012, ...] }
],
"model": "qwen3.7-text-embedding",
"usage": { "prompt_tokens": 12, "total_tokens": 12 }
}ENDPOINTS
Images
POST/v1/images/generations
OpenAI’s image generation API, for every image model except the Gemini ones. You pay per image returned. Other fields, such as size, are passed to the model; some models ignore or reject them.
| Parameter | Type | Description |
|---|---|---|
modelrequired | string | An image model id. |
promptrequired | string | What to draw. |
n | integer | How many images, 1–10. Default 1. The balance must cover all of them. |
curl https://console.musube.ai/v1/images/generations \
-H "Authorization: Bearer $MUSUBE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-image-3.0",
"prompt": "A lighthouse at dusk, film grain",
"n": 1
}'Each item in data has url or b64_json, depending on the model, and sometimes revised_prompt. Links are not permanent; save the image if you need it later.
{
"created": 1764000000,
"data": [
{ "url": "https://..." }
]
}ENDPOINTS
Speech
POST/v1/audio/speech
OpenAI’s text-to-speech API, for speech models. The response body is the audio file itself, not JSON. You pay per input character.
| Parameter | Type | Description |
|---|---|---|
modelrequired | string | A speech model id. |
inputrequired | string | The text to speak. Up to 4,096 characters. |
response_format | string | mp3 (default), wav, opus, aac, flac or pcm. Sets the Content-Type of the reply. |
voice | string | Optional. Some models reject any voice, so leave it out unless the model documents one. |
curl https://console.musube.ai/v1/audio/speech \
-H "Authorization: Bearer $MUSUBE_API_KEY" \
-H "Content-Type: application/json" \
-o speech.mp3 \
-d '{
"model": "qwen-audio-3.1-tts-flash",
"input": "Hello from Musube.",
"response_format": "mp3"
}'ENDPOINTS
Videos
Video is asynchronous. Start a job, then poll it or wait for a webhook. When it completes, download the file.
Start a job
POST/v1/videos
The job is charged when it is accepted, at its length and resolution. If it fails, the charge is refunded. The balance must cover the whole clip up front.
| Parameter | Type | Description |
|---|---|---|
modelrequired | string | A video model id. |
promptrequired | string | What to film. |
seconds | number | string | Clip length, 1–20, rounded to whole seconds. Default 5. duration is accepted as an alias. Values outside the range are clamped. |
resolution | string | 480p, 720p or 1080p. Default 720p. |
size | string | Instead of resolution, a size like 1280x720. The shorter side picks the resolution tier: up to 480 is 480p, up to 720 is 720p, larger is 1080p. |
Other fields are passed to the model; support varies by model.
curl https://console.musube.ai/v1/videos \
-H "Authorization: Bearer $MUSUBE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kling-video-v4",
"prompt": "A paper boat drifting down a rain-soaked street",
"seconds": 5,
"resolution": "720p"
}'{
"id": "video_...",
"object": "video",
"model": "kling-video-v4",
"status": "queued",
"progress": 0,
"created_at": 1764000000,
"completed_at": null,
"url": null,
"error": null,
"seconds": 5,
"resolution": "720p"
}Check a job and download it
GET/v1/videos/{id}
GET/v1/videos/{id}/content
status moves from queued to in_progress to completed or failed. progress runs from 0 to 100. A completed job has the file’s link in url (download it; the link is not permanent); a failed one has error.message. Poll every 5–10 seconds, or use webhooks instead.
/content answers with a 302 redirect to the file. Before the job completes it returns 409 not_ready; for a failed job, 409 job_failed. Only the account that started a job can read it.
# Status and progress
curl https://console.musube.ai/v1/videos/$VIDEO_ID \
-H "Authorization: Bearer $MUSUBE_API_KEY"
# The finished file (302 redirect; -L follows it)
curl -L https://console.musube.ai/v1/videos/$VIDEO_ID/content \
-H "Authorization: Bearer $MUSUBE_API_KEY" \
-o video.mp4ENDPOINTS
Webhooks
Instead of polling, get a signed POST when a video job started through the API finishes. Add up to five endpoints in the console under Webhooks. Each has its own secret, starting with whsec_. Use the console’s test button to send a webhook.test event.
Events
| Event | Sent when |
|---|---|
video.completed | A video job finished. data.url is the file. |
video.failed | A video job failed. data.error.message says why. It was refunded. |
The body is { type, created_at, data }. created_at is Unix seconds. data is the same video job object that GET /v1/videos/{id} returns.
{
"type": "video.completed",
"created_at": 1764000300,
"data": {
"id": "video_...",
"object": "video",
"model": "kling-video-v4",
"status": "completed",
"progress": 100,
"created_at": 1764000000,
"completed_at": 1764000290,
"url": "https://...",
"error": null
}
}content-type: application/json
user-agent: Musube-Webhooks/1.0 (+https://musube.ai)
webhook-id: 3f2b6c1e-...
webhook-timestamp: 1764000300
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=Verify the signature
Requests follow the Standard Webhooks spec. Verify every request against the raw body, before parsing it. The standardwebhooks package does this for you.
# pip install standardwebhooks flask
import os
from flask import Flask, request
from standardwebhooks.webhooks import Webhook, WebhookVerificationError
app = Flask(__name__)
wh = Webhook(os.environ["MUSUBE_WEBHOOK_SECRET"]) # whsec_...
@app.post("/webhooks/musube")
def musube_webhook():
body = request.get_data(as_text=True) # the raw body
try:
event = wh.verify(body, {
"webhook-id": request.headers["webhook-id"],
"webhook-timestamp": request.headers["webhook-timestamp"],
"webhook-signature": request.headers["webhook-signature"],
}) # raises if forged or older than 5 minutes
except (WebhookVerificationError, KeyError):
return "invalid signature", 400
if event["type"] == "video.completed":
pass # event["data"]["id"], event["data"]["url"]
elif event["type"] == "video.failed":
pass # event["data"]["error"]["message"]
return "", 204To verify by hand: take the secret after whsec_ and base64-decode it to get the key. Compute HMAC-SHA256 of ${webhook-id}.${webhook-timestamp}.${body} with that key, and base64-encode it. The header is v1, followed by that value. It may hold several space-separated signatures; accept if any matches. Compare in constant time, and refuse timestamps more than five minutes from now.
import base64, hashlib, hmac, time
def verify_musube_webhook(secret: str, headers, body: str) -> bool:
msg_id = headers["webhook-id"]
timestamp = headers["webhook-timestamp"]
header = headers.get("webhook-signature", "")
# Refuse old or future timestamps to stop replays.
if abs(time.time() - int(timestamp)) > 300:
return False
key = base64.b64decode(secret.removeprefix("whsec_"))
digest = hmac.new(key, f"{msg_id}.{timestamp}.{body}".encode(), hashlib.sha256).digest()
expected = "v1," + base64.b64encode(digest).decode()
# The header may hold several space-separated signatures.
return any(hmac.compare_digest(candidate, expected) for candidate in header.split(" "))Delivery
- Endpoints must be public
https://URLs on port 443 or 8443. Private and local addresses are refused. - Answer with any 2xx within 10 seconds. Do slow work after you respond.
- Anything else is retried 7 more times, over about 11 hours (30 s, 2 min, 10 min, 30 min, 1 h, 3 h, 6 h), then marked failed.
- Redirects are not followed. A 3xx counts as a failure.
- An event can arrive more than once. Drop repeats by
webhook-id, which stays the same across retries. - The console lists recent deliveries with their status codes, and can send a failed one again.
OPERATE
Errors
Errors use OpenAI’s shape (except on /v1/messages, which uses Anthropic’s), so SDKs raise them as their usual exceptions. Branch on code; the message is for people and may change.
{
"error": {
"message": "The model 'gpt-9' does not exist. List models with GET /v1/models.",
"type": "invalid_request_error",
"param": "model",
"code": "model_not_found"
}
}| Status | Code and type | When | What to do |
|---|---|---|---|
| 400 | nullinvalid_request_error | The body is not a JSON object, or a required field is missing (model, messages, prompt, input). param names the field. | Fix the request. Do not retry as is. |
| 400 | wrong_endpointinvalid_request_error | The model is served at a different endpoint. The message names it. | Send the request to the endpoint in the message. |
| 400 | unsupported_modelinvalid_request_error | The model is not available through /v1/responses (Claude and Gemini). | Call it at /v1/chat/completions or /v1/messages. |
| 400 | string_above_max_lengthinvalid_request_error | Speech input is over 4,096 characters. | Split the text into several calls. |
| 400 | invalid_requestinvalid_request_error | The model rejected a parameter. The message says which. | Change the parameter. Not every model takes every OpenAI field. |
| 401 | missing_api_keyinvalid_request_error | No Authorization: Bearer header (or x-api-key). | Send the header. |
| 401 | invalid_api_keyinvalid_request_error | The key is wrong, malformed or revoked. | Check the key, or create one at /dashboard/keys. |
| 401 | expired_api_keyinvalid_request_error | The key passed its expiry date. | Create a new key and deploy it. |
| 402 | insufficient_balanceinsufficient_quota | The balance is too low for this call. | Add funds in the console's Billing page, or turn on auto-reload. |
| 403 | model_not_allowedpermission_error | The key's permissions do not include this model or its modality. | Use an allowed model, or widen the key's permissions. |
| 403 | ip_not_allowedpermission_error | The request came from an IP address outside the key's allow list. | Call from an allowed address, or add yours to the key. |
| 404 | model_not_foundinvalid_request_error | No model has that id. | Check the id against GET /v1/models. |
| 404 | not_foundinvalid_request_error | No video job with that id belongs to your account. | Check the id. Jobs are visible only to the account that started them. |
| 409 | not_readyinvalid_request_error | You asked for a video's content before it finished. | Poll GET /v1/videos/{id} or wait for the webhook. |
| 409 | job_failedinvalid_request_error | The video job failed. It has no file and was not charged. | Start a new job, perhaps with a changed prompt. |
| 429 | key_limit_reachedinsufficient_quota | The call would take the key past its monthly spending limit. | Raise the key's limit, or wait for the 1st of the month (UTC). Retrying will not help. |
| 429 | rate_limit_exceededrate_limit_error | Too many requests this minute for the key, or the model is busy. | Wait for Retry-After seconds, or back off exponentially if it is absent. |
| 502 | upstream_errorapi_error | The model provider returned an error, or could not read a video job. | Retry with backoff. |
| 502 | upstream_unreachableapi_error | The model provider could not be reached. | Retry with backoff. |
| 503 | service_unavailableapi_error | Model calls are paused on our side. | Retry later with backoff. |
| 503 | model_unavailableapi_error | This model cannot be served right now. | Try another model. Retry this one later. |
Safe to retry with backoff: rate_limit_exceeded, upstream_error, upstream_unreachable and service_unavailable. The others need a change first.
OPERATE
Rate limits
Each key may make 300 requests per minute by default. You can set it per key, from 1 to 3,000, on the keys page. The limit counts in fixed 60-second windows.
Every /v1 response made with a key carries the key’s current state:
HTTP/1.1 200 OK
x-ratelimit-limit-requests: 300
x-ratelimit-remaining-requests: 287
x-ratelimit-reset-requests: 12s| Header | Meaning |
|---|---|
x-ratelimit-limit-requests | Requests allowed per minute for this key. |
x-ratelimit-remaining-requests | Requests left in the current window. |
x-ratelimit-reset-requests | Time until the window resets, such as 12s. |
Over the limit, you get 429 rate_limit_exceeded with a Retry-After header in seconds. A model can also be rate-limited by its provider. That returns the same code, but Retry-After is not guaranteed.
HTTP/1.1 429 Too Many Requests
Retry-After: 12
x-ratelimit-limit-requests: 300
x-ratelimit-remaining-requests: 0
x-ratelimit-reset-requests: 12s
{
"error": {
"message": "...",
"type": "rate_limit_error",
"param": null,
"code": "rate_limit_exceeded"
}
}Retrying
Retry with exponential backoff, and wait at least Retry-After when it is present. The openai SDKs already do this for 429 and 5xx responses (two retries by default).
# curl can retry 429 and 5xx itself, and honours Retry-After:
curl --retry 5 --retry-max-time 120 \
https://console.musube.ai/v1/chat/completions \
-H "Authorization: Bearer $MUSUBE_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "model": "qwen3.8-flash", "messages": [{ "role": "user", "content": "Hello" }] }'Without an SDK, a loop like this works:
import random, time
import httpx
RETRYABLE = {"rate_limit_exceeded", "upstream_error", "upstream_unreachable", "service_unavailable"}
def call_with_backoff(send, attempts=6):
for attempt in range(attempts):
response: httpx.Response = send()
code = (response.json().get("error") or {}).get("code") if response.status_code >= 400 else None
if code not in RETRYABLE or attempt == attempts - 1:
return response
retry_after = response.headers.get("retry-after")
delay = float(retry_after) if retry_after else min(60, 2 ** attempt) + random.random()
time.sleep(delay)OPERATE
API keys
Manage keys at /dashboard/keys. Each key has its own settings, so you can give each app or environment a key with only what it needs.
Expiry
A key expires after 30, 90, 180 or 365 days, or never. The default is 90 days. An expired key gets 401 expired_api_key. A revoked key gets 401 invalid_api_key.
Rolling a key
Rolling replaces a key with a new secret. The old one can stop at once, or keep working for 1 hour, 24 hours or 7 days while you deploy the new one.
Monthly spending limit
Optionally cap what a key may spend each calendar month (UTC), at list price. A call that would pass the limit gets 429 key_limit_reached with type insufficient_quota. The limit resets on the 1st. Usage is charged after each call, so concurrent calls can go slightly over.
Rate limit
Requests per minute, 1–3,000, default 300. See Rate limits.
Permissions
A key can be restricted to:
- Modalities: any of
text,image,video,speechandembedding. - Models: a list of model ids.
- IP addresses: single addresses or CIDR ranges, such as
203.0.113.0/24.
A call outside these gets 403 with type permission_error and code model_not_allowed or ip_not_allowed. With no restrictions set, a key can call every model from anywhere.
OPERATE
Teams
A key belongs to your personal account or to a team. A team shares one balance, one set of keys and one usage history. A call made with a team’s key is charged to the team. Switch between accounts in the console.
OPERATE
Billing
- The API is prepaid. Add funds to your balance in the console.
- Each call is charged at the model’s price after it finishes: per token for text, per input token for embeddings, per image, per input character for speech. Prices are on the models page.
- Video is charged when the job is accepted, by length and resolution, and refunded if the job fails.
- Failed calls are not charged, except a stream cut short, which is charged for the tokens already sent.
- Before a call starts, the balance must cover it. If it does not, you get
402 insufficient_balance.
OPERATE
Usage and logs
The console’s Logs page lists every request with its model, key, status, duration and cost. You can filter it and download the requests as CSV for your own accounting.
OPERATE
Support
Questions, higher limits or volume pricing: email sales@musube.ai. Include the time of the request, the model and the error code. Never send your API key.

