Running Claude Code via XAI Control
Posted August 31, 2025 ‐ 4 min read

Claude Code is a powerful terminal coding assistant from Anthropic. Typically, using it requires an official subscription, but its open API endpoint configuration offers a more flexible solution: Set up a dedicated proxy service through XAI Control, using your own Anthropic API Key to power it.
This guide will walk you through the entire process, allowing you to enjoy the powerful features of Claude Code while gaining the benefits of XAI Control, such as secure key management, cost control, and a unified entry point.
Prerequisites
Before you begin, make sure you have the following:
- An official Anthropic API Key: You need a valid, working Anthropic API key (usually starting with
sk-ant-
). - An XAI Control account: If you don't have one, register for free at a.xaicontrol.com.
- A Node.js and npm environment: For installing the Claude Code CLI tool.
Step 1: Add Your Anthropic Key in XAI Control
First, we need to securely add your Anthropic API Key to XAI Control's encrypted space, allowing XAI Control to act as your key proxy.
- Log in to your XAI Control account: a.xaicontrol.com.
- Navigate to the "Providers" menu, then click "Add Provider Key".
- Fill in the form with the following information:
- Name (Optional):
My-Anthropic-Key
(or any name you prefer for easy identification). - Level:
1
(or any positive integer for grouping). - Provider:
https://api.anthropic.com
(This is Anthropic's official API address). - SecretKey: Enter your own official Anthropic API Key or the token generated by Claude Code.
- Name (Optional):
- Click "Add Provider Key".
After completing this step, your Anthropic key is now managed by XAI Control, and all subsequent calls will be routed through XAI Control's unified entry point.
Step 2: Obtain Your XAI API Key
The XAI API Key is your unique credential for calling the XAI Control service. It is different from the Anthropic Key you added in the previous step.
- When you successfully register for XAI Control, you will receive an email with the subject "Welcome to XAI - Your Account is Ready!" to your registered email address. This email contains your exclusive XAI API Key. Please keep it safe.
Step 3: Install and Configure the Claude Code CLI
Now, let's install the Claude Code tool and point it to our XAI Control proxy service.
-
Globally install Claude Code: Open your terminal and run the following command:
npm install -g @anthropic-ai/claude-code
-
Configure environment variables: This is the most crucial step. We need to tell the
claude
command to use the XAI Control API address and your XAI API Key.# Point the API endpoint to XAI Control's unified entry point export ANTHROPIC_BASE_URL=https://api.xaicontrol.com # Set the authentication token to your XAI API Key, not the original Anthropic Key export ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxxxxxxxx"
Important Note
ANTHROPIC_BASE_URL
must behttps://api.xaicontrol.com
.ANTHROPIC_AUTH_TOKEN
must be your XAI API Key (from the welcome email), not your Anthropic API Key.- For convenience, it is recommended to add the
export
commands above to your shell's configuration file (e.g.,.bashrc
,.zshrc
).
Step 4: Start Using It!
Congratulations! All configurations are complete. You can now interact with Claude Code in your terminal just as you would with the official service.
Example 1: Ask a direct question
claude "write a simple HTTP file server in Go"
Example 2: Explain existing code
cat main.go | claude "explain the logic of this Go code"
Example 3: Enter interactive mode
claude
> How can I help you today?
> write a dockerfile for a node.js app
Now, all requests sent via the claude
command will be intelligently routed through api.xaicontrol.com
to the Anthropic Key you configured in XAI Control. All usage and logs can be clearly viewed in the XAI Control dashboard.
Why Choose This Method?
- Unified Management: Manage all your model keys from OpenAI, Anthropic, Gemini, and more in one place with XAI Control.
- Secure and Reliable: Your original keys are not exposed in your local environment and are stored with zero-trust encryption, eliminating the risk of leaks.
- Cost and Permission Control: Utilize XAI Control's powerful sub-account system to create separate keys for team members or different projects, with fine-grained control over their quotas, model access, and rate limits.
- High Availability: Benefit from enterprise-grade features like failover and key rotation provided by XAI Control, ensuring service stability.