Quickstart: connect Claude Code, Codex, or Cursor to an AI API proxy
Before connecting Claude Code, Codex, or Cursor to an AI API proxy, confirm the tool, protocol compatibility, Base URL, API key, and model name.
Start with three checks
When you connect Claude Code, Codex, or Cursor to an API proxy, do not start with the tool UI. First confirm three things:
- Which tool you are using: Claude Code, Codex, Gemini CLI, OpenCode, and other tools use different configuration files.
- Which protocol the provider supports: Anthropic-compatible, OpenAI-compatible, or both.
- Exactly how the Base URL should be written: some providers require
/v1, while others require the URL without/v1. Follow the provider documentation.
If these three details do not line up, the CLI usually fails with a login error, 401, 404, or model not found.
If you are still choosing a provider, use the AI API Directory to compare API proxy options by model coverage, payment methods, and verification notes. For OpenAI-compatible setups, the OpenAI API Proxy Providers page is a narrower comparison, while Cheap OpenAI API Providers focuses on visible pricing and top-up value.
What to check for Claude Code
Claude Code usually depends on the Anthropic environment variables:
export ANTHROPIC_BASE_URL="https://your-proxy.example"
export ANTHROPIC_AUTH_TOKEN="your proxy API key"
claude
If the provider gives you an Anthropic-style API key, it may ask you to use:
export ANTHROPIC_API_KEY="sk-..."
claude
Note: once ANTHROPIC_API_KEY is set, Claude Code tends to use the API key billing path instead of your Claude subscription login path.
What to check for Codex
Codex is OpenAI’s local CLI. The official install flow is:
npm i -g @openai/codex
codex
On first run, Codex asks you to choose ChatGPT login or an API key. For proxy use, focus on whether the provider supports the OpenAI Responses API or a Chat Completions-compatible interface, and whether you need OPENAI_BASE_URL, OPENAI_API_KEY, or ~/.codex/config.toml.
When CC Switch is useful
If you only use one tool, exporting environment variables manually is usually enough.
If you use Claude Code, Codex, Cursor, Gemini CLI, and switch between official accounts, proxy providers, and local models, a manager such as CC Switch becomes useful. Its value is not replacing the CLI. It helps you manage providers, configs, sessions, usage, and sync.