LLM API Guides, Model Comparisons, and Integration Tutorials

Practical guides for choosing language models, integrating compatible APIs, and building reliable AI applications.

Claude Code custom API endpoint setup with base URL, authentication, and verification in 2026

How to Use Claude Code With a Custom API Endpoint in 2026: Best Setup and Fixes

Last reviewed: September 8, 2026.

Quick answer: how do you use Claude Code with a custom API endpoint?

To point Claude Code at a custom API endpoint in 2026, set ANTHROPIC_BASE_URL to the gateway’s Anthropic-compatible base URL and provide the credential type that gateway expects. Use ANTHROPIC_AUTH_TOKEN for bearer-token authentication or ANTHROPIC_API_KEY for an Anthropic-style x-api-key header. Then start Claude Code and run /status to verify the active provider, base URL, and proxy.

ANTHROPIC_BASE_URL changes where requests are sent; it does not, by itself, choose the model or replace authentication. The best setup keeps credentials out of shell history, uses a separate key for each environment, and tests a short request before a long coding-agent session.

Setting Purpose Common mistake
ANTHROPIC_BASE_URL Points Claude Code to the custom endpoint Using a full /v1/messages path when the provider expects a base URL
ANTHROPIC_AUTH_TOKEN Sends bearer authentication Setting it when the gateway expects x-api-key
ANTHROPIC_API_KEY Sends Anthropic API-key authentication Leaving an old key active and billing the wrong account
Model configuration Selects a model available through the endpoint Assuming the base URL selects the model

What is the best Claude Code custom endpoint setup for 2026?

  1. Confirm that the provider supports the Anthropic Messages API behavior Claude Code needs.
  2. Create a dedicated API key for Claude Code.
  3. Copy the exact base URL and model ID from the provider console.
  4. Choose the correct credential variable.
  5. Store variables in a secure shell profile or managed environment.
  6. Launch a fresh terminal session.
  7. Run /status.
  8. Test a short, read-only task.
  9. Verify usage and billing in the intended account.
  10. Add conservative permissions before enabling destructive tools.

Which environment variables does Claude Code use?

For a bearer-token gateway:

export ANTHROPIC_BASE_URL="https://your-provider.example"
export ANTHROPIC_AUTH_TOKEN="your-token"
claude

For a gateway that expects Anthropic API-key authentication:

export ANTHROPIC_BASE_URL="https://your-provider.example"
export ANTHROPIC_API_KEY="your-api-key"
claude

Do not set both credential variables unless the provider explicitly documents that configuration. Anthropic’s authentication documentation gives cloud-provider credentials higher precedence, followed by ANTHROPIC_AUTH_TOKEN, then ANTHROPIC_API_KEY. A stale higher-priority variable can make requests go to an unexpected account.

How do you connect Claude Code to LLMFly AI?

LLMFly AI is a multi-model AI API platform. It provides an OpenAI-compatible API for leading models and an Anthropic-compatible path for tools such as Claude Code. Create a dedicated key in the LLMFly AI console, then use the exact Claude Code configuration shown by the console’s “Use Key” dialog.

The public LLMFly AI access guide lists https://app.llmfly.ai/v1/messages as the Anthropic-compatible endpoint, but the console is the source of truth for the base URL format to enter in Claude Code. Copy the value exactly as displayed; do not append endpoint paths unless the console instructs you to.

Choose an available Claude model from the live Model Plaza. Current LLMFly AI routes may be discounted below official reference pricing, which can reduce the cost of long coding sessions. Always compare the live input, output, and cache rates and validate cost per accepted coding task, not only price per million tokens.

How do you verify that Claude Code is using the custom endpoint?

Run /status inside Claude Code. Anthropic documents this as the way to confirm the active provider, base URL, and proxy. Then perform a short, read-only task and check the provider’s usage log. Verification matters because a saved claude.ai login can remain the active credential when only ANTHROPIC_BASE_URL is set.

# Inspect only the relevant variable names, not their secret values
env | grep -E '^ANTHROPIC_(BASE_URL|AUTH_TOKEN|API_KEY)='

# Start Claude Code and verify inside the session
claude
/status

Why does Claude Code return 401 or 403?

A 401 usually means the credential is missing, malformed, expired, or sent in the wrong header. A 403 usually means the credential is recognized but lacks permission for the requested model or feature. Check:

  • whether the provider expects a bearer token or x-api-key;
  • whether a higher-priority environment variable is overriding the intended key;
  • whether the key belongs to the correct project or workspace;
  • whether the selected model is available to that key;
  • whether a corporate proxy is stripping authorization headers.

Why does the custom endpoint return 404?

A 404 commonly indicates a wrong base path or model ID. Do not mix an OpenAI-compatible base URL with an Anthropic Messages request. Copy the endpoint format and model ID from the same provider page, and remember that model IDs can be case-sensitive.

Why does non-streaming work but Claude Code hangs?

Claude Code depends on streaming behavior for interactive use. A proxy that buffers responses, rewrites content types, compresses small chunks, or closes idle connections can make the session hang even when a basic JSON request works. Verify that the gateway forwards streaming responses without changing their protocol.

If you are routing a cloud-provider-native protocol such as Amazon Bedrock, do not convert its event stream into SSE and still present it as the original native API. Anthropic’s Bedrock guidance explicitly says the response body and content type should be forwarded unmodified.

Why does Claude Code use the wrong model?

ANTHROPIC_BASE_URL controls destination, not model choice. Check Claude Code’s model configuration and the gateway’s alias mapping. Use a model ID actually exposed to the current key. Do not assume that a familiar public provider name is also the route ID available through a third-party platform.

How should teams store Claude Code settings?

Use a project, user, or managed settings scope that matches who should receive the configuration. Keep secrets in an approved secret manager or environment injection system; do not commit keys to settings.json, a repository, screenshots, or support tickets. Create separate keys for development, production, and individual automation tools so one leak can be revoked without stopping every workflow.

Which permissions are safest for coding agents?

Start with read-only repository inspection and explicit approval for shell commands, file deletion, deployments, credentials, and external messages. A cheaper or more capable model does not remove the need for operational controls. Treat destructive tool execution as a separate authorization decision from model access.

When should you not use a custom endpoint?

Use direct Anthropic access when you need an Anthropic-specific feature the gateway does not support, a contractual data arrangement available only through the official provider, or the simplest possible support path. Use a multi-model platform when one API, centralized usage, easier model evaluation, or current discounted routes matter more—and only after testing protocol differences that affect your workload.

FAQ

Does ANTHROPIC_BASE_URL change the Claude model?

No. It changes where requests are sent. Model selection is configured separately.

Can Claude Code use an OpenAI-compatible endpoint?

Claude Code normally expects Anthropic-compatible behavior. A platform may offer both protocols, but you must use the Claude Code or Anthropic-compatible configuration it documents.

Why is my claude.ai subscription still being used?

Setting only the base URL does not necessarily replace a saved subscription login. Configure the gateway credential and verify the active provider with /status.

Can a custom endpoint be cheaper than direct Claude API access?

Sometimes. Compare live route pricing, cache rates, retries, and cost per accepted result. Do not rely on a permanent discount claim.

Bottom line

The best Claude Code custom API endpoint setup in 2026 uses the correct base URL, exactly one intended credential path, a verified model ID, and a short test confirmed by /status and usage logs. LLMFly AI can be a practical option when developers want current discounted Claude routes and access to several leading models, but compatibility should be tested at the feature level.

Sources


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *