Skip to navigation

Inference Router Quickstart

List your models, send a Chat Completions or Messages request, and stream the reply.
View as MarkdownOpen in Claude

The Inference Router exposes OpenAI-compatible and Anthropic-compatible endpoints at https://api.you.com. Point an existing SDK at that base URL and authenticate with your You.com API key.

1. Get an API key

Get an API key at you.com/platform and send it as a bearer token:

Authorization: Bearer <your-api-key>

The Web Search, Contents, Answer, and Research APIs read the key from X-API-Key. The Inference Router reads it from Authorization, the header the OpenAI and Anthropic SDKs already send. The samples below read the key from YDC_API_KEY.

2. List your models

GET /v1/models returns the models your key can call. Access is set per account, so two keys can see different lists.

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

Each model reports two token limits:

FieldMeaning
max_input_tokensThe context window, in tokens.
max_tokensThe largest output a request may ask for.

A limit is published only when it holds for every request to the model. A model with no published limit omits the field in the OpenAI format, and reports null in the Anthropic format, which you get by sending an anthropic-version header. The Anthropic format also adds display_name and paging fields.

{
"object": "list",
"data": [
{ "id": "kimi-k3", "object": "model", "max_input_tokens": 262144, "max_tokens": 131072 },
{ "id": "muse-spark-1.3", "object": "model" }
]
}

3. Send a request

Use a model id from the previous step. To try a request without code, open the Playground.

import os
from openai import OpenAI
client = OpenAI(base_url="https://api.you.com/v1", api_key=os.environ["YDC_API_KEY"])
response = client.chat.completions.create(
model="kimi-k3",
messages=[{"role": "user", "content": "Explain nucleus sampling in two sentences."}],
)
print(response.choices[0].message.content)

The same model through the Anthropic-compatible endpoint:

import os
import anthropic
client = anthropic.Anthropic(base_url="https://api.you.com", auth_token=os.environ["YDC_API_KEY"])
message = client.messages.create(
model="kimi-k3",
max_tokens=1024,
messages=[{"role": "user", "content": "Explain nucleus sampling in two sentences."}],
)
print(message.content[0].text)

4. Stream the response

Set stream to true on /v1/chat/completions to receive the reply as server-sent events. Each data: line is a chat.completion.chunk, and the stream ends with data: [DONE].

Set stream_options.include_usage to true to receive the token counts on one more chunk before [DONE]. That chunk has an empty choices list, so check chunk.choices before reading delta.

stream = client.chat.completions.create(
model="kimi-k3",
messages=[{"role": "user", "content": "Explain nucleus sampling in two sentences."}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="", flush=True)
if chunk.usage:
print(f"\n{chunk.usage.total_tokens} tokens")

/v1/messages streams Anthropic server-sent events when stream is true. When a request declares a web tool, the stream also carries progress events; see Web Tools.

Next Steps