Skip to content

Docs / OpenAI-compatible API

OpenAI-compatible API

POST /v1/chat/completions accepts the OpenAI request body. Fields we handle, fields we drop, limits, response headers and examples.

Get an API key

POST /v1/chat/completions takes the OpenAI Chat Completions request body and answers in the OpenAI response shape. The official OpenAI SDKs work with a new base URL and key. The OpenAI Python SDK runs against the API in our test suite on every change.

Base URL: https://api.yunshurouter.com/v1

Example

curl https://api.yunshurouter.com/v1/chat/completions \
  -H "Authorization: Bearer $YUNSHU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "messages": [
      {"role": "system", "content": "You answer in one sentence."},
      {"role": "user", "content": "What is a context window?"}
    ],
    "max_tokens": 200,
    "temperature": 0.3
  }'
from openai import OpenAI

client = OpenAI(base_url="https://api.yunshurouter.com/v1", api_key="tq-...")

completion = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[
        {"role": "system", "content": "You answer in one sentence."},
        {"role": "user", "content": "What is a context window?"},
    ],
    max_tokens=200,
    temperature=0.3,
)
print(completion.choices[0].message.content)
print(completion.usage)
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.yunshurouter.com/v1", apiKey: "tq-..." });

const completion = await client.chat.completions.create({
  model: "deepseek-v4-pro",
  messages: [
    { role: "system", content: "You answer in one sentence." },
    { role: "user", content: "What is a context window?" },
  ],
  max_tokens: 200,
  temperature: 0.3,
});
console.log(completion.choices[0].message.content);

Request fields

Field Handling
model Required. A model ID from GET /v1/models, a combo (combo/<name>), or a model with a :floor or :nitro suffix. Up to 256 characters
messages Required. At least 1, at most 4,096. A developer message is treated as system
max_completion_tokens / max_tokens Output cap, 1 to 1,000,000. max_completion_tokens wins if both are sent. Lowered to the model’s own maximum output. Default when omitted: 1,024
temperature 0 to 2
stream true for server-sent events. See Streaming
stream_options.include_usage Adds a final usage chunk to a stream
tools, tool_choice, parallel_tool_calls Up to 512 tools. See Tool calling
reasoning, reasoning_effort Turns reasoning on or off. See Reasoning
models Up to 5 fallback models. See Fallbacks and combos
response_format, top_p, stop, seed, presence_penalty, frequency_penalty and other fields Passed to the model as sent

Fields we do not pass on

These fields are removed before the request reaches the model:

Field Why
n, best_of We generate and price one completion per request. You always get one choice
provider, route Routing is ours to decide. Use :floor or :nitro instead
stream_options (other than include_usage) We control usage reporting on the stream

Limits

Limit Value
Request body 2 MiB. Larger bodies get 413 request_too_large
Messages per request 4,096
Tools per request 512
Fallback models (models) 5
Model ID length 256 characters

Prompts that are clearly longer than the model’s context window are refused with 400 context_length_exceeded before they are sent. Our token estimate errs high, so a prompt close to the limit is sent and the model decides.

Model suffixes

Append a suffix to any model ID to choose how the request is routed:

Suffix Meaning
:floor The cheapest route for this request
:nitro The fastest route for this request
{"model": "deepseek-v4-pro:floor", "messages": [{"role": "user", "content": "Hi"}]}

Any other suffix is refused with 400 invalid_request. The response and the bill name the base model (deepseek-v4-pro).

Response

The body is the OpenAI chat.completion object. model is always the model ID you called (for a fallback, the model that answered). usage has prompt_tokens, completion_tokens and total_tokens; prompt_tokens_details.cached_tokens and completion_tokens_details.reasoning_tokens appear when the model reports them.

The cost is not in the body. Use GET /v1/generation.

Response headers

Header Value
x-yunshu-request-id The request id. Use it with GET /v1/generation and when you contact support
x-yunshu-request-ref The same id (kept for older clients)
x-yunshu-model The model that answered. Differs from your model when a fallback served
x-yunshu-cache hit if the answer came from our cache (not charged), otherwise miss
raw = client.chat.completions.with_raw_response.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "Hi"}],
)
print(raw.headers.get("x-yunshu-request-id"), raw.headers.get("x-yunshu-cache"))
completion = raw.parse()
const { data, response } = await client.chat.completions
  .create({ model: "deepseek-v4-pro", messages: [{ role: "user", content: "Hi" }] })
  .withResponse();
console.log(response.headers.get("x-yunshu-request-id"), response.headers.get("x-yunshu-cache"));

Token saver header

If the key has the token saver switched on, long tool outputs are shortened before they are sent and billed. To switch it off for one request:

x-yunshu-token-saver: off

The header can only switch the saver off. Whether it is on is the key’s setting.

Errors

Errors use the OpenAI envelope: {"error": {"type", "code", "message", "request_id"}}. See Errors.