How to use Claude Code with a custom API endpoint

Claude Code is powerful, but you should not have to rewrite your workflow every time you change providers. If your gateway speaks the Anthropic Messages API, the setup is just a few environment variables.
1. Get an API key
Create a key with your provider and keep it in your shell environment. Never paste a live key into a project file or commit it to git.
2. Point Claude Code at the endpoint
export ANTHROPIC_API_KEY="your_api_key"
export ANTHROPIC_BASE_URL="https://api.example.com"
claudeThe important detail is the base URL: it should be the provider's API root, not a dashboard URL. The gateway should expose POST /v1/messages and return Anthropic-style streaming events.
3. Verify the three things that usually break
- Authentication: send the key as the provider expects it.
- Streaming: the endpoint must support SSE for a responsive terminal experience.
- Tools: preserve tool definitions and tool results, or coding agents will appear to “think” forever.
When a custom endpoint is worth it
A compatible gateway is useful when you need one stable endpoint across providers, clearer cost control, or a lower-cost route for development work. Keep a reliable fallback for production-critical tasks.
Related guides
- What does “Anthropic API compatible” actually mean?
- Claude Code 429 Error: What It Means and How to Fix It
Connect Claude Code in minutes
Kintio provides an Anthropic-compatible endpoint for Claude Code and other AI coding tools.
Try Kintio →