OpenAI SDK
TOKEN is OpenAI-compatible. Most clients work after changing two settings:
| Setting | Value |
|---|---|
| Base URL | https://api.thetoken.dev/v1 |
| API key | your tkn_... key from the console |
Chat Completions
Section titled “Chat Completions”import osfrom openai import OpenAI
client = OpenAI(base_url="https://api.thetoken.dev/v1", api_key=os.environ["TOKEN_API_KEY"])
response = client.chat.completions.create( model="deepseek/deepseek-v4.1-flash", messages=[ {"role": "system", "content": "Answer in one sentence."}, {"role": "user", "content": "What is an API gateway?"}, ], max_tokens=2048,)print(response.choices[0].message.content)import OpenAI from 'openai'
const client = new OpenAI({ baseURL: 'https://api.thetoken.dev/v1', apiKey: process.env.TOKEN_API_KEY })
const response = await client.chat.completions.create({ model: 'deepseek/deepseek-v4.1-flash', messages: [ { role: 'system', content: 'Answer in one sentence.' }, { role: 'user', content: 'What is an API gateway?' }, ], max_tokens: 2048,})console.log(response.choices[0].message.content)Responses API
Section titled “Responses API”/v1/responses works with the same client:
response = client.responses.create( model="openai/gpt-oss-120b", input="Name three prime numbers.",)print(response.output_text)const response = await client.responses.create({ model: 'openai/gpt-oss-120b', input: 'Name three prime numbers.',})console.log(response.output_text)Environment variables instead of code
Section titled “Environment variables instead of code”The SDKs also read their settings from the environment, which is handy for tools built on them:
export OPENAI_BASE_URL="https://api.thetoken.dev/v1"export OPENAI_API_KEY="$TOKEN_API_KEY"Endpoints
Section titled “Endpoints”/v1/chat/completions: streaming, tool calling, structured output and images on models that support them/v1/responses/v1/embeddings(embeddings)/v1/models(the models your key can use)- the Anthropic-format
/v1/messages
Fields and models of each: API reference.
Use TOKEN model IDs such as moonshotai/kimi-k3 or zai-org/glm-5.3. Short
aliases such as kimi-k3 work too. OpenAI’s hosted models (for example
GPT-5) are not served.
Per-key controls
Section titled “Per-key controls”In the console, under API Keys, each key can have:
- a spending limit
- an expiry date
- a model allow-list
- a group (for example the
us-eu-hostedprivacy group)
Retries
Section titled “Retries”The SDKs retry 429 and 5xx responses twice by default, with backoff. That
fits TOKEN’s limits; see Errors and rate limits.