bestokens exposes an OpenAI-compatible API. If your code already works with the OpenAI SDK, you only need to change two values: the base URL and the API key.
1. Create an API key
Sign in to the dashboard, open API Keys, and click Create key. The full key is shown exactly once — store it in your secret manager immediately.
Keys look like sk-bs- followed by 48 characters. Treat them like passwords. Never commit them to a repository.
2. Make your first request
curl https://api.bestokens.cn/v1/chat/completions \
-H "Authorization: Bearer $BESTOKENS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5-mini",
"messages": [{"role": "user", "content": "Explain edge computing in one sentence."}]
}'
3. Use the OpenAI SDK
from openai import OpenAI
client = OpenAI(
base_url="https://api.bestokens.cn/v1",
api_key="sk-bs-...",
)
resp = client.chat.completions.create(
model="claude-sonnet-4-5",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.bestokens.cn/v1',
apiKey: process.env.BESTOKENS_API_KEY,
});
const resp = await client.chat.completions.create({
model: 'deepseek-chat',
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(resp.choices[0].message.content);
4. Check your usage
Every request is metered and written to your usage log within a few seconds. The dashboard shows per-model token counts, cost, latency and cache hit rate. You can also query GET /v1/usage with the same API key.
La documentación técnica se mantiene en inglés.