AI Agents
Coding Agents on TokLab
Run Claude Code on TokLab's Claude models and Codex CLI on GPT-6, billed to your TokLab balance.
Coding agents can use TokLab as their model provider. They send requests with your TokLab API key, and every request is billed by tokens to your TokLab balance instead of a subscription.
| Agent | Endpoint it uses | Models |
|---|---|---|
| Claude Code | Anthropic Messages, https://api.toklab.ai/v1/messages | Claude |
| Codex CLI | OpenAI Responses, https://api.toklab.ai/v1/responses | GPT-6 |
To let an agent call TokLab's image and video models instead, use the MCP server or see Use TokLab from AI agents.
Claude Code
Run this in the terminal you start Claude Code from:
export ANTHROPIC_BASE_URL=https://api.toklab.ai
export ANTHROPIC_API_KEY=YOUR_API_KEY
export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-5-5
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5-5
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-5-5
claude --model claude-opus-5-5- The base URL has no path. Claude Code adds
/v1/messagesitself. - The three
ANTHROPIC_DEFAULT_*_MODELvariables point Claude Code'sopus,sonnetandhaikualiases, which it also uses for background work, at TokLab model IDs. You can also pass an ID directly, for exampleclaude --model claude-fable-5-1. - The key replaces your Claude plan. In an interactive session, Claude Code asks you once to approve the key; from then on, requests are billed to your TokLab balance. Unset the variables to go back to your plan.
To keep the settings for every launch, put the same variables in the env block of ~/.claude/settings.json. That file then holds a key that spends your balance, so keep it private.
| Model ID | Use it for |
|---|---|
claude-opus-5-5 | Everyday coding |
claude-fable-5-1 | Long refactors and hard debugging |
claude-fable-5 | Setups that rely on forcing a tool call |
claude-sonnet-5-5 | The sonnet alias |
claude-haiku-5-5 | The haiku alias and background work |
Live rates per million tokens are in the model catalog.
Codex CLI
Add TokLab to your user-level ~/.codex/config.toml, keeping your other settings:
model = "gpt-6-sol"
model_provider = "toklab"
[model_providers.toklab]
name = "TokLab"
base_url = "https://api.toklab.ai/v1"
env_key = "TOKLAB_API_KEY"
wire_api = "responses"Then export your key and start Codex:
export TOKLAB_API_KEY=YOUR_API_KEY
codex- Use the user-level file. Codex ignores
model_providerandmodel_providersin a project's.codex/config.toml. - Pick the model with
model, or for one session withcodex -m gpt-6-astra. GPT-6 Astra suits the hardest tasks, GPT-6 Sol everyday coding and GPT-6 Luna fast, cheaper steps. - The tested models are GPT-6. Codex sends Responses requests; another text model needs to accept the Responses format, which its API reference lists, and has not been tested in Codex.
Check the connection
curl https://api.toklab.ai/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-haiku-5-5",
"max_tokens": 32,
"messages": [{"role": "user", "content": "Reply OK."}]
}'A working key returns a message with a short reply. For Codex, run codex exec "Reply OK." after setting up the configuration above.
Cost and limits
- Requests are billed by the tokens in each response. A coding session sends a long prompt prefix with every request: instructions, tool definitions and project files. Where the model supports prompt caching, later requests read that prefix from the cache at a lower rate.
- Every request appears in your LLM logs. Add credit on the Credits page.
- HTTP
429means too many requests at once. Run fewer parallel sessions or subagents, and wait forRetry-Afterwhen it is present.
Troubleshooting
| Symptom | Fix |
|---|---|
401 | Check the key. For Claude Code, set either ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN, not both. |
404 on every request | Claude Code needs ANTHROPIC_BASE_URL=https://api.toklab.ai; Codex needs base_url = "https://api.toklab.ai/v1". |
| Model not available | Use a model ID listed above: Claude models for Claude Code, GPT-6 for Codex. |
| Insufficient balance | Add credit on the Credits page. |
429 | Fewer parallel sessions or subagents; respect Retry-After when present. |