Skip to content

Docs / Authentication and API keys

Authentication and API keys

Send your Yunshu Router key as a Bearer token or in the x-api-key header. How keys are created, stored, limited and revoked.

Get an API key

Every /v1/ endpoint needs an API key. One key works for both the OpenAI and the Anthropic formats.

Sending the key

Use either header. Both are accepted on every endpoint.

Header Example Used by
Authorization Authorization: Bearer tq-... OpenAI SDKs, most tools, Claude Code’s ANTHROPIC_AUTH_TOKEN
x-api-key x-api-key: tq-... Anthropic SDKs, Claude Code’s ANTHROPIC_API_KEY

If you send both, Authorization is used. The Bearer prefix is optional: a bare key in Authorization also works.

curl https://api.yunshurouter.com/v1/models \
  -H "Authorization: Bearer $YUNSHU_API_KEY"

curl https://api.yunshurouter.com/v1/models \
  -H "x-api-key: $YUNSHU_API_KEY"

The SDKs set the header for you:

from openai import OpenAI
import anthropic

openai_client = OpenAI(base_url="https://api.yunshurouter.com/v1", api_key="tq-...")
anthropic_client = anthropic.Anthropic(base_url="https://api.yunshurouter.com", api_key="tq-...")
import OpenAI from "openai";
import Anthropic from "@anthropic-ai/sdk";

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

The anthropic-version header is accepted and has no effect. Headers such as OpenAI-Organization are ignored.

Creating a key

Administrators create keys in the console under API keys.

  • The full key is shown once, when you create it. Copy it then.
  • We store only a keyed hash of the key, so nobody at Yunshu Router can read it back.
  • The console shows the first 11 characters (for example tq-AbC1dEf2) so you can tell keys apart.

When you create a key you can set:

Setting Default Range
Name default up to 100 characters
Rate limit 120 requests per minute 1 to 100,000
Monthly budget none any amount above 0, in your balance currency
Allowed models all models up to 200 model IDs
Token saver off on or off

See Budgets and limits for how each setting is enforced.

Revoking and deleting a key

  • Revoke stops the key at once. Requests with it get 401 authentication_failed.
  • Delete stops the key, the same as revoke. The console still lists it, marked revoked. Usage made with it stays in your history and on your invoices.

Keeping keys safe

  • Keep keys in environment variables or a secret manager, not in source code.
  • Use one key per app, agent or teammate, so you can see usage per key and revoke one without stopping the others.
  • Give agents and shared tools a key with a monthly budget and an allow-list.
  • A key works from anywhere. Do not ship it in a browser page or mobile app.

When authentication fails

Status code Meaning What to do
401 authentication_failed No key was sent, or the key is wrong, revoked or deleted Check the header name and the key. Make sure no spaces or quotes were copied with it
403 account_suspended The organisation is suspended Contact support. The console stays readable

The full list is on the Errors page.