API Integration Overview
This section is for downstream developers: access the platform's chat, image generation, video generation, audio, and search capabilities through a single API Key — the capability matrix, authentication methods, and error semantics are covered below; per-capability integration guides are in the sub-pages in the left navigation; capability introductions and selection guidance for each brand model follow Model Square in the Console.
The official API address of the platform is
https://token.yaoshu.cc; all examples below use it directly.Placeholder conventions: replace
sk-your-api-keyin the examples with your platform API Key; replace{task_id}with the actual task ID; replace angle-bracket placeholders (such as<embedding-model>) with the corresponding model name (as returned byGET /v1/models).
1. Capability Overview
| Capability (direction · form) | Endpoint | Integration method |
|---|---|---|
| Chat · Chat format (text in → text out, synchronous) | /v1/chat/completions, /v1/completions | OpenAI SDK, direct |
| Chat · Responses format (text in → text out, synchronous) | /v1/responses | OpenAI SDK responses interface / Codex CLI / Agents SDK |
| Chat · Messages format (text in → text out, synchronous) | /v1/messages | Anthropic SDK, direct |
| Image generation and editing (text / source image → new image, synchronous) | /v1/images/generations, /v1/images/edits | Any OpenAI SDK, direct |
| Video generation (text / image / video / audio reference → video, async task: submit → poll → download) | /api/v3/contents/generations/tasks | Direct HTTP (V3-style JSON / multipart), model yaoshu-video; fields and examples in Video Generation |
| Text to speech (text → audio, complete audio returned in one response) | /v1/audio/speech | OpenAI SDK audio.speech interface / direct HTTP, model yaoshu-audio |
| Music generation (text / lyrics → song or instrumental, async task: submit → poll → download) | /suno/submit/music (submit), /suno/fetch/{task_id} (query; result_url is a complete URL that can be downloaded directly) | Direct HTTP (JSON submit and polling), model yaoshu-music |
| Audio understanding (text / image / audio / video → text only, synchronous) | /v1/chat/completions | OpenAI SDK (chat interface), model yaoshu-omni |
| Real-time audio/video conversation (speak, listen and answer simultaneously, returns text and audio) | /v1/realtime?model=yaoshu-omni-realtime | OpenAI Realtime SDK (WebSocket), model is fixed to yaoshu-omni-realtime |
| Web search (query terms → list of web results, not question answering, synchronous) | /api/paas/v4/web_search | Direct HTTP (platform-unified web_search format) |
| Rerank (document list → reordered by relevance, synchronous) | /v1/rerank | Cohere SDK |
| Embeddings (text → vectors, synchronous) | /v1/embeddings | Any OpenAI SDK, direct |
Integration summary: every capability uses the same API Key authentication and the same platform address — point your existing SDK's base_url at https://token.yaoshu.cc and swap in a platform Key: chat (any of the three formats: chat / responses / messages) plus image/audio/embeddings/rerank work with your existing OpenAI / Anthropic / Cohere SDKs with zero code changes; the video model yaoshu-video uses the task endpoint (submit in the JSON / multipart format described in Video Generation, then poll and download); music uses the task endpoint (/suno/submit/music to submit and obtain a task ID → poll for the result); search uses the unified search endpoint (search_engine switches tiers, and all tiers share one response format).
The three chat entry points are functionally equivalent and billed identically; pick whichever matches your existing SDK and no migration is needed. Do not mix speech into the same chat entry point:
yaoshu-omnireturns text only on the chat endpoint; text to speech uses/v1/audio/speechwithyaoshu-audio; simultaneous listen-and-answer uses/v1/realtimewithyaoshu-omni-realtime. For the distinctions, see Text to Speech, Audio and Video Understanding, and Real-Time Conversation.
2. Quick Start (Three Steps)
- Get an API Key: sign in to the Console → API Key management → create an API Key; you receive a key starting with
sk-. - Replace the address and key: replace the OpenAI (or corresponding vendor) API address in your existing code with the platform address, and the key with a platform Key.
- Verify connectivity:
curl https://token.yaoshu.cc/v1/models \
-H "Authorization: Bearer sk-your-api-key"A JSON model list in the response means integration succeeded. The models available to you are exactly what this endpoint returns (the model lists supported by each capability are configured by the platform).
3. Authentication
All AI endpoints use API Key authentication. The platform accepts both request headers below — pick whichever your SDK uses by default:
| Header | Example | Use case |
|---|---|---|
Authorization: Bearer | Authorization: Bearer sk-xxx | Default for OpenAI-style SDKs (recommended) |
x-api-key | x-api-key: sk-xxx | Default for Anthropic-style SDKs |
WebSocket (/v1/realtime) passes the key via the Sec-WebSocket-Protocol: openai-insecure-api-key.sk-xxx protocol header; Authorization: Bearer sk-xxx also works.
Switching the Compute Region of an API Key (No Sign-in Required)
Users accessing from overseas, or wanting to switch to overseas compute, can switch the compute region of that key without signing in to the Console — just call the endpoint with the key (only this key is affected; the change takes effect on the next request):
curl -X PUT https://token.yaoshu.cc/api/key/region \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{"region":"overseas"}'region accepts domestic (domestic, default) / overseas (overseas), and returns {"region":"overseas","label":"海外"}. This endpoint changes only the region, not quota or status; you can also switch when the key is disabled, expired, or out of quota. After switching, if a model has no service route configured for the target region, the call returns 403 and names the specific model — set region back to domestic to recover.
Self-Service Deactivation of an API Key (No Sign-in Required)
If a key may have leaked, a client has been compromised, or you need to suspend a key temporarily, no Console sign-in is required — call the endpoint with that key to deactivate this key (only this one is affected; other keys under the same account are unaffected):
curl -X POST https://token.yaoshu.cc/api/key/disable \
-H "Authorization: Bearer sk-your-api-key"Request: no request body and no parameters — just put the key in the request header; passing the key in URL parameters or the request body is not accepted.
Success response:
{ "code": 200, "flag": true, "data": { "tokenId": 12, "effectiveStatus": 2, "effectiveStatusLabel": "停用" } }| Field | Type | Description |
|---|---|---|
tokenId | int | ID of the deactivated key |
effectiveStatus | int | Effective status after deactivation: 2 = disabled; if the key was already expired or out of quota, 3 / 4 is returned (its original reason for being unavailable is not overwritten) |
effectiveStatusLabel | string | Human-readable status name in Chinese (disabled / expired / exhausted) |
JavaScript example:
const res = await fetch("https://token.yaoshu.cc/api/key/disable", {
method: "POST",
headers: { Authorization: "Bearer sk-your-api-key" }
});
const body = await res.json();
if (res.ok && body.flag) {
console.log("Deactivated", body.data);
}Behavior:
| Item | Description |
|---|---|
| Scope of impact | Only the key in the request header is deactivated; quota, expiry time, region and other settings are unchanged |
| Repeated calls | Idempotent — calling again with an already deactivated key still returns success and does not raise an error |
| When it takes effect | On the next call to an AI endpoint: returns 401「令牌已停用」 (if the key's quota was already exhausted, returns 429「令牌配额已用尽」); requests already in progress and streaming responses already established are unaffected |
| Can another user's key be deactivated | No. Any other key ID / user ID carried in the request is ignored |
| Restoring | This endpoint can only deactivate, not restore — sign in to the Console and set the status back to enabled in API Key management, or contact the platform administrator |
| Rate limit | 60 requests per minute per IP |
Error responses (note: this endpoint belongs to the key self-service management surface, so the error body is {"success":false,"message":"..."}, which differs from the OpenAI error format used by AI endpoints):
| HTTP | Response | Handling |
|---|---|---|
| 401 | {"success":false,"message":"未提供令牌"} | No key in the request header |
| 401 | {"success":false,"message":"令牌无效"} | The key does not exist or has been deleted |
| 403 | {"success":false,"message":"用户已被封禁"} | The account is banned; contact the platform |
| 429 | {"success":false,"message":"请求频率过高,请稍后再试"} | Back off according to the Retry-After header, then retry |
Suggested self-check: immediately call GET /v1/models after deactivation; it should return 401「令牌已停用」, which means the change has taken effect; call it again after restoring the key to confirm it is usable.
Resetting a Key's 5-Hour Spend Window (No Sign-in Required)
Each key has a rolling 5-hour spend cap (100 CNY by default, adjustable per key in the Console). When the cap is reached, the key's next request is rejected (HTTP 403, code=key_spend_window_exceeded) until the window rolls forward or someone resets it.
Automated clients can use the key itself to clear the window's used amount immediately, without signing in to the Console (only the key in the request header is affected; the cap and balance are unchanged):
curl -X POST https://token.yaoshu.cc/api/key/spend-window/reset \
-H "Authorization: Bearer sk-your-api-key"Request: no request body and no parameters — just put the key in the request header; passing the key in URL parameters or the request body is not accepted.
Success response:
{ "code": 200, "flag": true, "data": { "tokenId": 12, "clearedUsedQuota": 12345678, "clearedUsedCny": 24.69, "spendWindowLimitQuota": 50000000, "spendWindowLimitCny": 100, "spendWindowEnabled": true, "spendWindowUsedCny": 0 } }| Field | Type | Description |
|---|---|---|
tokenId | int | ID of the reset key (always the one in the request header) |
clearedUsedQuota / clearedUsedCny | int / number | Amount cleared this time (quota units / CNY); 0 when the window was already empty |
spendWindowLimitQuota / spendWindowLimitCny | int / number | The key's current 5-hour cap (quota / CNY); 0 when the cap is disabled |
spendWindowEnabled | boolean | Whether the 5-hour cap is enabled for this key |
spendWindowUsedCny | number | Used amount after the reset (always 0) |
Behavior:
| Item | Description |
|---|---|
| Scope of impact | Only the window of the key in the request header is reset; lifetime remaining quota, account balance, cap configuration and key status are unchanged |
| Can it overspend after resetting | No. The 5-hour cap is only a rate layer; the real hard limit is the account balance / enterprise allotted quota — insufficient balance is still rejected (429 insufficient_quota) regardless of resets |
| Repeated calls | Idempotent — calling again when the window is already empty still returns success with clearedUsedQuota = 0 |
| Call limit | No cooldown and no count limit (only the rate limit below applies) |
| When the key is unusable | Disabled / expired / out-of-quota keys can still call it (self-service configuration is not locked out) |
| Rate limit | 60 requests per minute per IP |
| Can another key be reset | No. Any other key ID / user ID carried in the request is ignored |
Error responses (also part of the key self-service management surface, so the error body is {"success":false,"message":"..."}): 401 no key provided / invalid key, 403 the account is banned, 429 too many requests — handle them the same way as the previous section.
4. Common Error Semantics
Error responses use the OpenAI-compatible format {"error": {"message", "type", "code"}}; handle them by "whose problem it is":
Deterministic rejections actively made by the platform, where "retrying is meaningless", uniformly return HTTP 429: disabled models / unsupported operations, enterprise policy, disabled key capabilities, arrears and insufficient quota, request content too large, invalid request body, no available route, restricted service account, etc. When the client receives 429 with error.metadata.retryable=false, display error.message and stop — do not resend the same request.
Retryable transient failures keep their original status code and still go through retry: service flapping / stream cut / timeout, and all candidate routes being in circuit-breaker cooldown returning 5xx (with Retry-After) — handle by retrying with backoff; platform / service rate limiting follows the standard HTTP 429 (with Retry-After and error.metadata.retryable=true). Authentication failures stay 401, and server-side errors keep their original status code as-is.
| Category | HTTP | Typical code | Client-side handling |
|---|---|---|---|
| Authentication failure (key missing / invalid / expired / banned) | 401 | invalid_request_error | Check the key |
| Model does not exist or has been delisted | 429 | model_not_found | Check the model name spelling (case-sensitive); confirm the model has not been delisted by the platform — do not retry |
| API Key quota exhausted / insufficient balance | 429 | insufficient_quota | Top up or switch to another API Key — do not retry (quota does not recover on its own) |
| Per-conversation, per-model spend has reached the platform threshold | 429 | session_spend_limit_exceeded | Decide downstream: if you confirm continuation, resend the request (released immediately); if it is judged abnormal, terminate the conversation; you will receive this code again once the accumulated spend reaches the next tier (see the note below) |
| Problem with the request itself (parameter format errors, content violations, etc.) | 4xx | Passed through as-is | Fix the request |
| Request content too large (context too long, exceeding the platform's per-request processing limit) | 429 | request_too_large | Trim the context or start a new conversation, then resend; do not retry as-is (the same content will necessarily fail again) |
| Content failed the safety review (non-compliant input content) | 429 | content_policy_violation | Modify the relevant content and resend; do not resubmit the same content (it will be blocked again, and repeated violations affect your account) |
| Platform rate limiting / service busy | 429 | rate_limit_error etc., with a Retry-After header | Back off and retry after the number of seconds given in Retry-After |
| A single key's 5-hour spend has reached its cap (key-level rate insurance) | 403 | key_spend_window_exceeded | Wait for the window to roll forward, or call POST /api/key/spend-window/reset with that key to clear it self-service; do not retry immediately (it will necessarily fail again before a reset) |
| Server-side account / quota anomaly (platform service route returning 401/403/429 etc., uniformly normalized) | 503 | upstream_account_limited | The current route is fluctuating; retry later — retrying with 5xx backoff is enough to recover |
Quota errors can be identified programmatically by OpenAI SDKs (code=insufficient_quota).
Platform-side technical failures (request content too large, request body that cannot be parsed/serialized, service connection or response anomalies) provide a readable Chinese explanation of the cause and how to handle it in message, and no longer expose the original internal implementation text; decide whether to retry based on code and the HTTP status — resending deterministic failures such as request_too_large as-is will necessarily fail again.
Addresses in error messages are redacted: message contains no internal URL, domain, or IP:port (those positions are shown as [service], for example service connect failed: [service]). When troubleshooting, rely on type/code and the HTTP status code, not on the address information in the message.
Per-conversation spend circuit breaker (session_spend_limit_exceeded): the platform accumulates actually charged spend per "same conversation × model" (each model accumulates separately and independently), and when the threshold for that model is reached (configured per model by the platform), the next request of that conversation is intercepted:
- Conversation identity comes from the session identifier you pass in: the
Session-Idrequest header (orX-Session-Id/X-Conversation-Id/Thread-Id, etc.), or the top-level request body fieldsconversation_id/session_id/thread_id,metadata.conversation_id,prompt_cache_key— any one of them; keep the same identifier for the same conversation. Requests carrying no session identifier do not participate in this mechanism. - The error message looks like
模型 yaoshu-text 对话累计消费已达 10.00 元(门槛 10.00 元),如确认继续请重发该请求,否则请终止对话— the model name is themodelyou requested, and the amount is the accumulated spend of that model in this conversation. - The handling decision is yours: confirm continuation → directly resend the request (same conversation identifier; the platform releases it immediately, and it will be intercepted again when the accumulated spend reaches the next tier, e.g. 20 yuan); judge it abnormal → terminate the conversation (send no further requests).
- Watch out for automatic retry behavior: some HTTP clients (e.g. Apache HttpClient) automatically retry 429 after a delay by default — if you want the "continue/terminate" decision to be genuinely made by your business layer, disable automatic retries for this error code and hand 429 +
session_spend_limit_exceededto your upper-layer logic; otherwise the behavior is observed as "auto-continue after a delay of about 60 seconds at each tier". - Interception happens before the request leaves the gateway, and intercepted requests are not billed.
5. Billing Rules (Failures and Interruptions)
Billing principles align with inference cost: a request is charged only when it is successfully delivered to the server and processed (billed); platform-side interception and service failures are not charged.
| Scenario | Billed | Description |
|---|---|---|
| Request intercepted by the platform (parameter validation failure, rate limiting, insufficient quota) | ❌ | The request never left the gateway and was rejected in place; the pre-deducted quota is refunded in full |
| Server returned an error (4xx/5xx), stream cut, timeout | ❌ | Treated as a failure; the pre-deducted quota is refunded in full |
| Request succeeded and the server returned normally | ✅ | Billed on the actual usage returned by the server (tokens / image count / seconds) |
| Streaming request disconnected by the client mid-way (generation stopped, network interrupted) | ✅ | The content has already been generated on the server and counted toward inference cost; billed on the final actual usage (standard industry practice); to stop the loss by interrupting, close the connection directly |
6. Related Documentation
| Group | Document | Content |
|---|---|---|
| Chat | Chat Completions | Non-streaming / streaming (SSE), multimodal image input, quick reference of common parameters |
| Chat | Responses | Non-streaming / streaming events, comparison with chat parameters |
| Media generation | Image Generation and Editing | Text / source image → new image (synchronous) |
| Media generation | Video Generation | yaoshu-video text / multi-asset reference → video; tasks, callbacks, download and billing |
| Media generation | Text to Speech | yaoshu-audio text to speech: full table of 68 system voices, emotion tags, instruction control, word-level timestamps |
| Media generation | Music Generation | yaoshu-music style / lyrics → song or instrumental (async task), supports a target duration of 10~360 seconds, includes a creation guide |
| Multimodal interaction | Audio and Video Understanding | yaoshu-omni listens / watches and returns text only (transcription, summarization, subtitles) |
| Multimodal interaction | Real-Time Conversation | yaoshu-omni-realtime WebSocket, speak, listen and answer simultaneously |
| Retrieval and embeddings | Web Search | Query terms → list of web results (not question answering); search_engine switches search tiers |
| Retrieval and embeddings | Embeddings | Text → vectors (semantic search / RAG ingestion) |
| Retrieval and embeddings | Rerank | Reorder a document list by relevance (RAG re-ranking) |
