Skip to main content
AI models & keys (Settings > AI models & keys) lets your own coding tools and scripts use your company’s models, as you, within your budgets. The key covers model calls only. File edits, shell commands and local skills stay on your computer and are not recorded.

Connect a coding tool

1

Pick your client

Under Connect a client, pick Claude Code, Codex CLI, OpenCode or Your own code.
2

Copy and run the setup

  • Claude Code, Codex CLI or OpenCode: pick macOS, Linux or Windows, select Copy (it creates a key for that client and computer), and run it in your terminal (PowerShell on Windows). The coding tool stays connected in every new terminal.
  • Your own code: select Copy and paste it into your project’s coding agent. It wires your OpenAI or Anthropic SDK calls to the gateway, reading the key from XPANDER_GATEWAY_KEY. The prompt never contains your key.
Connect a client with Claude Code, Codex CLI, OpenCode and Your own code, Claude Code selected, and Linux picked in the line Copy creates your API key automatically

Connect a client, with Claude Code and Linux picked. The setup command and Copy are below it.

Set up manually shows the same settings as files, with your address and a new key filled in. For Claude Code, that is the env block of ~/.claude/settings.json that What does the Claude Code command change? below shows, with no model: you pick the model in Claude Code. For Codex CLI, OpenCode and Your own code, it also has a Model field.
The command starts Claude Code with these variables, then asks it to save the same values in the env block of ~/.claude/settings.json (%USERPROFILE%\.claude\settings.json on Windows). Your other settings in that file stay as they are.To use a model from another vendor, start Claude Code with claude --model <model ID>, or type /model <model ID> in a session. Claude, GPT and Gemini IDs work as Available models shows them. For a model from any other provider, put the provider’s ID and :: in front: z_ai::glm-4.7, nebius::moonshotai/Kimi-K3, cerebras::gpt-oss-120b, open_router::google/gemini-4-argon or amazon_bedrock::minimax.minimax-m2.5. Without the prefix, the gateway reads the ID as an Anthropic model, and the call fails.When Claude Code is done, the env block has these three entries. The command adds no model:
On a self-hosted install, the address is your own gateway’s address.The file holds your key in plain text. Anyone who can read the file can use the key. If the file leaks, choose Revoke under Gateway keys.With your own Claude plan, the command sets ANTHROPIC_BASE_URL and ANTHROPIC_CUSTOM_HEADERS (x-xpander-api-key: <your key>) instead. It clears ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY for this launch and removes them from the env block, because either one replaces your plan sign-in. If your shell profile sets either one, delete that line too.
No. Since v2.1.323, Claude Code assumes a 1M-token window for a model ID it does not recognize, such as a Gemini model or your own provider’s model, and shows a warning that names the assumed size. On an earlier version it assumes 200K. Run claude update.If the model’s window is smaller, set CLAUDE_CODE_MAX_CONTEXT_TOKENS only when you start the model with the smaller window, and keep it out of settings.json:
This example starts Z.ai’s GLM-4.7, which has a 200K window. In PowerShell, run $env:CLAUDE_CODE_MAX_CONTEXT_TOKENS='200000'; claude --model z_ai::glm-4.7; Remove-Item Env:CLAUDE_CODE_MAX_CONTEXT_TOKENS.If you put it in the env block instead, it applies to every model ID Claude Code does not recognize, and models with a larger window compact early. See Correct the window for a gateway or custom model ID. To check that your model passed the test on Claude Code, see Models from other vendors on each harness.

Create a key yourself

Under Gateway keys, choose Create key, give it a name such as My desktop, and pick when it expires (7 days to Never). Copy it: it is Shown only once. Use one key per computer and coding tool. Revoke stops a key at once.

Available models

Available models lists what you may call. Copy a model ID and use it as model in your coding tool. Shortcuts your admin set up work the same way. A missing model is turned off for you: ask an admin. If you use your own Claude plan here, set When my Claude plan hits its limit to Continue on company models or Pause, unless your admin set calls to pause. Your spend is in Usage (Settings > Usage).

Next steps

AI Gateway

What your admins control.

Gateway errors

What a refused call means.