Skip to main content
Corvex Token Factory exposes an Anthropic-compatible Messages API, so Claude Code connects to it as an LLM gateway. You set the endpoint, key, and model as environment variables, either in your shell or in the env block of a Claude Code settings file, and tell Claude Code the model’s real context window. Verified with Claude Code 2.1.299, October 2026.

Prerequisites

Context window and compaction

Claude Code does not read the context window of a model it doesn’t recognize from the endpoint. Unless you tell it otherwise, it assumes 200,000 tokens and compacts the conversation well before a Token Factory model’s real limit. Two variables fix that:
  • CLAUDE_CODE_MAX_CONTEXT_TOKENS sets the window Claude Code assumes for the model. Set it to the model’s context_window.
  • CLAUDE_CODE_AUTO_COMPACT_WINDOW sets the window Claude Code compacts against. /context reports usage out of this value. Claude Code compacts before usage reaches it, keeping a buffer of min(max_tokens, 20,000) + 13,000 tokens (33,000 by default), shown in /context as the autocompact buffer.
Every request reserves room for the reply: the engine enforces input + max_tokens ≤ context_window, and Claude Code sends max_tokens = 32,000 by default (CLAUDE_CODE_MAX_OUTPUT_TOKENS). A single turn with large tool results can push the context past the compaction point before compaction runs, so leave about 15% headroom: size the compaction window as (context_window − max_tokens) / 1.15, rounded down: CLAUDE_CODE_AUTO_COMPACT_WINDOW accepts plain integers from 100000 to 1000000. If you change CLAUDE_CODE_MAX_OUTPUT_TOKENS, recompute the compaction window with the formula. GET /v1/models reports each model’s current context_window and max_output_tokens.
1

Verify the key

Export the key and send a token-counting request. It checks the key and request shape without running inference.
2

Add the settings

Add an env block to your user settings file. This example selects zai-org/GLM-5.3; for another model, change every model ID and take both numbers from the table above.
settings.json
The user settings file is ~/.claude/settings.json. Keep the key out of a project’s .claude/settings.json, which is usually committed. The same variables also work as shell exports. To keep your default Claude Code setup and use Token Factory only on demand, put the block in a separate file and start Claude Code with claude --settings <file>.The ANTHROPIC_DEFAULT_*_MODEL and CLAUDE_CODE_SUBAGENT_MODEL variables route Claude Code’s background and subagent requests to the same model, so no request asks for a model Token Factory doesn’t serve.
3

Run Claude Code and check the window

Run /status to confirm the base URL and model, and /context to confirm the window. For zai-org/GLM-5.3, /context reports usage out of 314.1k tokens.

Compatibility notes

  • Prompt caching. The Messages API accepts cache_control, but Token Factory does not treat it as a request to cache content. Engine-reported cache usage is passed through; missing cache-usage fields are reported as zero. Cached input tokens are billed at the cached input rate. See Errors: Prompt caching for details.
  • Auto mode classifier. In auto mode, Claude Code asks the Anthropic API to run its safety classifier server-side and shows a notice saying the session “isn’t eligible” when the results don’t come back. Token Factory serves non-Anthropic models and does not provide those server-side checks. CLAUDE_CODE_AUTO_MODE_SERVER=0 is the opt-out Anthropic documents for this case: auto mode keeps working with the local classifier, its requests count toward token usage at the applicable model rates, and the notice does not appear. See Auto mode classifier request charges.
  • Context length. If a session still reaches the model’s limit, the gateway returns context_length_exceeded. Run /compact and retry. See Errors.
  • Model capabilities. Choose a model whose input types and features match the task. Unsupported inputs return a structured error; compare the available models on the Models page.
Last modified on October 28, 2026