# Twelver Developer & API Reference (https://twelver.app) > Twelver API technical reference: Bearer sk-… auth, OpenAI-compatible /v1/chat/completions, reasoning_effort rules, async Media API, MCP, and errors. ## Surface Overview - **Chat Completions** (`https://twelver.app/api/ai//v1/chat/completions`): The OpenAI-compatible endpoint — what you paste into Cline, opencode, Cursor or any coding agent. - **Media API** (`https://twelver.app/api/ai//v1/media/generations`): Images, video, music and speech from your own code: POST creates a job, GET on its id returns the finished files. - **MCP** (`https://twelver.app/api/mcp/v1/`): A remote MCP server per toolset — connects to Claude, Cursor and other MCP clients. No config id needed. Starter allowance: 0.25M tokens. Monthly plans: Basic $13 (10.4M), Pro $20 (16M), Premium $49 (39.2M). --- # Twelver Chat Completions API: Model Series & reasoning_effort > Reference for POST /api/ai//v1/chat/completions and GET /v1/models: model series, live rates, reasoning_effort, max_tokens, vision, and tools. Canonical URL: https://twelver.app/docs/en/api/chat-completions/ ## Endpoints & Authentication Point any OpenAI SDK or compatible coding agent (Cline, Kilo Code, OpenCode, Qwen Code, Codex CLI) at base URL https://twelver.app/api/ai//v1 with header Authorization: Bearer sk-. The path segment selects your default model series (provisioned alongside your key via Create API key). Passing an explicit model in the JSON body overrides the config series; passing an unknown or raw checkpoint ID (such as qwen4-max instead of qwen-max) returns 404 model_not_found before any balance reservation. - POST https://twelver.app/api/ai//v1/chat/completions — synchronous and SSE streaming (stream: true) chat completions, function calling (tools), and vision input (image_url). - GET https://twelver.app/api/ai//v1/models — returns all 15 public model series and their current backing models in OpenAI list format. **TypeScript (official OpenAI SDK)** ```typescript import OpenAI from 'openai'; const client = new OpenAI({ baseURL: 'https://twelver.app/api/ai//v1', apiKey: process.env.TWELVER_API_KEY, // sk-... }); const res = await client.chat.completions.create({ model: 'qwen-max', // Qwen4-Max; pass 'qwen' for Qwen3.7-Plus reasoning_effort: 'low', // 'none' disables thinking on qwen-max; 'low' | 'medium' | 'high' | 'max' max_tokens: 4096, messages: [ { role: 'user', content: 'Design an idempotent webhook consumer in TypeScript.' }, ], }); console.log(res.choices[0]?.message.content); ``` ## Active Model Series & Capabilities Matrix Series keys are versionless and durable: when a provider ships a new flagship checkpoint (for example, qwen-max moving to Qwen4-Max), existing configs upgrade automatically with zero code changes. | Series (model) | Backing model | Context | Vision (image_url) | Default reasoning | Accepted reasoning_effort | Input / output ($ per 1M) | | --- | --- | --- | --- | --- | --- | --- | | gpt | GPT-6 Luna | 1.05M (tier >272K) | Yes | off | none \| low \| medium \| high \| xhigh | 0.163 / 0.813 | | qwen-flash | Qwen3.8-Flash | 1M | Yes | off | — | 0.244 / 0.764 | | zai-flash | GLM-5.3-Flash | 1.3M | No | low | low \| high \| max | 0.244 / 0.813 | | minimax | MiniMax M3.1 Flash | 1M | Yes | low | low \| medium \| high \| max | 0.244 / 0.975 | | deepseek-flash | DeepSeek V4.1 Flash | 1M | Yes | off | — | 0.488 / 1.95 | | auto / qwen | Qwen3.7-Plus | 1M (tier >256K) | Yes | off | — | 0.65 / 2.6 | | xiaomi | MiMo V2.6 Pro | 1M | Yes | off | — | 0.707 / 1.41 | | gpt-terra | GPT-6.1 Terra | 1.05M (tier >272K) | Yes | medium | none \| low \| medium \| high \| xhigh \| max | 1.63 / 8.13 | | deepseek | DeepSeek V4 Pro | 1M | No | off | — | 2.15 / 6.44 | | zai | GLM-5.3 | 1M | No | max | low \| high \| max | 2.28 / 7.15 | | qwen-max | Qwen4-Max | 1M | Yes | high | none \| low \| medium \| high \| max | 2.44 / 7.31 | | grok | Grok 4.7 | 500K (tier >200K) | Yes | high | low \| medium \| high \| xhigh | 3.25 / 9.75 | | gpt-sol | GPT-6.1 Sol | 1.05M (tier >272K) | Yes | medium | low \| medium \| high \| xhigh \| max | 3.25 / 16.25 | | gpt-max | GPT-6 Astra | 1.05M | Yes | medium | low \| medium \| high \| xhigh \| max | 16.25 / 81.25 | _Verified against /api/pricing on 1 December 2026._ ## Controlling reasoning_effort & max_tokens Budgeting The proxy accepts both max_tokens and max_completion_tokens (with max_tokens taking precedence if both are sent) and translates to the upstream parameter automatically. On reasoning-capable models (qwen-max, zai, minimax, grok, gpt-*), max_tokens caps reasoning tokens + visible answer tokens combined, and reasoning tokens bill at the model output rate. - qwen-max (Qwen4-Max): defaults upstream to deep thinking ("high"). Pass "reasoning_effort": "none" to disable thinking completely (0 reasoning tokens — recommended for fast completions or small max_tokens caps), or "low" / "medium" / "high" / "max" to tune depth. (Use standard reasoning_effort rather than Alibaba-specific enable_thinking.) - minimax (MiniMax M3.1 Flash): thinking is always enabled; when reasoning_effort is omitted, the proxy defaults it to "low". - zai (GLM-5.3) & grok (Grok 4.7): thinking cannot be disabled; pass "reasoning_effort": "low" for minimum latency and spend. - gpt-terra, gpt-sol, gpt-max (plus gpt when tools are passed with effort != "none"): bridged over OpenAI Responses. Custom temperature / top_p require "reasoning_effort": "none". When continuing multi-turn tool calls, replay assistant.responses_reasoning on the assistant message. ## Frequently Asked Questions ### Which Base URL and API key format should I configure in Cursor, Cline, OpenCode, or the OpenAI SDK? Set Base URL to https://twelver.app/api/ai//v1 (OpenAI-compatible clients append /chat/completions automatically) and send Authorization: Bearer with an sk-… key owned by the same account as the config-id. ### Which reasoning_effort values are accepted, and why can custom temperature return HTTP 400? Accepted reasoning_effort values are none, minimal, low, medium, high, xhigh, max (per-series subsets are listed in the capability table above). On bridged GPT series (gpt-terra, gpt-sol, gpt-max), passing custom temperature or top_p requires reasoning_effort: "none". ### How do I preserve reasoning state across multi-turn tool calls? On Responses-bridged GPT series, assistant tool-call turns include a responses_reasoning field — echo that field back unchanged on the assistant message when sending tool results. --- # Twelver Media Generation API: Image, Video, Music & Speech > Async request and response schema for POST /v1/media/files, POST /v1/media/generations, polling GET /v1/media/generations/:taskId, and media toolsets. Canonical URL: https://twelver.app/docs/en/api/media/ ## Async Task Lifecycle The Media API uses the same Bearer sk-… key under /api/ai//v1/media. Each job runs the requested media toolsets and retains task state in Redis for 24 hours. - POST https://twelver.app/api/ai//v1/media/files — upload an input asset (multipart/form-data, field file) for image-to-image, image-to-video, or transcription; returns a signed URL to pass in files. - POST https://twelver.app/api/ai//v1/media/generations — start a generation task ({ id, status: "running", output, error }). - GET https://twelver.app/api/ai//v1/media/generations/:taskId — poll status ("running" | "completed" | "failed") and read finished signed URLs from output.files. - GET https://twelver.app/api/ai//v1/media/generations/schema — inspect the live request/response schema and registered toolset slugs. **curl — submit & poll a generation job** ```bash # 1. Submit a generation job curl -X POST "https://twelver.app/api/ai//v1/media/generations" \ -H "Authorization: Bearer sk-..." \ -H "Content-Type: application/json" \ -d '{ "prompt": "Minimalist geometric emblem on a clean white background", "toolsets": [ "image-generation" ] }' # 2. Poll task status (24h TTL) curl "https://twelver.app/api/ai//v1/media/generations/" \ -H "Authorization: Bearer sk-..." ``` ## Request & Response Schema (@contract/media-api) Exact JSON shape validated by the router and returned by GET /schema: **MEDIA_API_SCHEMA** ```json { "request": { "prompt": "string", "toolsets": [ "string" ], "files": [ { "url": "string", "content_type": "string", "description": "string" } ] }, "response": { "status": "running | completed | failed", "id": "string", "error": { "message": "string" }, "output": { "text": "string", "files": [ { "url": "string", "content_type": "string", "description": "string" } ] } } } ``` ## Public Media Toolset IDs Pass one or more of the following toolset slugs in the toolsets array: | Toolset ID | Category | Required plan | Tools exposed | | --- | --- | --- | --- | | image-generation | image | Any (incl. starter) | describe-image, text-to-image, image-to-image, images-to-image | | grok-image-generation | image | Pro+ | grok-text-to-image, grok-image-to-image, grok-images-to-image | | seedream-image-generation | image | Pro+ | seedream-text-to-image, seedream-image-to-image, seedream-multi-image-blend | | ideogram-image-generation | image | Pro+ | ideogram-generate, ideogram-remix, ideogram-edit, ideogram-remove-background, ideogram-vectorize | | grok-video-generation | video | Pro+ | grok-text-to-video, grok-image-to-video, grok-video-to-video, grok-reference-images-to-video | | seedance-video-generation | video | Any (incl. starter) | seedance-text-to-video, seedance-image-to-video, seedance-multimodal-to-video, seedance-edit-video, seedance-extend-video, seedance-finalize-video | | seedance-economy-video | video | Any (incl. starter) | seedance-economy-text-to-video, seedance-economy-image-to-video, seedance-economy-multimodal-to-video, seedance-economy-edit-video, seedance-economy-extend-video | | google-video-generation | video | Any (incl. starter) | google-text-to-video, google-image-to-video, google-reference-images-to-video, google-edit-video, google-extend-video | | hailuo-video-generation | video | Any (incl. starter) | hailuo-text-to-video, hailuo-image-to-video, hailuo-frames-to-video, hailuo-reference-to-video, hailuo-regenerate-video | | happyhorse-video-generation | video | Any (incl. starter) | happyhorse-text-to-video, happyhorse-image-to-video, happyhorse-reference-to-video, happyhorse-edit-video | | wan-video-generation | video | Pro+ | wan-text-to-video, wan-image-to-video, wan-reference-to-video, wan-edit-video | | media-manipulation | video | Any (incl. starter) | media-video-stitch, media-video-trim, media-video-crop, media-video-resize, media-video-add-audio, media-video-extract-audio, media-video-extract-frame, media-video-contact-sheet, media-video-to-gif, media-images-to-video, media-video-overlay-image, media-video-inspect, media-audio-stitch, media-audio-trim, media-audio-mix, media-image-resize, media-image-crop, media-image-rotate, media-image-split-grid | | google-music | audio | Any (incl. starter) | google-text-to-music | | minimax-music | audio | Any (incl. starter) | minimax-text-to-music, minimax-music-cover, minimax-music-cover-analyze, minimax-generate-lyrics | | google-audio-speech | audio | Any (incl. starter) | google-text-to-speech, google-text-to-speech-dialogue, google-voice-design, google-list-voices | | qwen-audio-speech | audio | Any (incl. starter) | qwen-text-to-speech, qwen-voice-clone, qwen-list-voices | | grok-audio-speech | audio | Any (incl. starter) | grok-text-to-speech | | speech-to-text | audio | Any (incl. starter) | transcribe-audio, transcribe-video | | web-search | search | Any (incl. starter) | web-search, web-crawl | | perplexity-search | search | Any (incl. starter) | perplexity-search, perplexity-read | | image-search | search | Any (incl. starter) | image-search-by-text, image-search-by-image, image-search-fetch | | document | documents | Any (incl. starter) | write-document, create-document, update-document, read-document, export-document | | code | documents | Any (incl. starter) | write-code, create-code, update-code | | webapp | documents | Any (incl. starter) | write-webapp, create-webapp, update-webapp, publish-webapp | | presentation | documents | Any (incl. starter) | write-presentation, create-presentation, update-presentation | | graphic | documents | Any (incl. starter) | write-graphic, create-graphic, update-graphic | | agents | other | Any (incl. starter) | | ## Frequently Asked Questions ### How does async media generation work from start to finish? Submit POST https://twelver.app/api/ai//v1/media/generations with toolset, tool, and params to receive HTTP 202 and a taskId, then poll GET https://twelver.app/api/ai//v1/media/generations/:taskId until status reaches completed or failed. ### How do I pass source images, audio, or video into a media task? Upload the file as multipart/form-data to POST https://twelver.app/api/ai//v1/media/files and pass the returned fileId inside params (for example, imageFileIds or audioFileId). ### How long are media task records retained for polling? Task state remains queryable for 24 hours after creation; download completed media outputs to your own storage once finished. --- # Twelver Remote MCP API: Streamable HTTP Toolset Servers > Endpoint pattern /api/mcp/v1/, Bearer sk-… vs OAuth 2.1 authentication, plan tier gates, and the full catalog of MCP toolsets and methods. Canonical URL: https://twelver.app/docs/en/api/mcp/ ## Remote MCP Connection Pattern Every Twelver toolset is served as a standalone remote Streamable HTTP MCP endpoint at https://twelver.app/api/mcp/v1/. Unlike Chat Completions and the Media API, MCP URLs do not take a . Authenticate either with header Authorization: Bearer sk-… or via browser OAuth 2.1 in clients such as Claude Desktop, Claude Code, and Cursor. **mcp.json (Claude Code / Cursor / MCP clients)** ```json { "mcpServers": { "twelver-image": { "type": "http", "url": "https://twelver.app/api/mcp/v1/image-generation", "headers": { "Authorization": "Bearer sk-..." } } } } ``` ## MCP Toolset Catalog (27) Mount only the toolset endpoints your agent needs so tool schemas stay compact in prompt context: | Toolset | Endpoint URL | Plan tier | Count | Tool names | | --- | --- | --- | --- | --- | | image-generation | https://twelver.app/api/mcp/v1/image-generation | Any (incl. starter) | 4 | describe-image, text-to-image, image-to-image, images-to-image | | grok-image-generation | https://twelver.app/api/mcp/v1/grok-image-generation | Pro+ | 3 | grok-text-to-image, grok-image-to-image, grok-images-to-image | | seedream-image-generation | https://twelver.app/api/mcp/v1/seedream-image-generation | Pro+ | 3 | seedream-text-to-image, seedream-image-to-image, seedream-multi-image-blend | | ideogram-image-generation | https://twelver.app/api/mcp/v1/ideogram-image-generation | Pro+ | 5 | ideogram-generate, ideogram-remix, ideogram-edit, ideogram-remove-background, ideogram-vectorize | | grok-video-generation | https://twelver.app/api/mcp/v1/grok-video-generation | Pro+ | 4 | grok-text-to-video, grok-image-to-video, grok-video-to-video, grok-reference-images-to-video | | seedance-video-generation | https://twelver.app/api/mcp/v1/seedance-video-generation | Any (incl. starter) | 6 | seedance-text-to-video, seedance-image-to-video, seedance-multimodal-to-video, seedance-edit-video, seedance-extend-video, seedance-finalize-video | | seedance-economy-video | https://twelver.app/api/mcp/v1/seedance-economy-video | Any (incl. starter) | 5 | seedance-economy-text-to-video, seedance-economy-image-to-video, seedance-economy-multimodal-to-video, seedance-economy-edit-video, seedance-economy-extend-video | | google-video-generation | https://twelver.app/api/mcp/v1/google-video-generation | Any (incl. starter) | 5 | google-text-to-video, google-image-to-video, google-reference-images-to-video, google-edit-video, google-extend-video | | hailuo-video-generation | https://twelver.app/api/mcp/v1/hailuo-video-generation | Any (incl. starter) | 5 | hailuo-text-to-video, hailuo-image-to-video, hailuo-frames-to-video, hailuo-reference-to-video, hailuo-regenerate-video | | happyhorse-video-generation | https://twelver.app/api/mcp/v1/happyhorse-video-generation | Any (incl. starter) | 4 | happyhorse-text-to-video, happyhorse-image-to-video, happyhorse-reference-to-video, happyhorse-edit-video | | wan-video-generation | https://twelver.app/api/mcp/v1/wan-video-generation | Pro+ | 4 | wan-text-to-video, wan-image-to-video, wan-reference-to-video, wan-edit-video | | media-manipulation | https://twelver.app/api/mcp/v1/media-manipulation | Any (incl. starter) | 19 | media-video-stitch, media-video-trim, media-video-crop, media-video-resize, media-video-add-audio, media-video-extract-audio, media-video-extract-frame, media-video-contact-sheet, media-video-to-gif, media-images-to-video, media-video-overlay-image, media-video-inspect, media-audio-stitch, media-audio-trim, media-audio-mix, media-image-resize, media-image-crop, media-image-rotate, media-image-split-grid | | google-music | https://twelver.app/api/mcp/v1/google-music | Any (incl. starter) | 1 | google-text-to-music | | minimax-music | https://twelver.app/api/mcp/v1/minimax-music | Any (incl. starter) | 4 | minimax-text-to-music, minimax-music-cover, minimax-music-cover-analyze, minimax-generate-lyrics | | google-audio-speech | https://twelver.app/api/mcp/v1/google-audio-speech | Any (incl. starter) | 4 | google-text-to-speech, google-text-to-speech-dialogue, google-voice-design, google-list-voices | | qwen-audio-speech | https://twelver.app/api/mcp/v1/qwen-audio-speech | Any (incl. starter) | 3 | qwen-text-to-speech, qwen-voice-clone, qwen-list-voices | | grok-audio-speech | https://twelver.app/api/mcp/v1/grok-audio-speech | Any (incl. starter) | 1 | grok-text-to-speech | | speech-to-text | https://twelver.app/api/mcp/v1/speech-to-text | Any (incl. starter) | 2 | transcribe-audio, transcribe-video | | web-search | https://twelver.app/api/mcp/v1/web-search | Any (incl. starter) | 2 | web-search, web-crawl | | perplexity-search | https://twelver.app/api/mcp/v1/perplexity-search | Any (incl. starter) | 2 | perplexity-search, perplexity-read | | image-search | https://twelver.app/api/mcp/v1/image-search | Any (incl. starter) | 3 | image-search-by-text, image-search-by-image, image-search-fetch | | document | https://twelver.app/api/mcp/v1/document | Any (incl. starter) | 5 | write-document, create-document, update-document, read-document, export-document | | code | https://twelver.app/api/mcp/v1/code | Any (incl. starter) | 3 | write-code, create-code, update-code | | webapp | https://twelver.app/api/mcp/v1/webapp | Any (incl. starter) | 4 | write-webapp, create-webapp, update-webapp, publish-webapp | | presentation | https://twelver.app/api/mcp/v1/presentation | Any (incl. starter) | 3 | write-presentation, create-presentation, update-presentation | | graphic | https://twelver.app/api/mcp/v1/graphic | Any (incl. starter) | 3 | write-graphic, create-graphic, update-graphic | | agents | https://twelver.app/api/mcp/v1/agents | Any (incl. starter) | 0 | | ## Frequently Asked Questions ### Does the Remote MCP API require a model-series config-id? No. Every toolset is mounted directly at https://twelver.app/api/mcp/v1/ and bills the underlying tool rate against your token balance without needing a config-id. ### Should I authenticate MCP clients with a Bearer API key or OAuth 2.1? IDE and CLI agents (Cursor, OpenCode, Cline, Codex) can pass Authorization: Bearer with an sk-… key directly in mcpServers headers. Browser-backed clients like Claude also support OAuth 2.1, and external ad-account connectors require user OAuth. ### Why do some MCP toolsets require a paid tier when I still have starter tokens? Compute-heavy media and research toolsets enforce a plan-tier gate (Basic+, Pro+, or Premium) on selection, whereas open toolsets run on any positive token balance. --- # Error Codes, Streaming, Caching & Billing — Twelver API > OpenAI-compatible error envelopes (400, 401, 402, 404, 429, 502/503), in-band SSE stream errors, token reservation & settlement, and prompt caching. Canonical URL: https://twelver.app/docs/en/api/errors/ ## HTTP Status Codes & OpenAI Error Envelopes All pre-stream errors return the standard OpenAI { error: { message, type, code, param } } envelope so official SDKs distinguish quota exhaustion (402), invalid parameters (400/404), and retryable upstream faults (429/502/503). | HTTP | error.type | error.code | Retryable | When it happens | Client action | | --- | --- | --- | --- | --- | --- | | 400 | invalid_request_error | invalid_request | No | Invalid JSON body, unsupported reasoning_effort value, or custom temperature without reasoning_effort="none" on Responses-bridged series. | Fix request parameters before retrying; hold is not charged. | | 400 | invalid_request_error | content_filter | No | Upstream provider rejected the prompt via safety inspection (e.g. data_inspection_failed). | Rephrase input; token reservation is refunded in full. | | 401 | invalid_request_error | unauthorized | No | Missing Authorization: Bearer sk-… header, revoked key, or config-id owned by a different user. | Verify the Authorization header and confirm the API key and config-id belong to the same account. | | 402 | insufficient_quota | insufficient_quota | No | Token balance is below the pre-request estimate. | Do not retry with backoff; top up at the /upgrade URL returned in error.message. | | 404 | invalid_request_error | model_not_found | No | Unknown model string (such as a raw vendor checkpoint instead of a series key). | Call GET /:configId/v1/models and pass a public series key (auto, qwen, qwen-max, zai, grok, deepseek, gpt, etc.). | | 429 | upstream_error | rate_limit_exceeded | Yes | Transient upstream provider rate limit. | Retry with exponential backoff; failed pre-stream calls refund their hold. | | 502 | upstream_error | upstream_unavailable | Yes | Upstream model provider gateway failure before output started. | Retry after a short delay; token hold is refunded. | | 503 | upstream_error | upstream_unavailable | Yes | Upstream provider temporarily overloaded. | Retry with backoff or fall back to another series. | **Example 402 insufficient_quota response** ```json { "error": { "message": "Twelver: out of tokens. Top up at https://twelver.app/upgrade to keep using this key.", "type": "insufficient_quota", "code": "insufficient_quota", "param": null } } ``` ## In-Band SSE Errors, Token Settlement & Prompt Caching New accounts start with 0.25M starter tokens; monthly plans on this domain: Basic: $13 (10.4M) · Pro: $20 (16M) · Premium: $49 (39.2M). - Reservation & settlement: billedText places a pre-flight hold sized from the message payload (including image token estimates) and settles against exact provider usage on completion. Any request rejected before streaming begins refunds the hold in full. - Mid-stream errors (stream: true): if an upstream failure occurs after HTTP 200 SSE headers are flushed, the proxy emits data: {"error":{...}} followed by data: [DONE]. Inspect parsed chunks for top-level error objects. - Prompt caching: tokens reported under prompt_tokens_details.cached_tokens automatically bill at each model’s discounted cache-hit rate (e.g. 5% of input on Qwen4-Max, 20% on Qwen3.7-Plus, 10% on DeepSeek V4). Keep system prompts and tool definitions byte-stable at the start of messages to maximize cache hits. ## Frequently Asked Questions ### Which HTTP error codes should my client retry automatically? Retry only 429 (rate_limit_exceeded) and 502/503 (upstream_unavailable) with exponential backoff. Do not retry 400, 401, 402 (insufficient_quota), or 404 without fixing the request or topping up. ### How are errors surfaced mid-stream when stream: true is enabled? Once HTTP 200 SSE headers are flushed, mid-stream upstream faults arrive as an in-band event data: {"error": {...}} right before data: [DONE]. Always check parsed SSE chunks for an error object. ### Are reserved tokens refunded on upstream failure, and how does prompt caching bill? Any request rejected before streaming begins refunds the pre-flight hold in full, and completed calls settle to exact provider usage. Tokens reported in prompt_tokens_details.cached_tokens automatically bill at each series’ discounted cache rate.