RouterShiftRouterShift
Browse ModelsPricingDocs
RouterShiftRouterShiftRouterShift. Enterprise AI Infrastructure.
Browse ModelsStatusDocsTermsPrivacyDPATransparency

API Documentation

OverviewPlatform capabilitiesQuickstartSDKs & agentsAuthenticationMaking RequestsRate limitsBilling & PricingPrivate AccessDual-Currency SettlementError Handling
API Reference

RouterShift API Overview

RouterShift provides OpenAI-, Anthropic-, and Gemini-compatible data-plane interfaces for the models currently active for your key. Routing, failover, billing, and audit evidence are applied behind the protocol boundary.

Key Features

  • OpenAI-compatible API — drop-in replacement for any OpenAI SDK client
  • Smart routing with configurable strategies (weighted, round-robin, latency-based, failover)
  • Built-in circuit breaker and rate limiting to protect your application
  • Semantic caching to reduce latency and costs on repeated queries
  • Comprehensive logging, monitoring, and spend analytics
  • Multi-provider support with automatic failover when a provider is unavailable

OpenAI-Compatible Base URL

Fully compatible with OpenAI client libraries. Just change the SDK base_url to the address below with your RouterShift API key.

https://api.routershift.com/v1

Anthropic-Compatible Base URL

For Anthropic SDK or Claude Code. Note: no /v1 suffix — the SDK auto-appends /v1/messages.

https://api.routershift.com

Multi-Protocol Compatible

OpenAI, Anthropic, and Gemini clients can usually connect by changing the base URL and credential. Native-protocol extensions are not automatically portable across protocols: bridging supports only fields whose meaning can be represented equivalently. Use the live OpenAPI contract for documented interfaces; actual route and model restrictions still apply.

Supported Model Categories

Use GET /v1/models as the authority for models available to your key. Availability can vary with product activation, route health, permissions, balance, region, and private-access policy.

Getting Help

If you encounter issues or have questions, check the sections below for detailed guides. For billing inquiries, contact support through the console. For real-time status updates, visit the Status page.

Full Endpoint List

The table is a human-readable index of the public data plane. Use /api/openapi.yaml for the machine contract and /api/docs for interactive reference; key scopes still apply per endpoint and model.

GET/v1/version

Data-plane API version and compatibility information

GET/v1/models

Model Listing

POST/v1/chat/completions

Chat Completions (OpenAI-compatible)

POST/v1/messages

Messages API (Anthropic-compatible)

POST/v1/messages/count_tokens

Messages token estimate (text, thinking and tools; not exact native usage)

POST/v1/models/gemini/:model/generateContent

Gemini content generation

POST/v1/models/gemini/:model/streamGenerateContent

Gemini Stream Generate Content

POST/v1/embeddings

Text Embeddings

POST/v1/rerank

Rerank

POST/v1/chat/completions/estimate

Preflight token and cost estimate

POST/v1/images/generations

Image Generation

GET/v1/images/tasks/:id

Image task — check an existing task, without resubmitting generation

POST/v1/audio/transcriptions

Audio Transcription

POST/v1/audio/speech

Text to Speech

POST/v1/tts

Extended Text to Speech

POST/v1/transcriptions

Extended Transcription

POST/v1/midjourney/imagine

Midjourney Image Generation

POST/v1/suno/generate

Suno Music Generation

POST/v1/video/generations

Video generation task

GET/v1/video/tasks/:task_id

Video generation task status

POST/v1/chat/completions/async

Async Task — Submit

GET/v1/chat/completions/async/:task_id

Async Task — Check Status

GET/v1/chat/completions/async/:task_id/result

Async Task — Get Result

POST/v1/batch

Batch Processing

GET/v1/batch/:batch_id

Batch job status

GET/v1/batch/:batch_id/results

Batch result download

POST/v1/batch/:batch_id/cancel

Cancel a batch job

POST/v1/mcp/

MCP JSON-RPC tools gateway

GET/v1/mcp/sse

MCP SSE transport

POST/v1/a2a/

A2A JSON-RPC gateway

GET/v1/a2a/sse

A2A SSE event stream

MethodPathDescription
GET/v1/versionData-plane API version and compatibility information
GET/v1/modelsModel Listing
POST/v1/chat/completionsChat Completions (OpenAI-compatible)
POST/v1/messagesMessages API (Anthropic-compatible)
POST/v1/messages/count_tokensMessages token estimate (text, thinking and tools; not exact native usage)
POST/v1/models/gemini/:model/generateContentGemini content generation
POST/v1/models/gemini/:model/streamGenerateContentGemini Stream Generate Content
POST/v1/embeddingsText Embeddings
POST/v1/rerankRerank
POST/v1/chat/completions/estimatePreflight token and cost estimate
POST/v1/images/generationsImage Generation
GET/v1/images/tasks/:idImage task — check an existing task, without resubmitting generation
POST/v1/audio/transcriptionsAudio Transcription
POST/v1/audio/speechText to Speech
POST/v1/ttsExtended Text to Speech
POST/v1/transcriptionsExtended Transcription
POST/v1/midjourney/imagineMidjourney Image Generation
POST/v1/suno/generateSuno Music Generation
POST/v1/video/generationsVideo generation task
GET/v1/video/tasks/:task_idVideo generation task status
POST/v1/chat/completions/asyncAsync Task — Submit
GET/v1/chat/completions/async/:task_idAsync Task — Check Status
GET/v1/chat/completions/async/:task_id/resultAsync Task — Get Result
POST/v1/batchBatch Processing
GET/v1/batch/:batch_idBatch job status
GET/v1/batch/:batch_id/resultsBatch result download
POST/v1/batch/:batch_id/cancelCancel a batch job
POST/v1/mcp/MCP JSON-RPC tools gateway
GET/v1/mcp/sseMCP SSE transport
POST/v1/a2a/A2A JSON-RPC gateway
GET/v1/a2a/sseA2A SSE event stream

Protocol Correspondence

RouterShift is compatible with multiple API protocols. The table below shows the base URL and SDK configuration for each.

OpenAI Compatible

https://api.routershift.com/v1

Models: <available-model-code>

Authorization: Bearer / x-api-key

Anthropic Compatible

https://api.routershift.com

Models: <available-model-code>

x-api-key: sk-xxx

Gemini Native

https://api.routershift.com/v1

Models: <available-model-code>

Authorization: Bearer

Base URLExample Model ParameterAuth Header
https://api.routershift.com/v1
Standard OpenAI SDK — just change base_url
<available-model-code>Authorization: Bearer / x-api-key
https://api.routershift.com
Standard Anthropic SDK — just change base_url
<available-model-code>x-api-key: sk-xxx
https://api.routershift.com/v1
Gemini native format, call generateContent directly
<available-model-code>Authorization: Bearer

Unified Authentication

All endpoints use the same authentication. Both header formats work identically:

OpenAI-compatible format

Authorization: Bearer sk-xxx

Anthropic-compatible format

x-api-key: sk-xxx

Platform capabilities

RouterShift API Overview

RouterShift provides OpenAI-, Anthropic-, and Gemini-compatible data-plane interfaces for the models currently active for your key. Routing, failover, billing, and audit evidence are applied behind the protocol boundary.

RouterShift uses prepaid wallets and request-level price snapshots. Successful requests debit the customer sale price; image, audio, video, and other products settle on their configured native billing dimensions.

Key Features

Use GET /v1/models as the authority for models available to your key. Availability can vary with product activation, route health, permissions, balance, region, and private-access policy.

  • OpenAI-compatible API — drop-in replacement for any OpenAI SDK client
  • Smart routing with configurable strategies (weighted, round-robin, latency-based, failover)
  • Built-in circuit breaker and rate limiting to protect your application
Open

Quickstart Guide

Get started with RouterShift in under 3 minutes. Follow the 5-step onboarding flow to go from registration to monitoring.

  • 1. Register
  • 2. Create API Key
  • 3. Add Funds
Open

Making Requests

RouterShift provides chat, embeddings, model discovery and other supported endpoints. Use the request and response format of the selected OpenAI-, Anthropic- or Gemini-compatible endpoint.

  • Streaming Responses
  • Async Requests
  • Batch Processing
Open

Private Access

Private Access supports BYOK and external AI account pools to deliver controlled access channels with flexible pricing and fallback behavior.

  • BYOK Integration
  • Account Pools
  • Failure Fallback
Open

Add model tools to an Agent

Add tools to an Agent through MCP, or use the Python/Node SDK in application code: these are parallel access options. Follow these four local stdio steps and keep credentials out of shared configuration and version control.

  • Create a dedicated directory and install MCP
  • Configure the local stdio client
  • Restart the connector and verify eight tools
Open

Billing & Pricing

RouterShift uses prepaid wallets and request-level price snapshots. Successful requests debit the customer sale price; image, audio, video, and other products settle on their configured native billing dimensions.

  • Pricing Model
  • Wallet & Credits
  • Billing & Invoices
Open

Quickstart Guide

Get started with RouterShift in under 3 minutes. Follow the 5-step onboarding flow to go from registration to monitoring.

1. Register

Create an account when self-registration is enabled, or follow the invitation and account flow supplied by your administrator.

2. Create API Key

Create a named API key and restrict its models, budget, expiry, IP ranges, and other scopes to the minimum your application needs.

3. Add Funds

Query GET /v1/models, review the approved customer sale price and native billing dimensions, then ensure the matching CNY or USD wallet has sufficient available balance.

4. Make Your First Call

Use the curl or SDK example below. Replace YOUR_API_KEY and YOUR_MODEL_CODE with values from your console and the runtime model catalog.

curl "https://api.routershift.com/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ROUTERSHIFT_API_KEY" \
  -d '{
  "model": "YOUR_MODEL_CODE",
  "messages": [
    {
      "role": "user",
      "content": "Hello!"
    }
  ],
  "max_tokens": 100
}'

5. Monitor Usage

Reconcile status, latency, token or native usage dimensions, cache source, and customer spend by date, model, and API key. Configure budgets and alerts where available.

SDK and agent integrations

Use a standard compatible client today or adopt the first-party Python and Node.js data-plane SDKs. Both choices share the same live API contract.

SDK 0.3.4 downloads

Download version 0.3.4 directly from this page. Python requires 3.9 or later; Node.js and local MCP require Node 20 or later. These version-pinned website archives do not imply publication on npm or PyPI. Regular Node SDK users do not need the optional MCP dependencies.

python -m pip install "https://routershift.com/downloads/sdk/routershift-0.3.4-py3-none-any.whl"
Download Python wheelDownload Node.js archiveView SHA-256 checksums

List models visible to your API key

Run this read-only request first and copy an exact model code into the examples below. The list shows what the key can see; it does not prove that every operation or mode is enabled for that model.

import os
from routershift import RouterShift

client = RouterShift(api_key=os.environ["ROUTERSHIFT_API_KEY"])
models = client.models.list()
print([model.id for model in models])

Text conversations

Python, Node and MCP can call text models. Agents can keep their primary model and call RouterShift when needed. Model permissions and charges stay in the same API.

import os
from routershift import RouterShift

client = RouterShift(api_key=os.environ["ROUTERSHIFT_API_KEY"])
response = client.chat.completions.create(
    model="YOUR_TEXT_MODEL_CODE",
    messages=[{"role": "user", "content": "Summarize this project in one sentence."}],
)
print(response.choices[0].message.content)

HTTP Omni requests

This example sends WAV audio and requests text and audio over an HTTP stream. Choose an accepted OpenAI-compatible route, with stream mode and voice supported by the model. SSE-only models require stream:true; routershift_chat also accepts this option. The SDK preserves content parts, audio, modalities, tool calls and audio responses. HTTP Omni does not provide Realtime WebSockets or arbitrary cross-provider protocol conversion.

import base64
import os
from pathlib import Path
from routershift import RequestOptions, RouterShift

client = RouterShift(api_key=os.environ["ROUTERSHIFT_API_KEY"])
audio_data = base64.b64encode(Path("/absolute/path/to/sample.wav").read_bytes()).decode()
response = client.chat.completions.create(
    model="YOUR_OMNI_MODEL_CODE",
    messages=[{"role": "user", "content": [
        {"type": "text", "text": "Describe the sound."},
        {"type": "input_audio", "input_audio": {"data": audio_data, "format": "wav"}},
    ]}],
    stream=True,
    modalities=["text", "audio"],
    audio={"voice": "YOUR_MODEL_VOICE", "format": "wav"},
    request_options=RequestOptions(max_retries=0),
)
for chunk in response:
    if chunk.choices:
        delta = chunk.choices[0].delta or {}
        print(delta.get("content", ""), end="")
        if delta.get("audio"):
            print(delta["audio"].get("transcript", ""), end="")

Speech generation

audio.speech calls /v1/audio/speech. Python returns audio bytes; Node returns data bytes and the actual contentType. Choose a voice and format supported by the model. Returned audio is not automatically saved locally. The exact qwen3-tts-flash-2025-11-27 bailian.tts.characters contract is REST-only URL-TTS: submit response_mode=json to /v1/tts or /v1/audio/speech. It returns audio_url, not embedded audio; ordinary SDK byte methods and local MCP audio tools do not support that envelope. Billing evidence is native weighted usage.characters, not local character counts, bytes or playback duration. Seed Audio bills native original_duration, not playback duration or subtitle timing. These contracts still require independent product, pricing, binding and acceptance gates; documentation does not activate drafts.

import os
from routershift import RouterShift

client = RouterShift(api_key=os.environ["ROUTERSHIFT_API_KEY"])
speech = client.audio.speech(
    model="YOUR_SPEECH_MODEL_CODE",
    input="Welcome to RouterShift.",
    voice="YOUR_MODEL_VOICE",
    response_format="wav",
)
print(len(speech))

Audio transcription

audio.transcribe submits the explicitly selected audio file as multipart to /v1/audio/transcriptions. Keep its actual filename extension. This example requests JSON and reads text; supported languages and formats depend on the route.

import os
from pathlib import Path
from routershift import RouterShift

client = RouterShift(api_key=os.environ["ROUTERSHIFT_API_KEY"])
transcript = client.audio.transcribe(
    model="YOUR_TRANSCRIPTION_MODEL_CODE",
    file=Path("/absolute/path/to/sample.wav").read_bytes(),
    filename="sample.wav",
    response_format="json",
)
print(transcript.text)

Transcribe an HTTPS audio URL

Use audio.transcribe_url in Python, audio.transcribeURL in Node.js, or POST JSON to /v1/transcriptions with file_url. The SDK validates the HTTPS URL and does not download the recording locally. FunASR/Qwen ASR public JSON returns segments/words only when valid native timing is present. Their start/end values are seconds converted from native milliseconds; missing or invalid timing is not invented and is marked by timestamps_omitted. Subtitle timing and playback duration are not billing evidence: billing uses the contract's native final or cumulative duration, without summing cumulative reports. Missing or conflicting evidence requires reconciliation, not resubmission. The Go and Java tabs use their standard HTTP clients; RouterShift does not claim first-party Go or Java SDKs.

import os
from routershift import RouterShift

client = RouterShift(api_key=os.environ["ROUTERSHIFT_API_KEY"])
transcript = client.audio.transcribe_url(
    "YOUR_TRANSCRIPTION_MODEL_CODE",
    "https://media.example/recording.wav",
    language="en",
    audio_format="wav",
    response_format="json",
)
print(transcript.text)

Generate images and read image tasks

Use images.generate with a model enabled for image generation. On models that support asynchronous images, add async_=True in Python or async: true in Node.js, then query the returned id with images.retrieve. A completed response contains data with image URLs; a pending response contains an id and status.

import os
from routershift import ImageTaskResponse, RouterShift

client = RouterShift(api_key=os.environ["ROUTERSHIFT_API_KEY"])
image = client.images.generate(
    model="YOUR_IMAGE_MODEL_CODE",
    prompt="A quiet garden in watercolor",
)
print(image)
if isinstance(image, ImageTaskResponse):
    print(client.images.retrieve(image.id))

Submit a video and query its status

videos.create submits one video task and returns task_id. Save it before querying videos.retrieve; a pending task may not have video_url yet. Both SDKs also provide videos.poll for bounded waiting. The API path is /v1/video/generations, with singular video.

Verified native Seedance and Wan 3.0 routes support generate_audio: omit it for the provider default, false for no audio track, true for audio. Wan maps it to parameters.audio and currently defaults to sound. Audio on/off uses the same Wan video tariff, without an extra audio charge. Other routes may not support it; explicit values must not be silently dropped.

import os
from routershift import RouterShift

client = RouterShift(api_key=os.environ["ROUTERSHIFT_API_KEY"])
task = client.videos.create(
    model="YOUR_VIDEO_MODEL_CODE",
    prompt="A slow camera movement through a garden",
)
print(task.task_id)
result = client.videos.retrieve(task.task_id)
print(result.status, result.video_url)

Choose parameters by model

Use only parameters accepted for the selected model and operation. Preserve explicit false and seed=0; omission leaves the upstream default unchanged. These notes describe implementation, not verified live availability.

  • Qwen Image 3.0: seed, watermark, prompt_extend and enable_thinking are model-specific controls. prompt_extend_mode accepts direct or agent; agent requires prompt extension and is not for image editing. enable_thinking applies only when prompt extension is enabled and does not implicitly enable prompt_extend.
  • Wan 3.0 video: seed, watermark and prompt_extend are model-specific controls. Use generate_audio for audio generation; whether it is optional, required or unsupported depends on the selected model. file/link media requires prompt_extend=true or omission; explicit false is rejected.
  • Ark Seedance: the current platform route does not accept seed or prompt_extend. Do not reuse Qwen or Wan parameters across providers.

Code support is not deployment, and deployment is not product acceptance. Advanced editing, video extension, MOV, Draft, HappyHorse, Wan 2.7, Animate and VACE under offline development do not imply enabled products. Confirm the exact model, operation and parameters before a paid submission.

Reference images to first-frame video (REST, SDK, MCP)

This example uses three non-portrait HTTPS references to generate one image, then passes its returned HTTPS URL as image_url for the video first frame. Replace both model placeholders with codes visible to your key at /v1/models and separately accepted for those exact operations; visibility alone is not acceptance. The example's 720p and 5 seconds require support from the selected video route.

Ark: use an accepted Seedream Pro image-edit route and Seedance first-frame route. Only a model that accepts three references may use this input; 2048x1152 is not a global size. Real-person portraits have separate rules; a same-account text-to-image exception does not authorize three-photo fusion.

Bailian: an accepted Qwen Image 3.0 editing route supports one to three references and returns a URL; do not expect b64_json or assume asynchronous image mode is enabled. Wan first-frame video uses image_url. Resolution and duration must be accepted by the selected route; a supplier console capability does not prove platform route acceptance.

The tabs describe one sequence, not automatic retries. For REST or MCP, call each step separately. Skip image-task lookup if a completed image URL is already returned; otherwise query the original image task once and continue only with a usable HTTPS URL. Save the video task_id and query that same task once; a pending task can be queried later.

REST and SDK image tasks return id, while video tasks return task_id. Local MCP results instead expose structuredContent.task_id when a task ID is present: inspect isError and next_action, then use structuredContent.outputs[].url or attached MCP image content. Only an actual HTTPS URL can be passed as video image_url; attached image content alone is not a URL. Never assume MCP returns REST data[0].url.

curl --fail-with-body --connect-timeout 10 --max-time 30 "https://api.routershift.com/v1/models" \
  -H "Authorization: Bearer $ROUTERSHIFT_API_KEY"

curl --fail-with-body --connect-timeout 10 --max-time 120 -i -X POST "https://api.routershift.com/v1/images/generations" \
  -H "Authorization: Bearer $ROUTERSHIFT_API_KEY" -H "Content-Type: application/json" \
  -d '{"model":"YOUR_ACCEPTED_IMAGE_MODEL_CODE","prompt":"Combine three landscapes into one scene","image":["https://media.example/landscape-1.png","https://media.example/landscape-2.png","https://media.example/landscape-3.png"],"n":1,"response_format":"url"}'

curl --fail-with-body --connect-timeout 10 --max-time 30 -i "https://api.routershift.com/v1/images/tasks/IMAGE_TASK_ID" \
  -H "Authorization: Bearer $ROUTERSHIFT_API_KEY"

A returned 400 rejection differs from a transport timeout with unknown submission outcome. On errors, retain the safe error code and message plus X-Request-ID (and a task ID if returned); do not expect raw upstream reasons or automatically resubmit a paid POST. A failed task lookup makes status unavailable, not generation failure. Waiting timeout does not cancel or refund work. Budget, charge and settlement follow platform records, not this example or a supplier's displayed price.

Add model tools to an Agent

Add tools to an Agent through MCP, or use the Python/Node SDK in application code: these are parallel access options. Follow these four local stdio steps and keep credentials out of shared configuration and version control.

  1. 1. Create a dedicated directory and install MCP

    Use Node 20 or later. This MCP-only installation adds the two protocol peer dependencies; a regular Node SDK installation does not need them.

    mkdir routershift-mcp
    cd routershift-mcp
    npm init -y
    npm install "https://routershift.com/downloads/sdk/routershift-sdk-0.3.4.tgz" @modelcontextprotocol/server@2.0.0 zod@4.6.4
  2. 2. Resolve the absolute server entry

    Run this in the new directory. It prints a JSON-escaped absolute path that you can paste into the configuration args array.

    node -p "JSON.stringify(require('node:path').resolve('node_modules/@routershift/sdk/dist/mcp/cli.js'))"
  3. 3. Configure the local stdio client

    Replace the example path, set the API key only in your local environment, and keep the trusted API origin without /v1, credentials, a query or fragment. The Codex tab uses its documented stdio and env_vars syntax.

    {
      "mcpServers": {
        "routershift": {
          "command": "node",
          "args": [
            "/absolute/path/to/your/project/node_modules/@routershift/sdk/dist/mcp/cli.js"
          ],
          "env": {
            "ROUTERSHIFT_API_KEY": "sk-REPLACE_LOCALLY",
            "ROUTERSHIFT_BASE_URL": "https://api.routershift.com"
          }
        }
      }
    }
  4. 4. Restart the connector and verify eight tools

    Restart or reload the MCP client, confirm that all eight tools appear, then call the read-only routershift_list_models first. Invoke a billed model tool only when you intend to submit that operation.

Eight tools are available: routershift_list_models, routershift_chat, routershift_generate_image, routershift_create_video, routershift_get_task, routershift_speech, routershift_transcribe, routershift_transcribe_url. First select a model supporting the operation. Query image/video tasks with routershift_get_task, supplying kind (image or video) and task_id.

routershift_chat accepts HTTPS image/video references; audio_file reads an explicitly selected absolute WAV/MP3 path, up to 16 MiB. routershift_transcribe reads one selected local audio file through file_path; routershift_transcribe_url passes one HTTPS file_url without downloading it. Speech and Omni audio outputs return inline audio. routershift_generate_image accepts response_format url or b64_json; for bounded, valid PNG, JPEG, WebP or GIF b64_json output, it returns MCP-native image content without writing, downloading or rehosting a file, and without copying Base64 into text JSON. Oversize or unknown-format image data is explicitly omitted; do not resubmit a paid request to retrieve omitted output. The adapter does not scan directories or automatically save results.

The JSON tab shows the common mcpServers shape; the TOML tab shows documented Codex syntax. Configuration locations and subprocess permissions differ by client. Remote-only MCP clients need a separately supported transport; these examples do not claim testing in every Agent UI.

The local MCP adapter lets Agents call RouterShift text, multimodal, audio and task APIs. The existing /v1/mcp gateway provides access to configured external tools. Its HTTP/SSE configuration does not replace the local model-tool configuration here.

Model access, waiting and billing

UGC platforms: submit once, save the task ID and original X-Request-ID, then query the same task. A business job ID is not a server replay guarantee. REST, SDK and MCP share one task and billing contract; switching access methods must not repeat an uncertain generation.

Keep submission, task execution, delivery and billing separate. Missing task IDs require investigation, not a new POST. A failed GET only makes status unavailable. If generation completed but download failed, recover delivery of the same known output. released and reconciliation_required end polling; neither proves success or a refund.

Async chat status/list retains status and adds execution_status, billing_status, reason_code, next_action and retry_allowed: false. completed means result-ready, not billing settled; unknown does not mean free or refunded. Image SDK _billing_status and MCP billing_status copy only the actual allowlisted X-Billing-Status header; absent or invalid headers remain absent. Querying never claims billing recovery or authorizes resubmission.

Copy the full request ID from user fees or administrator request logs, then search by exact request_id: nonempty valid UTF-8, at most 256 bytes, with no whitespace or control characters. Existing permissions and time/model filters still apply; no match does not prove no acceptance or charge. Keep the original submission ID separate from task IDs and later query IDs. CSV export still covers the whole selected time range, not the ID-filtered rows.

Control new submissions with your application's queue and per-user limits; use bounded, staggered polling. A timeout stops local waiting, not provider work. Mock concurrency tests do not certify the supplier's capacity for simultaneous generation.

Replace YOUR_* placeholders with your model codes, voices or task IDs. /v1/models lists codes visible to your key, not acceptance of text, Omni, image, video, audio or every execution mode. Verify the selected model’s inputs, outputs and enabled modes. This guide does not claim universal model or Realtime support.

Image, video, speech and transcription submissions are not automatically retried; MCP chat also submits once. A timeout or cancelled wait does not cancel provider work, refund it or make resubmission safe. Keep image id and video task_id for lookup. released and reconciliation_required are terminal states, not proof of successful generation.

SDK and MCP calls use the same API, prices, usage metering, wallet and settlement as direct requests. They add no separate balance or billing system. A returned result URL does not certify completed settlement; inspect the API billing status when available and your existing console records.

A quote's as_of is the lookup time, not a price-lock validity period. Accepted work settles using its frozen price contract and native actual usage, unaffected by later catalog or key-price updates. Frozen rates do not mean a fixed final amount. Missing or conflicting usage requires reconciliation, not a guessed charge. Recover the original task; do not generate again with new parameters.

First-party SDKs

Typed clients cover model discovery, chat, messages, embeddings, media and async workloads without exposing console-session APIs.

Compatible ecosystems

OpenAI, Anthropic and Gemini clients normally connect by changing the base URL and credential, so existing agent frameworks need minimal adaptation.

Agent protocols

MCP and A2A are protocol boundaries for tool and agent interoperability; applications consume stable behavior rather than routing internals.

Independent SDK releases

SDK packages are versioned, tested and released separately from platform deployment. Version 0.3.4 is available from this website; this does not claim npm or PyPI publication, and the live OpenAPI contract remains authoritative.

import os
from routershift import RouterShift

client = RouterShift(api_key=os.environ["ROUTERSHIFT_API_KEY"])
models = client.models.list()
print([model.id for model in models])
response = client.chat.completions.create(
    model="YOUR_MODEL_CODE",
    messages=[{"role": "user", "content": "Hello"}],
)

Authentication

All API requests require authentication using a Bearer token. You can generate and manage API keys from your console dashboard.

API Key Format

API keys begin with sk- followed by a unique identifier. Keep your API keys secure and never expose them in client-side code or version control.

Authorization Header

Include your API key in the Authorization header of every request:

Authorization: Bearer YOUR_API_KEY

Security Best Practices

  • Never hardcode API keys in your source code. Use environment variables or a secrets manager.
  • Rotate API keys regularly from the console dashboard — create new keys and revoke old ones without downtime.
  • Use separate API keys for development and production environments.
  • Set usage limits and IP restrictions on API keys for additional security.
  • Monitor key usage in the console dashboard for unusual activity.
  • Never commit API keys to version control. Add .env files to .gitignore.

Webhook HMAC Signatures

User webhook deliveries include X-RS-Signature with the HMAC-SHA256 hex digest of the request body. X-RS-Event and X-RS-Delivery identify the event and delivery.

Making Requests

RouterShift provides chat, embeddings, model discovery and other supported endpoints. Use the request and response format of the selected OpenAI-, Anthropic- or Gemini-compatible endpoint.

Chat Completions

Send a chat completion request with a model name, messages array, and optional parameters like temperature, max_tokens, and top_p. RouterShift routes your request to the appropriate provider based on your routing configuration.

Streaming Responses

Enable streaming by setting stream: true. RouterShift supports Server-Sent Events (SSE) for real-time token streaming. The stream format is compatible with the OpenAI streaming specification.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.routershift.com/v1",
    api_key=os.environ["ROUTERSHIFT_API_KEY"],
)
stream = client.chat.completions.create(
    model="YOUR_MODEL_CODE",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Async Requests

For long-running tasks or batch processing, use async mode. Submit a request and poll for results — useful for workloads exceeding typical timeout limits.

Batch Processing

Upload a JSONL file to POST /v1/batch and poll its status and results. Processing time and prices depend on the selected execution mode and model contract; batch submission alone does not guarantee a discount or a fixed completion time.

Embeddings

Generate vector embeddings for text using the /v1/embeddings endpoint. Embeddings are useful for semantic search, clustering, and retrieval-augmented generation (RAG).

Token Estimation

Send the chat payload to POST /v1/chat/completions/estimate to estimate tokens and cost before invocation. Estimates are not final charges; actual usage and the applicable price contract determine billing.

Rate Limits & Request Controls

Effective limits come from your API key, customer policy, model route, and upstream capacity. Treat response headers and console configuration as runtime facts.

Default Rate Limits

Platform keys return x-ratelimit-limit-{tps,rpm,tpm,tph} and x-ratelimit-remaining-{tps,rpm,tpm,tph} for enabled limits. Retry-After appears only when waiting can restore capacity, rounded up to whole seconds; it is not a retry guarantee. Without it, check the per-request allowance and policy. Never automatically resend a POST with an unknown outcome; use bounded backoff with jitter only for requests confirmed safe to retry.

HTTP Response Codes

429429 Too Many Requests — You have exceeded your rate limit. Check the Retry-After header and back off.
402402 Payment Required — Your account balance is insufficient. Add credits in the Billing section.
403403 Forbidden — The authenticated key is not permitted to use this model, route, or operation. Review key scopes and customer policy.
503503 Service Unavailable — No provider is currently available for the requested model. The circuit breaker may have temporarily disabled all providers.
401401 Unauthorized — Missing or malformed Authorization header.
400400 Bad Request — Invalid request parameters. Check the error message for details.

Billing & Pricing

RouterShift uses prepaid wallets and request-level price snapshots. Successful requests debit the customer sale price; image, audio, video, and other products settle on their configured native billing dimensions.

Pricing Model

Charges use the platform's approved customer sale price and lock the model, currency, price version, and billing dimensions per request. The public catalog shows developer list prices for comparison; provider cost prices are settlement facts and do not price customer debits.

Billing & Invoices

Reconcile calls, tokens, cache dimensions, and spend by date, model, and API key. Bills, invoices, and refunds reference server-held request pricing evidence, so later price changes never rewrite history.

Wallet & Credits

CNY and USD wallets are accounted for independently. Available cash already excludes frozen funds; do not subtract them again. Personal grace credit and platform backing are disabled by default and require separately approved credit and backing capital. Credit exposure and unpaid principal are not cash or automatic model access. Admission still requires reviewed metering and a proven cost bound. Live progress is not a final bill; unknown results or usage remain pending reconciliation. Recharge status follows confirmed payment receipt.

Packages & Coupons

Packages, promotions, coupons, or savings plans affect customer prices only when the platform has configured an applicable rule. Discount funding remains separate from provider native payables.

Reseller Commission Engine

Resellers earn a percentage of platform margin on every request from invited users. Per-model commission rate overrides allow granular partner programs — e.g., 15% on GPT-4o, 10% on Claude. Attribution is automatic via invite links; settlement is real-time per request.

Private Access

Private Access supports BYOK and external AI account pools to deliver controlled access channels with flexible pricing and fallback behavior.

BYOK Integration

Bind your own provider keys after activating Private Access. The upstream provider bills your account separately; RouterShift service fees follow the selected plan and any applicable waiver. BYOK does not mean all usage is free.

Account Pools

Support external account pools (including browser/CLI-assisted account systems) through one unified key bridge and policy layer.

Subscription Mode

Private Access is an optional value-added service. Review the selected plan's fixed monthly fee or usage-based service fee, billing currency, renewal setting and any waiver before activation. Core platform API usage remains pay-as-you-go.

Failure Fallback

If a private source is unavailable, eligible platform routes for the same model may be tried sequentially within your key and region permissions. Platform usage is charged at its applicable sale price and must pass balance and budget checks; a private-access subscription or fee waiver does not make it free.

Dual-Currency Settlement

A financial evidence chain across pricing, charging, revenue sharing, refunds, payments, and invoicing—not a display-only conversion. One account procures domestic and global models: customers retain a CNY purchasing and invoicing experience while overseas supply costs settle natively in the background.

Sale and cost currencies are separate

Domestic products are sold and invoiced in CNY. Customers do not absorb per-request FX volatility when an upstream provider charges USD.

Request-level price and FX snapshots

Cross-currency requests lock an approved FX version, price version, and actual wallet legs. Later FX changes never rewrite historical bills.

Native provider payables

Provider liabilities remain in the upstream currency while platform margin, reseller commission, and tax are recorded as distinct accounting facts.

Exact-path refunds and evidence

Wallet refunds reverse the original CNY/USD legs. Real re-conversions record FX gain or loss, and server-authoritative bills generate invoices and credit notes.

Error Handling

Understand common API errors and how to handle them gracefully in your application.

Error Response Structure

All errors follow the standard format with an error object containing a message, type, code, and param (if applicable).

{
  "error": {
    "message": "no upstream available",
    "type": "upstream_error",
    "code": "UPSTREAM_UNREACHABLE"
  },
  "request_id": "example-request-id"
}

Retry Strategy

Honor Retry-After when present. Retry only idempotent or safely replayable operations, use bounded exponential backoff with jitter, and stop after an application-defined attempt or time budget.

Common Error Types

  • invalid_request_error — Malformed request body or missing required parameters.
  • authentication_error — Invalid, expired, or revoked API key.
  • rate_limit_error — Too many requests. Slow down and respect Retry-After headers.
  • server_error — Temporary provider or platform issue. Retry with backoff.
  • upstream_error — No upstream is available or a provider attempt failed. Check error.code before deciding whether to retry.
  • content_filter_error — Request blocked by guardrails or content filter. Review the flagged content.

Structured Error Codes

OpenAI-compatible inference errors include the machine-readable field error.code. Use it for programmatic handling instead of parsing error messages.

AUTH_INVALIDInvalid credentials
AUTH_EXPIREDSession expired
AUTH_EMAIL_NOT_VERIFIEDEmail not verified
AUTH_INSUFFICIENTAccess denied
WALLET_LOWInsufficient balance
WALLET_EMPTYWallet is empty
RATE_LIMIT_GLOBALRate limit exceeded
RATE_LIMIT_KEYAPI key rate limit exceeded
RES_MODEL_NOT_FOUNDModel not found
UPSTREAM_UNREACHABLEUpstream provider unreachable
UPSTREAM_ERRORUpstream provider error
UPSTREAM_TIMEOUTUpstream provider timeout
INTERNAL_ERRORInternal server error
error.codeDescription
AUTH_INVALIDInvalid credentials
AUTH_EXPIREDSession expired
AUTH_EMAIL_NOT_VERIFIEDEmail not verified
AUTH_INSUFFICIENTAccess denied
WALLET_LOWInsufficient balance
WALLET_EMPTYWallet is empty
RATE_LIMIT_GLOBALRate limit exceeded
RATE_LIMIT_KEYAPI key rate limit exceeded
RES_MODEL_NOT_FOUNDModel not found
UPSTREAM_UNREACHABLEUpstream provider unreachable
UPSTREAM_ERRORUpstream provider error
UPSTREAM_TIMEOUTUpstream provider timeout
INTERNAL_ERRORInternal server error

Timeout Handling

Choose connection, request, and stream-idle timeouts for your workload and model latency. Do not assume one timeout value fits synchronous, streaming, async, and batch operations.