Claude Code
Claude Code (opens in a new tab) is Anthropic's CLI coding agent. Connect it to Xilos by overriding the API base URL and key so every coding task routes through the Xilos gateway for governance, caching, and cost control.
Prerequisites
- A Xilos account with an active organization.
- An API key from Settings in the Xilos dashboard, or a Virtual Key with scoped limits.
- Claude Code installed (see the Claude Code docs (opens in a new tab) for installation).
- The base URL:
https://api.xilos.ai/api/v1.
Configuration
Claude Code respects the standard ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY environment variables. Because Xilos is OpenAI-compatible, use the OpenAI-compatible override to route traffic through Xilos.
Set environment variables
export OPENAI_API_KEY="your-xilos-api-key"
export OPENAI_BASE_URL="https://api.xilos.ai/api/v1"Add these lines to your shell profile (~/.bashrc or ~/.zshrc) so they persist across sessions.
Info: If your version of Claude Code requires the Anthropic-specific variables instead, you can set those to the same Xilos values:
export ANTHROPIC_API_KEY="your-xilos-api-key" export ANTHROPIC_BASE_URL="https://api.xilos.ai/api/v1"
Launch Claude Code with the OpenAI provider
claude-code --provider openai --model xilosThe --model xilos flag tells Xilos to apply your routing rules. To target a specific model, pass a concrete model name (for example, claude-sonnet-4).
Verify in the dashboard
Check the Query Log in your Xilos dashboard to confirm Claude Code traffic is flowing through Xilos.
Warning: If your version of Claude Code does not support the
--provider openaiflag, check the latest Claude Code documentation for the current override mechanism. The principle remains the same: point the base URL athttps://api.xilos.ai/api/v1and use your Xilos API key.
Verify the Connection
Send a test prompt from Claude Code and confirm it appears in the Xilos dashboard:
- Run any Claude Code command that triggers an LLM call (for example,
claude-code "Explain this function"). - Open your Xilos dashboard.
- Navigate to Query Log.
- Confirm the query appears with the routing decision, governance actions, and cost breakdown.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
--provider openai not recognized | Your version of Claude Code uses a different flag. | Check the Claude Code release notes. Set ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY instead, or use the OpenAI-compatible override supported by your version. |
| 401 Unauthorized | The API key is invalid or expired. | Regenerate the key in the Xilos dashboard under Settings and update the environment variable. |
| Requests reach Anthropic directly | ANTHROPIC_BASE_URL is not set or is overridden by a config file. | Ensure the environment variable is exported in the shell where you launch Claude Code. |
| 403 Forbidden | A Xilos restriction rule blocked the query. | Check the Query Log for the triggered rule and adjust the rule or the query content. |
| Tool calls fail or time out | The model name does not match a model Xilos recognizes. | Use xilos for smart routing, or verify the model identifier in the Xilos dashboard under Models. |
Next Steps
- Create a Routing Rule — Direct specific query types to the best model.
- Create a Restriction Rule — Block, mask, or flag sensitive content.
- Enable Context Compression — Reduce token costs by 50–90%.
- Manage Virtual Keys — Scope API keys with budget and rate limits.