IN ENGLISH · CLI CODING AGENT

Connect Claude Code to an AI API from Iran

Claude Code, Anthropic's terminal coding agent, connects to api.anthropic.com by default. Two environment variables bring it onto 1xAi's native Anthropic route: the same Messages API, with a 1xAi key and the cost taken in Toman. No Anthropic account and no foreign card are needed.

[01]STEPS

Setting up Claude Code

  1. [01]

    Create an account and a 1xAi key. Register at 1xai.ir (the app is in Persian) and confirm your email or mobile number. You spin the sign-up gift wheel (from 100,000 to 1,000,000 Toman of gift credit) once, which is enough to test the connection. Then create a 1xai-* key in the dashboard and copy it at once: a key is shown only once.

  2. [02]

    Install Claude Code. If it is not installed yet, install Claude Code as Anthropic's documentation describes (through npm or the official installer). Installing needs no key.

  3. [03]

    Set two environment variables. In the terminal, set ANTHROPIC_BASE_URL to https://1xai.ir/anthropic and ANTHROPIC_AUTH_TOKEN to your 1xai-* key.

  4. [04]

    Run claude in the project folder. Run the claude command. Every request goes through 1xAi's native /anthropic route, and each call's cost is taken in Toman from your account and recorded in the dashboard.

  5. [05]

    Make the setting permanent. So that you need not export in every new terminal, add the same two lines to ~/.bashrc or ~/.zshrc and open a new terminal.

[02]CONFIGURATION

Ready to copy

Terminal: connecting Claude Code to 1xAibash
export ANTHROPIC_BASE_URL="https://1xai.ir/anthropic"
export ANTHROPIC_AUTH_TOKEN="1xai-XXXXXXXXXXXXXXXX"

claude

echo 'export ANTHROPIC_BASE_URL="https://1xai.ir/anthropic"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="1xai-XXXXXXXXXXXXXXXX"' >> ~/.zshrc
[03]MODEL

Recommended model

Recommended: claude-sonnet-4-6. A cheaper alternative: claude-haiku-4-5. Claude Code works with the Claude family; the recommended model is the main choice for everyday coding, and for heavier work you can switch to an Opus model. Every model and its Toman price is on the models page.

[04]TROUBLESHOOTING

Common errors

An authentication error although the key is right
Make sure both variables are defined in the same shell that runs claude (check with echo $ANTHROPIC_BASE_URL). If you had logged in with an Anthropic account before, open a new terminal so that the environment variables take effect.
401: invalid key
The key is wrong, has expired, or you revoked it. Copy it again from the dashboard or create a new one, with no space before or after it.
402: insufficient balance
The account's Toman credit is used up. A top-up starts at 100,000 Toman, by the Zarinpal gateway or the Digipay gateway or card-to-card transfer with a receipt; calls work again as soon as a payment succeeds.
Model name or routing error
1xAi routes by model name: claude-* to Anthropic, gemini-* to Google, deepseek-* to DeepSeek; grok-*, kimi-*, glm-*, qwen*, MiniMax-* and hy* reach the Grok, Kimi, GLM, Qwen, MiniMax and Hunyuan models; every other name goes to OpenAI. Write a model id exactly as the model list shows it.

Every error code is in the error reference.

FAQ · IN ENGLISH

Do I need an Anthropic account for Claude Code?

No. 1xAi's native /anthropic route offers Anthropic's own Messages API; the 1xai-* key takes the place of an Anthropic key, and each call's cost is taken in Toman from your 1xAi account.

Do features such as prompt caching work?

Yes. The /anthropic route forwards a request as it is to the official API, so native features such as cache_control and thinking are kept, and prompt caching lowers the cost of repeated tokens noticeably.

Other guides: Cursor, n8n, Cline, Open WebUI, LibreChat, Continue.

1xAi is an independent gateway. It is not affiliated with, endorsed by, or a reseller for OpenAI, Anthropic, Google, DeepSeek, xAI, Moonshot AI, Z.ai, Alibaba Qwen, MiniMax or Tencent Hunyuan. Requests are relayed upstream rather than answered by models of our own, so each provider's own usage policies apply to what their models will and will not do, and their model availability is theirs to change. Current reachability is published on the status page.