Claude Code Custom API Endpoint: Third-Party Gateway Setup with Chinese Open-Source Models
Claude Code Custom API Endpoint: Third-Party Gateway Setup with Chinese Open-Source Models
Claude Code can be configured to communicate with an Anthropic-compatible endpoint instead of using a provider endpoint directly. This makes it possible to test a gateway-managed workflow with model IDs exposed by the gateway, including Chinese open-source models available in ECAIX's current model catalog.
This guide is about a provider-specific, third-party compatibility workflow. Anthropic's official Claude Code gateway documentation explains that Anthropic does not support routing Claude Code to non-Claude models through a gateway. ECAIX does not claim that this workflow is officially supported by Anthropic, and a non-Claude model may not provide every Claude Code capability.
Read this before configuring
Use this guide to understand endpoint configuration and compatibility testing. Anthropic's official documentation does not support routing Claude Code to non-Claude models through a gateway. ECAIX has not published a claim that every Claude Code feature works with every non-Claude model. Check the terms and documentation of your Claude Code version, gateway, and model provider before using the workflow for production data.
Quick start
If you already understand the compatibility boundary, use this short path first:
- Open the current ECAIX model catalog and choose an active model ID.
- Create an ECAIX API key and keep it outside source control.
- Set
ANTHROPIC_BASE_URLtohttps://ecaix.com/api/ai/v1/anthropic. - Send the diagnostic request below and record the HTTP status.
- Run Claude Code in a read-only test project with
claude -p. - Test tools, streaming, context limits, and permissions separately.
Validation status at publication
| Area | Status | Evidence boundary |
|---|---|---|
| Public model IDs | Measured | Checked against the public ECAIX catalog on 2026-10-23 |
| Endpoint path | Measured | Matches the published ECAIX Anthropic-compatible docs |
| Direct API request with a live key | Not verified in this article | Run the diagnostic command with your own authorized key |
| Claude Code end-to-end session | Not verified in this article | Must be tested against your installed Claude Code version |
| Tool calls, streaming, long context | Not verified | Test independently; text compatibility is not feature compatibility |
This table is intentional: a configuration example is not the same as a measured compatibility result.
What this setup changes
The setup has four separate parts:
- Claude Code is the client that creates coding tasks and sends requests.
- The Anthropic-compatible gateway receives requests at an Anthropic-style endpoint.
- The model ID selects the upstream model exposed by the gateway.
- The API key authenticates the request and determines the account, quota, and permissions.
Changing the endpoint does not turn a non-Claude model into Claude. It only changes which compatible API surface receives the request. Tool use, context handling, model aliases, streaming behavior, and permission flows can vary by client version and gateway implementation.
Before you start
You need:
- A Claude Code installation that supports environment or settings-based endpoint configuration.
- An ECAIX API key.
- A model ID that currently exists in the ECAIX model catalog.
- A terminal where you can run a small test request without placing the API key in source control.
The catalog changes over time. Before copying a model ID into a configuration file, open the ECAIX models directory and confirm that the model is active and available for the API style you plan to use.
Configure the gateway endpoint
Claude Code stores settings in ~/.claude/settings.json on many installations. The exact settings schema can change, so treat the following as a starting pattern and compare it with the documentation for your installed version.
{
"env": {
"ANTHROPIC_BASE_URL": "https://ecaix.com/api/ai/v1/anthropic",
"ANTHROPIC_API_KEY": "YOUR_ECAIX_API_KEY",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
"CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT": "1"
},
"model": "deepseek-v4.1-flash"
}
Do not commit this file to a public repository if it contains a real API key. Prefer a local environment variable, a secrets manager, or the credential mechanism recommended by your Claude Code installation.
You can also configure the endpoint in a shell session while testing:
export ANTHROPIC_BASE_URL="https://ecaix.com/api/ai/v1/anthropic"
export ANTHROPIC_API_KEY="YOUR_ECAIX_API_KEY"
export ANTHROPIC_MODEL="deepseek-v4.1-flash"
The variable names and settings supported by a particular Claude Code release can change. If the client ignores ANTHROPIC_MODEL, use the model field or model alias mechanism documented by your version. The gateway still needs to recognize the final model ID.
Verify the Anthropic-compatible endpoint first
Before starting an interactive coding session, send one small request. This separates endpoint, authentication, and model-ID problems from Claude Code-specific behavior.
The command below saves response headers and the response body separately, then prints the HTTP status. Use a real authorized key only in your local shell; never paste it into an article, issue, or shared log.
curl -sS -D /tmp/ecaix-anthropic-headers.txt \
-o /tmp/ecaix-anthropic-response.json \
-w '\nHTTP %{http_code}\n' \
"${ANTHROPIC_BASE_URL}/messages" \
-H "x-api-key: ${ANTHROPIC_API_KEY}" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "deepseek-v4.1-flash",
"max_tokens": 128,
"messages": [
{"role": "user", "content": "Reply with one short sentence."}
]
}'
Expected interpretation:
200: inspect the response shape and confirm the returned model or usage fields.401or403: check the key, header, account, and permission scope before changing the prompt.404: check the base URL,/messagessuffix, and endpoint deployment.400: reduce the request to the smallest valid body and check model-specific fields.5xxor timeout: record the request time and response body, then separate gateway, upstream, and client timeout behavior.
A successful response confirms that the key, endpoint, request format, and model ID worked together for that request. It does not prove that every Claude Code feature will work.
Choosing a model ID
The ECAIX catalog contains model families from Chinese providers. The right starting model depends on the task, not only on the model name.
Coding and general development
Start with a current DeepSeek, Qwen, GLM, or Seed coding-capable model that is visible in the catalog. For example, a catalog may expose IDs such as deepseek-v4.1-flash, qwen3.8-flash, glm-5.3, or seed-2.0-code. Availability and capabilities can change, so always verify the current model page before publishing a configuration.
Long context and repository work
For large repositories or long technical documents, compare the context length shown in the model directory. A larger context window does not automatically mean better repository results: prompt structure, tool support, output limits, and the gateway's request limits also matter.
Tool calling and agent workflows
If the workflow needs function calling or tools, check the model and endpoint documentation. Some providers expose tool calling through OpenAI-compatible APIs, while others expose different field names or support only a subset of tool behavior. Start with a small tool-call test before giving the model access to a real repository or external system.
Chinese-language development work
Chinese open-source models can be useful when the codebase, documentation, issue tracker, or team workflow contains Chinese-language material. Evaluate the model with your own prompts and repository samples instead of relying only on general rankings.
Test Claude Code after the API request works
Once the direct request succeeds, start with a read-only or low-risk command:
claude -p "Explain what this repository does without editing files."
Then test one narrowly scoped task. For example:
claude -p "List the likely entry points for the web application. Do not modify files."
Use progressively more demanding tests:
- Plain text response.
- Short code explanation.
- Repository navigation.
- A controlled edit in a disposable branch.
- Tool use or multi-step task.
- Streaming and long-context behavior.
Do not assume that a successful text response proves that permission prompts, tool calls, streaming, context limits, or file editing behave identically to a Claude-backed session.
Choose the right API path
Claude Code is only one client workflow. The right API path depends on the client and feature set you need:
| Option | Best fit | What to compare |
|---|---|---|
| Official Claude API | Native Claude support and official documentation | Provider terms, native features, and billing |
| Third-party Anthropic-compatible gateway | A gateway-managed workflow using Anthropic-style requests | Protocol coverage, routing, limits, logging, and non-Claude restrictions |
| Model provider's native API | Provider-specific model capabilities | Native fields, tools, context limits, and provider SDK |
| OpenAI-compatible gateway | Existing OpenAI SDKs and tools | Base URL changes, field conversion, Responses support, and tool semantics |
For ECAIX, use the Anthropic Messages documentation for the Anthropic-style path and the Chat Completions documentation for OpenAI-compatible clients. Use the models directory to confirm the current model and the pricing page for current displayed pricing.
Compatibility matrix
The following matrix is a publication-time evidence boundary, not a claim that every feature is supported:
| Test area | Evidence in this article | Required next test |
|---|---|---|
| API key authentication | Request format and diagnostic command | Run with an authorized key and record status |
| Model routing | Current public catalog IDs | Confirm the response model or usage fields |
| Plain text generation | Minimal request shape | Record a real response |
| Streaming | Not verified here | Test event format and client parsing |
| Tool calls | Not verified here | Test one harmless function schema |
| Multi-step agent task | Not verified here | Use a disposable repository |
| Long context | Not verified here | Measure the largest successful prompt |
| Permission behavior | Not verified here | Test with read-only and controlled edit tasks |
This distinction prevents a successful minimal request from being presented as a complete Claude Code compatibility certification.
Model detail pages and current IDs
Use the model detail pages instead of copying an old model name from a blog post:
These links are entry points for checking the current model ID, context information, and page-level details. Availability can change after publication.
After an error, use this order instead of changing several variables at once:
- Save the HTTP status and response body.
- Confirm the base URL and endpoint suffix.
- Confirm the API key is present locally and has the expected scope.
- Confirm the exact model ID in the live model catalog.
- Retry with the smallest valid request.
- Compare the result with the client request sent by Claude Code.
- Only then investigate upstream routing, timeout, or tool schema differences.
For Model not found, this separates a spelling error from a permission problem, a gateway mapping problem, and an upstream provider failure. For 401 and 403, changing the model is usually not the first fix. For a text-success/tool-failure case, the next test should be the tool schema rather than another plain-text prompt.
Common errors
| Symptom | Likely cause | What to check |
|---|---|---|
401 or 403 | Missing, invalid, or unauthorized API key | Key value, account permissions, and endpoint headers |
| Model not found | The model ID is not in the current catalog or is not available to the key | /models, spelling, and model access |
| Unsupported parameter | The gateway or upstream model supports only part of the Anthropic request format | Remove optional fields and test a minimal request |
| Empty or malformed tool call | Tool schema or provider mapping differs | Test a single simple function before a full agent workflow |
| Timeout | Context, output, upstream load, or client timeout is too large | Reduce prompt size, output limit, or task scope |
| Client ignores the model setting | The installed Claude Code version uses a different configuration path | Check the version-specific settings documentation |
| Text works but agent task fails | Text compatibility is not the same as tool compatibility | Test tools, permissions, streaming, and context independently |
Security and data handling
Treat the gateway as a separate service boundary. Before sending source code or customer data, review:
- Which service receives prompts and file contents.
- Whether requests and responses are logged.
- How API keys are stored and rotated.
- Whether the model route is a real upstream connection or another provider's fallback route.
- Which tools the client can invoke.
- How to revoke the key after a test.
Never paste a production API key into a public issue, article, screenshot, or shell history that is shared with others.
How this differs from official Claude Code support
The official Anthropic documentation is the authority for Claude Code support. A third-party gateway may expose a compatible request format, but compatibility is not the same as official support. The safe way to describe this workflow is:
- Supported by this gateway configuration: the endpoint, authentication headers, model IDs, and features that ECAIX has tested.
- Not automatically supported: all Claude Code features, non-Claude model behavior, provider-specific tool semantics, and future client versions.
- Needs re-testing after changes: model availability, request fields, context limits, streaming, tool calls, and pricing.
FAQ
Do I need a Claude subscription for this workflow?
That depends on your Claude Code installation, account terms, and the gateway configuration. This article does not change Anthropic's subscription or product requirements. Verify the current official Claude Code documentation and the terms of the gateway you intend to use.
Can I use any model ID from the catalog?
No. Use a model ID that is currently visible, active, and compatible with the endpoint and account. A model can be present in a catalog but unavailable for a particular API style or key.
Does an Anthropic-compatible endpoint guarantee tool calling?
No. Protocol compatibility and tool behavior are separate checks. Run a small function-calling test and verify the model's current documentation before using tools in an automated workflow.
Where should I check current models and pricing?
Use the ECAIX models directory and pricing page. These pages are the source of truth for current availability and displayed pricing; do not copy old model IDs or prices from this article.
Summary
A safe integration sequence is:
- Read the official Claude Code and gateway documentation.
- Create an ECAIX API key without exposing it publicly.
- Choose a currently available model ID from
/models. - Configure
ANTHROPIC_BASE_URLand the key locally. - Test
/api/ai/v1/anthropic/messageswith a minimal request. - Test Claude Code with a read-only task.
- Test tools, streaming, context, and permissions separately.
- Re-check compatibility whenever the client, gateway, model, or endpoint changes.
For the next step, read the Anthropic Messages API documentation, review the current model catalog, and create a key from API Keys.
A practical compatibility checklist
Before treating the integration as useful for a team, record the result of each test:
| Test | Result to record |
|---|---|
| Minimal text request | HTTP status, response shape, and model ID |
| Streaming | Whether events arrive in the format your client expects |
| Tool call | Whether the tool schema is accepted and the arguments are returned correctly |
| Long context | The largest prompt that completes within your timeout |
| File editing | Whether permissions and patch application behave as expected |
| Failure handling | How the client reports rate limits, timeouts, and upstream errors |
| Key revocation | Whether the test key can be disabled and replaced |
This checklist is more useful than a single successful greeting. A gateway can accept a text request while still requiring different settings for tools, streaming, context windows, or model aliases.
When not to use the configuration
Do not use this setup for sensitive production repositories until you understand logging, retention, routing, and access controls. Do not assume that a provider-compatible endpoint provides the same safety behavior, system prompts, tool permissions, or context accounting as the original provider. For regulated or confidential workloads, complete an internal security review and use a deployment path that your organization has approved.
Keeping the configuration current
Review the setup when any of the following changes:
- Claude Code is upgraded.
- The gateway changes its Anthropic-compatible implementation.
- The model ID is renamed, removed, or mapped to another upstream.
- Streaming, tools, context limits, or error behavior changes.
- ECAIX changes the models or API limits shown in the live catalog.
Keep the configuration in a small, documented test project. That makes it easier to compare behavior after a client or model update without exposing a production repository.