Skip to content

API docs · Chat & images

Connect Codex, Claude Code and WorkBuddy

Point Codex at /v1/responses and Claude Code at /v1/messages: configuration, what we tested, limitations and troubleshooting. Also covers WorkBuddy custom models (not tested).

This page shows how to point OpenAI Codex and Anthropic Claude Code at the Global site chat API. The settings below were tested on 2026-11-13 with Codex CLI 0.168.0 and Claude Code 2.1.323 (multi-turn tool calls, streaming). Parts marked "not tested" are taken from the public OpenAI and Anthropic documentation and have not been verified by us.

This uses the custom endpoint settings both tools ship with. It is not an integration provided or endorsed by OpenAI or Anthropic.

The page also covers custom models in Tencent WorkBuddy. That section follows WorkBuddy’s configuration instructions; we have not tested it with the WorkBuddy client.

Before you start

  • On the API keys page in the console, create a key and tick chat:create. The model must be enabled for your account, and on the key's model allowlist if the key has one.
  • Use the API domain for the base URL, not the website domain. OpenAI format (Codex): https://api.aitoken.tools/v1. Anthropic format (Claude Code): https://api.aitoken.tools, without /v1.
  • Model names are the IDs in this site's model list and must match exactly.
  • Keys belong to one site; a key from the other site does not work here.
ToolEndpointBase URL
CodexPOST /v1/responseshttps://api.aitoken.tools/v1
Claude CodePOST /v1/messages
POST /v1/messages/count_tokens
https://api.aitoken.tools
WorkBuddyPOST /v1/chat/completionshttps://api.aitoken.tools/v1/chat/completions

Codex (CLI)

Codex only speaks the Responses API (wire_api = "chat" was removed in February 2026), which is POST /v1/responses here, streaming or not. Every chat model that supports the OpenAI format works: GPT, Kimi, DeepSeek, and Claude through conversion on the platform.

Edit the user-level config file ~/.codex/config.toml (Windows: %USERPROFILE%\.codex\config.toml) and add the block below. Codex reads provider settings only from the user-level file; those in a project's .codex/config.toml are ignored.

model = "claude-sonnet-4-5"
model_provider = "aitoken"

[model_providers.aitoken]
name = "aitoken"
base_url = "https://api.aitoken.tools/v1"
env_key = "AITOKEN_API_KEY"
wire_api = "responses"

Put the key in the AITOKEN_API_KEY environment variable and run codex, or codex exec "…" for non-interactive use.

export AITOKEN_API_KEY="sk-…"
codex

PowerShell:

$env:AITOKEN_API_KEY = "sk-…"
codex
  • Do not name the provider openai or azure: both names are reserved and Codex treats them specially.
  • Leave requires_openai_auth unset so no ChatGPT sign-in is needed.
  • For a model ID Codex does not know, it prints "Model metadata for <model> not found. Defaulting to fallback metadata". This is harmless.
  • If your network needs it, raise stream_idle_timeout_ms (default 300000) under [model_providers.aitoken].
  • Tested: startup, a shell tool call (exec_command) and the turn that follows it.

Desktop app and IDE extension (not tested)

According to the OpenAI documentation, the desktop app and the IDE extension read the same config.toml, so they should work, but we have not tested them. Two known caveats:

  • GUI apps usually do not inherit environment variables from your shell, so the key may have to be set as a system or user environment variable, followed by an app restart. macOS: launchctl setenv AITOKEN_API_KEY sk-…. Windows: add it under user environment variables.
  • Users have reported that setting a custom provider globally hides some ChatGPT features in the desktop app. To keep both, leave model and model_provider out of the top level of config.toml, put them in a profile file and start with codex --profile aitoken. On Codex 0.134 or later, create ~/.codex/aitoken.config.toml with these top-level keys:
model = "claude-sonnet-4-5"
model_provider = "aitoken"

The [model_providers.aitoken] block stays in config.toml.

Limitations of Codex through this site

  • Web search and MCP tools are not available: hosted tool types are dropped when the request is forwarded.
  • Reasoning is not carried across turns (reasoning items are dropped). GPT reasoning models may do somewhat worse on long multi-step tool use than when connected to OpenAI directly.
  • Image inputs work as URLs and data URLs; file_id inputs are not supported.
  • Freeform tools such as apply_patch work, but reach the model as a plain function with one string argument.
  • If a stream is cut (a single response is capped at 30 minutes), Codex retries automatically, and every retry is billed.

Claude Code (CLI)

Claude Code uses the Anthropic-format POST /v1/messages. That endpoint only serves models that support the Anthropic format, which means the Claude family (as shown in this site's model list). GPT, Kimi, DeepSeek and other models are not available through Claude Code, and Anthropic states that it does not support routing Claude Code to non-Claude models. Use Codex or the OpenAI-format endpoints for those.

On macOS or Linux, set the environment variables and start it:

export ANTHROPIC_BASE_URL="https://api.aitoken.tools"
export ANTHROPIC_AUTH_TOKEN="sk-…"
export ANTHROPIC_MODEL="claude-sonnet-4-5"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-sonnet-4-5"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-sonnet-4-5"
export CLAUDE_CODE_SUBAGENT_MODEL="claude-sonnet-4-5"
claude
VariableMeaning
ANTHROPIC_BASE_URLThe API domain, without /v1
ANTHROPIC_AUTH_TOKENYour platform key, sent as Authorization: Bearer. ANTHROPIC_API_KEY also works (sent as x-api-key), but needs a one-time approval in interactive mode
ANTHROPIC_MODELThe default model
ANTHROPIC_DEFAULT_OPUS_MODEL
ANTHROPIC_DEFAULT_SONNET_MODEL
ANTHROPIC_DEFAULT_HAIKU_MODEL
The model ID on this site for each of the opus, sonnet and haiku tiers. The haiku tier is also used for background tasks such as titles; if it points to a model your account does not have, you get "model not found" errors
CLAUDE_CODE_SUBAGENT_MODELThe model used by sub-agents
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFICOptional. Set to 1 to turn off non-essential network requests

Model IDs must match this site's model list exactly. The dated model IDs built into Claude Code may differ from the ones here, which is why the variables above map each tier to an ID on this site. The example uses one model for every tier; replace them with models enabled for your account. ANTHROPIC_SMALL_FAST_MODEL is deprecated; use ANTHROPIC_DEFAULT_HAIKU_MODEL instead.

PowerShell:

$env:ANTHROPIC_BASE_URL = "https://api.aitoken.tools"
$env:ANTHROPIC_AUTH_TOKEN = "sk-…"
$env:ANTHROPIC_MODEL = "claude-sonnet-4-5"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL = "claude-sonnet-4-5"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL = "claude-sonnet-4-5"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "claude-sonnet-4-5"
$env:CLAUDE_CODE_SUBAGENT_MODEL = "claude-sonnet-4-5"
claude

Or put them in the env block of the user-level ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.aitoken.tools",
    "ANTHROPIC_AUTH_TOKEN": "sk-…",
    "ANTHROPIC_MODEL": "claude-sonnet-4-5",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-sonnet-4-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-sonnet-4-5",
    "CLAUDE_CODE_SUBAGENT_MODEL": "claude-sonnet-4-5"
  }
}
  • Do not put the key in a project's .claude/settings.json: that file gets committed with the code. Use the user-level file or shell environment variables.
  • The VS Code extension reads these variables from claudeCode.environmentVariables in VS Code settings (per the Anthropic documentation; not tested by us).
  • To check that it took effect, type /status inside Claude Code; it shows the current base URL.
  • Tested: a Bash tool call and the following turn with claude -p, and streaming. Thinking and prompt caching fields and anthropic-beta headers are passed through unchanged, and count_tokens works.
  • If a request fails with 400 mentioning an unknown beta or field, set CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 (not needed in our test).

Claude desktop app (not tested)

The desktop app does not read ANTHROPIC_BASE_URL or settings.json. The route described in the Anthropic documentation is the third-party inference configuration, which we have not tested:

  1. Help → Troubleshooting → Enable Developer Mode. The app restarts.
  2. Developer → Configure Third-Party Inference.
  3. Choose the Gateway provider, set Gateway base URL to https://api.aitoken.tools, API key to your platform key, and the auth scheme to Bearer (or x-api-key).
  • In this mode Chat, Cowork and Code all go through this site. With a normal claude.ai sign-in the desktop app cannot be pointed at a gateway.
  • The model list only auto-discovers IDs it can recognise as Claude; models can also be listed explicitly in that configuration.
  • Menu names may differ between app versions.

WorkBuddy (not tested)

WorkBuddy is Tencent’s desktop AI assistant. Its custom models only support the OpenAI Chat Completions format, which is POST /v1/chat/completions on this site. That endpoint works with every chat model and supports streaming, tool calls and image input (depending on the model). This section follows WorkBuddy’s custom model instructions; if a field differs, follow your WorkBuddy version.

  1. At the bottom of the model dropdown, choose 「配置自定义模型」 (configure custom models), then 「添加模型」 (add model).
  2. Fill in the fields described below: the endpoint URL is https://api.aitoken.tools/v1/chat/completions, the API key is your platform key, and the model ID is an ID from this site’s model list.

You can also edit the config file directly. The user-level file is ~/.workbuddy/models.json (Windows: C:\Users\<username>\.workbuddy\models.json); older versions use ~/.codebuddy/. A project-level .codebuddy/models.json overrides the user-level file.

{
  "models": [
    {
      "id": "claude-sonnet-4-5",
      "name": "claude-sonnet-4-5",
      "vendor": "OpenAI",
      "url": "https://api.aitoken.tools/v1/chat/completions",
      "apiKey": "sk-…",
      "maxInputTokens": 128000,
      "maxOutputTokens": 8192,
      "supportsToolCall": true,
      "supportsImages": false,
      "supportsReasoning": false
    }
  ]
}
FieldMeaning
idModel ID sent to the API. It must match this site’s model list exactly and is case-sensitive
nameName shown in the dropdown
vendorVendor identifier. Use "OpenAI"
urlFull endpoint URL, which must end with /v1/chat/completions. Use the API domain, not the website domain. A URL that stops at the domain or at /v1 is rejected as invalid
apiKeyYour platform key
maxInputTokens
maxOutputTokens
Input and output token limits. Set them for the model you use
supportsToolCall
supportsImages
supportsReasoning
Capability flags: tool calls, image input, reasoning. Do not declare more than the model can do. WorkBuddy relies on tool calls to carry out tasks
  • The token limits and capability flags in the example are sample values. Change them for the model you use.
  • Do not put the key in a project-level .codebuddy/models.json, which may be committed with your code. Use the user-level file.
  • Each request first reserves quota for the estimated input plus the output limit, then settles on actual usage and returns the rest. The output limit is the request’s max_tokens, or the model’s maximum output when it is not sent. When your balance or the key’s total / daily limit cannot cover that reserve, the platform reserves what you can afford and lowers the output limit of that request to match: a reply may stop partway, and topping up or raising the key limit restores it. Some models are not lowered and return 402 directly when the quota falls short; see chat billing in the API docs for which ones. WorkBuddy sends a long system prompt and tool definitions with every request, so the reserved amount is larger than for ordinary chat. Keep headroom in both your balance and the key’s total limit.
SymptomCause and fix
The URL is reported as invalidurl does not go all the way to /chat/completions, or /v1 appears twice
401The key was copied incompletely or contains a space
404 model not foundid does not match this site’s model list (case-sensitive)
Ordinary chat works but tasks failThe model does not support tool calls, or supportsToolCall is false
WorkBuddy shows a custom model error (「自定义模型出现错误」) with "402 This API key does not have enough total limit left: this request needs a hold of …, but the key has … remaining" (error code key_limit_exceeded)The connection works. What is left of this key’s total limit cannot cover even the minimum output (1,024 tokens); the error message states the amount to reserve and the amount left. Raise the key’s total limit in the console or use another key
402 quota_exceeded (account balance too low)The balance cannot cover even the minimum output; the error message states the amount to reserve and the amount available. Top up and retry
Replies often stop partway, with no errorYour balance or this key’s total / daily limit cannot cover the reserve for the full output limit, so the output limit of that request was lowered (response header X-AiToken-Output-Capped). Top up or raise the key limit

Limits and billing

  • The account RPM is shared by all keys of the account. There is no platform-wide default cap; a limit applies only when one is set on the account or the key.
  • There is no platform-wide cap on in-flight chat and image requests; when a concurrency limit is set on the account or the key, requests beyond it return 429.
  • A single streamed response is cut after 30 minutes in total, or after 120 seconds with no data. Non-streamed responses must finish within 10 minutes.
  • The request body can be at most 32 MiB. Requests over 8 MiB are handled one at a time per account (and only a few at a time across the platform); when you already have one in progress, or that capacity is in use, you get 429 — retry after Retry-After once the earlier request has finished, or keep the body under 8 MiB.
  • Quota is reserved before the request starts, from the output limit and the request size (the model’s maximum output when no output limit is sent), and the unused part is released after settlement, so keep some headroom in your balance. When the balance or key limit cannot cover that reserve, the output limit of the request is lowered to what you can afford, so a reply may be cut short; topping up or raising the key limit restores it (some models called through /v1/chat/completions are not lowered and return 402 directly; see chat billing in the API docs). A 402 is returned only when even the minimum output (1,024 tokens) cannot be reserved; the error message states the amount to reserve and the amount available.
  • Billing is the same as for the equivalent chat request, and requests appear under Call logs in the console.
  • POST /v1/messages/count_tokens is free but counts toward RPM. For models whose upstream has no token counting it returns an estimate.

See also: Chat billing · Rate limits

Troubleshooting

SymptomCause and fix
401Wrong key, or a key from the other site (keys are per site)
403The key lacks chat:create, or the model is not enabled for the account or not on the key's model allowlist
404 model not foundThe model ID must match this site's model list. For Claude Code, set the model mapping variables above
402Not enough balance or key limit to reserve even the minimum output; the error message states the amount to reserve and the amount available
429Over the RPM or in-flight limit. Wait for Retry-After, then retry
400 on /v1/messages for a non-Claude modelThe model does not support the Anthropic format. Use Codex or the OpenAI-format endpoints for it
Codex says "wire_api = chat is no longer supported"Set wire_api to "responses"
model = "claude-sonnet-4-5"
model_provider = "aitoken"

[model_providers.aitoken]
name = "aitoken"
base_url = "https://api.aitoken.tools/v1"
env_key = "AITOKEN_API_KEY"
wire_api = "responses"