Developer docs
Quickstart
The gateway speaks the OpenAI wire protocol. Anything that accepts a base URL and a bearer key works unchanged.
Authentication
Send your key in the Authorization header. Base URL: https://api.token265.com/v1.
Authorization: Bearer sk-or-v1-...
First request
curl https://api.token265.com/v1/chat/completions \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are concise."},
{"role": "user", "content": "Explain tokenisation in one sentence."}
]
}'import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.token265.com/v1',
apiKey: process.env.OPENROUTER_KEY,
});
const res = await client.chat.completions.create({
model: 'openai/gpt-4o-mini',
messages: [{ role: 'user', content: 'hello' }],
});Streaming
Set stream: true and read server-sent events. Add stream_options: { "include_usage": true } to receive a final usage frame.
const stream = await client.chat.completions.create({
model: 'anthropic/claude-sonnet-4',
stream: true,
stream_options: { include_usage: true },
messages: [{ role: 'user', content: 'write a haiku' }],
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}Model routing
Model ids are author/model. Requests are routed to a healthy provider for that id using live price and latency; if the first provider fails, the request retries on the next one before any token is charged twice.
- Model metadata and prices: /models
- Availability is enforced per key group; a model that is not routed returns
404
Errors
| Status | Meaning | Fix |
|---|---|---|
| 401 | Key missing or revoked | Create a new key on the API keys page |
| 402 | Insufficient credits | Top up the account |
| 404 | Model not routed | Check the id on /models |
| 429 | Rate limited | Back off exponentially; raise limits on the console |
| 5xx | Provider failure after retries | Retry; the router already failed over |
Rate limits
Limits apply per key and per account, and are returned in the x-ratelimit-* headers. Raise them from the console under 系统设置 → 限流.