AI Agents

Coding Agents on TokLab

View Markdown

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.

AgentEndpoint it usesModels
Claude CodeAnthropic Messages, https://api.toklab.ai/v1/messagesClaude
Codex CLIOpenAI Responses, https://api.toklab.ai/v1/responsesGPT-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/messages itself.
  • The three ANTHROPIC_DEFAULT_*_MODEL variables point Claude Code's opus, sonnet and haiku aliases, which it also uses for background work, at TokLab model IDs. You can also pass an ID directly, for example claude --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 IDUse it for
claude-opus-5-5Everyday coding
claude-fable-5-1Long refactors and hard debugging
claude-fable-5Setups that rely on forcing a tool call
claude-sonnet-5-5The sonnet alias
claude-haiku-5-5The 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_provider and model_providers in a project's .codex/config.toml.
  • Pick the model with model, or for one session with codex -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 429 means too many requests at once. Run fewer parallel sessions or subagents, and wait for Retry-After when it is present.

Troubleshooting

SymptomFix
401Check the key. For Claude Code, set either ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN, not both.
404 on every requestClaude Code needs ANTHROPIC_BASE_URL=https://api.toklab.ai; Codex needs base_url = "https://api.toklab.ai/v1".
Model not availableUse a model ID listed above: Claude models for Claude Code, GPT-6 for Codex.
Insufficient balanceAdd credit on the Credits page.
429Fewer parallel sessions or subagents; respect Retry-After when present.