Claude Code API gateway
Claude Code API Gateway Setup with Moyi API
Configure Claude Code to use Moyi API's Anthropic-compatible gateway with a base URL, API key, model name, and concrete price anchors you can verify.
Last updated: 2026-05-31
What this setup does
Claude Code can run through an Anthropic-compatible API endpoint. Moyi API provides that endpoint so you can point Claude Code at one gateway, create one API key, and manage usage in one place.
This page is for users who already know why they want an API workflow. If you are still deciding between Claude subscriptions, direct provider APIs, and a gateway, start with the comparison notes below instead of copying commands blindly.
- Anthropic-compatible base URL: https://api.moyiapi.com
- API key source: the Moyi API dashboard API Keys page
- Best fit: high-token coding agent work, shared model spend, and users who want pay-as-you-go billing
Concrete price anchor
Claude Code is expensive when it starts reading files, rewriting patches, explaining failures, and retrying tests. A small per-token difference becomes visible once the agent is doing real project work.
The examples below use the current live pricing-table display logic, with list price and Moyi API price shown per 1M input/output tokens.
- Claude Sonnet 4.6: list $3/$15 per 1M input/output tokens, Moyi API $0.54/$2.7, about 82% lower.
- Claude Opus 4.6: list $5/$25 per 1M input/output tokens, Moyi API $0.75/$3.75, about 85% lower.
- GPT-5.5: list $5/$30 per 1M input/output tokens, Moyi API $0.5/$3, about 90% lower.
- Gemini 3.1 Pro Preview: list $2/$12 per 1M input/output tokens, Moyi API $0.38/$2.28, about 81% lower.
macOS and Linux configuration
Open a terminal in the project where you use Claude Code. Export the gateway endpoint and your Moyi API API key before starting Claude Code.
Model names can change as new models are added. Use the model names shown in the live Moyi API dashboard or documentation when you configure production workflows.
- export ANTHROPIC_BASE_URL=https://api.moyiapi.com
- export ANTHROPIC_AUTH_TOKEN=<your Moyi API API Key>
- export ANTHROPIC_MODEL=<the Claude model you want to use>
Windows PowerShell configuration
On Windows, set the same values with PowerShell environment variables. After a quick test, move the values into the shell profile or your preferred secret manager instead of pasting the API key repeatedly.
- $env:ANTHROPIC_BASE_URL="https://api.moyiapi.com"
- $env:ANTHROPIC_AUTH_TOKEN="<your Moyi API API Key>"
- $env:ANTHROPIC_MODEL="<the Claude model you want to use>"
Common setup checks
If Claude Code fails before sending a model request, check your local installation and shell environment first. If the request reaches the API but fails, check API key validity, account balance, model name, and the base URL.
Do not treat account login issues, subscription limits, network failures, and API authentication as the same problem. Splitting them early makes troubleshooting much faster.
- 401 or 403: check the API key and account balance first.
- Model not found: confirm the exact model name in Moyi API.
- Connection error: confirm the base URL is https://api.moyiapi.com.
FAQ
What API base URL should Claude Code use?
Use https://api.moyiapi.com as the Anthropic-compatible base URL, then provide your Moyi API API key through ANTHROPIC_AUTH_TOKEN.
Does this replace an Anthropic account or subscription?
No. This page describes an API gateway workflow for Claude Code. It does not bypass account rules, subscriptions, KYC, regional availability, or provider policies.
How much can the gateway change my Claude Code cost?
It depends on model choice and token volume. As a current price anchor, Claude Sonnet 4.6: list $3/$15 per 1M input/output tokens, Moyi API $0.54/$2.7, about 82% lower. Long-context coding-agent sessions are where this difference matters most.
Can I use the same Moyi API key with Codex?
Yes, Moyi API is designed for multiple coding agents. Claude Code uses the Anthropic-compatible endpoint, while OpenAI-compatible tools use the /v1 endpoint.
What should I check first when requests fail?
Check the environment variables in the current shell, then the API key, balance, model name, and base URL. These are more common than a broken Claude Code installation.