This page takes you from a new account to your first answer and its exact cost.
1. Create an account and add credit
- Sign up for an account.
- Open Billing and top up by card. Your balance is in USD, CNY or SGD, chosen when the organisation is created.
Yunshu Router is prepaid. A request is refused with 402 when the balance is empty, so add
credit before you start. There is no free trial credit.
2. Create an API key
- Open API keys and choose Create key. You need the administrator role.
- Copy the key. It starts with
tq-and is shown once. We store only a hash of it, so we cannot show it again. - Put it in an environment variable:
export YUNSHU_API_KEY="tq-..."
When you create a key you can give it a rate limit, a monthly budget and a list of allowed models. See Budgets and limits.
3. Send your first request
Pick the format your code already uses. Both reach the same models.
OpenAI format
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": "user", "content": "Say hello in three languages."}]
}'
# pip install openai
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.yunshurouter.com/v1",
api_key=os.environ["YUNSHU_API_KEY"],
)
completion = client.chat.completions.create(
model="deepseek-v4-pro",
messages=[{"role": "user", "content": "Say hello in three languages."}],
)
print(completion.choices[0].message.content)
// npm install openai
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.yunshurouter.com/v1",
apiKey: process.env.YUNSHU_API_KEY,
});
const completion = await client.chat.completions.create({
model: "deepseek-v4-pro",
messages: [{ role: "user", content: "Say hello in three languages." }],
});
console.log(completion.choices[0].message.content);
Anthropic format
The Anthropic base URL has no /v1. The SDK adds /v1/messages itself.
curl https://api.yunshurouter.com/v1/messages \
-H "x-api-key: $YUNSHU_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-pro",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Say hello in three languages."}]
}'
# pip install anthropic
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.yunshurouter.com",
api_key=os.environ["YUNSHU_API_KEY"],
)
message = client.messages.create(
model="deepseek-v4-pro",
max_tokens=1024,
messages=[{"role": "user", "content": "Say hello in three languages."}],
)
print(message.content[0].text)
// npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.yunshurouter.com",
apiKey: process.env.YUNSHU_API_KEY,
});
const message = await client.messages.create({
model: "deepseek-v4-pro",
max_tokens: 1024,
messages: [{ role: "user", content: "Say hello in three languages." }],
});
console.log(message.content[0].type === "text" ? message.content[0].text : "");
4. See what it cost
Every response carries a request id in the x-yunshu-request-id header. Look it up:
curl -i https://api.yunshurouter.com/v1/chat/completions ... # read x-yunshu-request-id
curl "https://api.yunshurouter.com/v1/generation?id=<request id>" \
-H "Authorization: Bearer $YUNSHU_API_KEY"
The answer has the token counts and the cost in your currency. The cost is not in the completion response itself. See Cost and usage.
5. Pick a model
List the models your key can use, with their context window and prices:
curl https://api.yunshurouter.com/v1/models \
-H "Authorization: Bearer $YUNSHU_API_KEY"
See Models endpoint, or browse the model list and prices.
Next steps
- Using Claude Code, Cursor, Codex or Cline? Start at the Base URL cheat sheet, then the setup guide for your coding tool.
- Stream the answer: Streaming.
- Keep a request alive when a model can’t serve it: Fallbacks and combos.
- Handle failures: Errors.