← Blog
Published on
2026-11-19

Configure a Claude Code custom endpoint with Hivenet Router

To use Hivenet Router as a Claude Code custom endpoint, set ANTHROPIC_BASE_URL to your Router’s HTTPS origin and ANTHROPIC_AUTH_TOKEN to a Router client key. Map the CLI’s model aliases to a model that your key can access. Start Claude Code from that terminal and run /status to check the endpoint and credential source.

Claude Code sends inference requests to POST /v1/messages. Router forwards each request to an eligible model server. If your local model already answers chat requests, check which API handled them. An OpenAI Chat Completions response tells you nothing about whether the same server accepts Anthropic Messages or returns the structured tool calls a coding session needs.

This guide starts with an existing, authenticated Router deployment and a model backend that supports structured tool use. It covers the client connection and common setup failures. Use the LLM routing overview for the broader architecture and the OpenCode guide if you want that client's OpenAI-compatible provider setup.

Compatibility boundary: Anthropic documents gateway connections but does not support using Claude Code with non-Claude models through gateways. Hivenet's documented integration is not a promise of Anthropic support or identical behavior across models. The setup below was checked against current documentation on November 19, 2026; it was not run against a deployed Router and model.

What is a Claude Code custom endpoint?

A custom endpoint is the API address Claude Code uses for model requests in place of its default address. In this setup the address belongs to Hivenet Router. The developer configures the terminal client once, and the Router operator controls which registered models the client key can reach.

Use HTTPS for the connection. Both the bearer credential and the model request travel to the host named in the base URL, so confirm that host with the operator before supplying a key. Router can apply the key’s model restrictions and rate limits to those API calls. To investigate a failure, give the operator the request ID and selected model. Keep the prompt, repository contents, and token out of the support message.

What Claude Code needs from the backend

The request path is Claude Code, your Router endpoint, a selected agent, and the model server. Router forwards the Messages request to the backend. It does not convert an OpenAI Chat Completions endpoint into an Anthropic Messages endpoint. The Router integration reference describes this arrangement.

Before configuring the client, have these pieces ready:

  • An HTTPS Router address that the developer's machine can reach.
  • A dedicated client key with access to the intended model. Keep administration credentials separate.
  • A healthy agent registered for that model and the llm capability.
  • A backend that accepts POST /v1/messages and supports the model's tool-call format.
  • A current Claude Code installation, following the official installation instructions.

vLLM documents a Claude Code integration, including the need for a tool-capable model and suitable tool-call configuration. Choose the parser and chat template for your model and vLLM version. Installing a server that exposes the endpoint does not establish that the model will use tools reliably.

Use a short served-model name, such as router-code-model, consistently in the backend, agent registration, client configuration, and key permissions. This is a placeholder for your deployed model, not a model available from Hivenet by that name. The vLLM integration guidance recommends avoiding slash-containing model names for this client path.

Anthropic's gateway compatibility reference lists /v1/messages/count_tokens as optional. Without it, Claude Code can use an approximate context count. Router documents forwarding that path too, but the selected backend must implement it. Do not make token counting a prerequisite for the first connection.

Set the base URL and authentication environment variables

Start with one terminal session. That makes it easier to see which configuration the client receives before introducing persistent settings. This example assumes your secret-management process has already made the raw Router client key available as HIVENET_ROUTER_API_KEY.

Replace https://router.example.com with your Router address. Use the origin without /v1: Claude Code adds the API path itself. Replace router-code-model with the same served-model name throughout.

Bash on macOS, Linux, or WSL

: "${HIVENET_ROUTER_API_KEY:?Set the Router client key first}"
unset ANTHROPIC_API_KEY

export ANTHROPIC_BASE_URL="https://router.example.com"
export ANTHROPIC_AUTH_TOKEN="$HIVENET_ROUTER_API_KEY"
export ANTHROPIC_DEFAULT_OPUS_MODEL="router-code-model"
export ANTHROPIC_DEFAULT_SONNET_MODEL="router-code-model"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="router-code-model"

Windows PowerShell

if (-not $env:HIVENET_ROUTER_API_KEY) {
    throw "Set the Router client key first"
}
Remove-Item Env:ANTHROPIC_API_KEY -ErrorAction SilentlyContinue

$env:ANTHROPIC_BASE_URL = "https://router.example.com"
$env:ANTHROPIC_AUTH_TOKEN = $env:HIVENET_ROUTER_API_KEY
$env:ANTHROPIC_DEFAULT_OPUS_MODEL = "router-code-model"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL = "router-code-model"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "router-code-model"

ANTHROPIC_AUTH_TOKEN sends the credential in an Authorization: Bearer header, which Router accepts. ANTHROPIC_API_KEY sends an x-api-key header instead. Clearing that variable in this session avoids mixing a separate Anthropic key into the setup. See Anthropic's gateway connection instructions for credential selection.

The three alias mappings deliberately point to one model for this first connection. Choosing sonnet will request your configured model; it does not turn that model into Claude Sonnet. Map the background haiku alias as well, so the client is not left requesting a model your deployment does not serve. Later, you can assign different served models to these aliases if each supports the required requests.

Check one Messages request before opening the coding session

Use the same key and model for the direct check and the client. First confirm that the model appears in GET /v1/models for that key. Then send a short Messages request through Router. The Router API reference covers both the Messages format and the backend endpoint requirement.

These commands use Bash and a current curl installation. On Windows, run this section in WSL or another Bash environment after setting the Bash variables above. The 120-second timeout is an example upper bound for this check, not a performance target.

curl --fail-with-body --silent --show-error \
  --connect-timeout 10 --max-time 30 \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  "$ANTHROPIC_BASE_URL/v1/models"

curl --fail-with-body --silent --show-error \
  --connect-timeout 10 --max-time 120 \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  --data '{
    "model": "router-code-model",
    "max_tokens": 128,
    "messages": [
      {"role": "user", "content": "Reply with a short greeting."}
    ]
  }' \
  "$ANTHROPIC_BASE_URL/v1/messages"

Compare the model ID returned by the catalog with the name you put in the JSON request. A typo here can make authentication look like the problem even when the key works. Look for an Anthropic-format message response with a content array, rather than an OpenAI choices response. Inspect any returned error before proceeding. The explicit max_tokens field is part of the Messages request; leaving it out can produce a backend rejection.

A successful response establishes a basic text path for this request. It does not establish streaming, tool execution, large-context behavior, or support for every field Claude Code may send.

Open Claude Code and confirm the active connection

From the configured terminal, start:

claude --model sonnet

Run /status. Check that the base URL is your Router address and that the active credential source is ANTHROPIC_AUTH_TOKEN. Confirm the intended model mapping, then send a short prompt. Shell variables affect processes launched from that shell; an already-open editor or a terminal without those variables can use different settings.

For a small coding check, create a disposable folder containing a short README.md. Ask the client to read and summarize it, with no file changes. Review any tool permission request before approving it, and confirm that the answer reflects the file. A model can produce plausible prose while failing to make the structured tool call the task needs.

If you later test edits or commands, use a throwaway project and inspect what changed. Keep tool permissions in the client. Router controls access to inference; it does not decide whether the coding agent may edit a local file or run a shell command. Our tool-calling guide explains that separation.

Save the endpoint in your Claude Code settings file

Shell exports last for the terminal session. To reuse the same endpoint across projects, edit the env object in your user settings file, ~/.claude/settings.json. On Windows the default location is %USERPROFILE%\.claude\settings.json. Merge the values into any existing settings so you keep your other preferences. See the Claude Code settings reference.

For example, a developer who uses the same Router model in several repositories could save these non-secret values:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://router.example.com",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "router-code-model",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "router-code-model",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "router-code-model"
  }
}

Keep supplying the bearer token through your secret-management process when starting a new terminal. For a personal override in one repository, use .claude/settings.local.json. If you create that file yourself, add it to .gitignore. The similarly named .claude/settings.json is shared project configuration and can be committed. Keep credentials out of both files.

This article covers the terminal client. The VS Code extension and Claude Desktop have their own configuration paths, described in Anthropic's connection documentation. Do not assume that a successful terminal export configures every Claude Code surface.

Give each client its own API key

Use a dedicated Router API key for the Claude Code CLI. Keep it out of version control and frontend code. If a key appears in a commit or shared diagnostic log, revoke it, issue a replacement, and update the credential source before starting a new terminal session. A separate key lets you do that without also rotating the credentials used by your chat interface.

For a shared Router deployment, give the client an identifiable key with the model access and quotas it needs. That allows its access to be changed without reusing an administration credential. Use our Router security guide and rate limits and quotas guide for the server-side controls.

Troubleshoot API calls by endpoint, credential, and model ID

Compare the same model and credential at each step: backend, Router request, then Claude Code. A failure through the client alone calls for a different check from a backend that rejects the basic Messages request.

SymptomFirst check
401 or an authentication conflictConfirm the raw Router client key is in ANTHROPIC_AUTH_TOKEN, reaches the process, and remains valid. Inspect the active credential source before changing accounts.
404 or a missing Messages endpointRemove /v1 from the client base URL. Separately check that the backend implements /v1/messages; Chat Completions support alone is insufficient.
Model unavailable or deniedCompare all alias mappings with the key's model catalog, the agent's registered name, and the backend's served name.
Text works, but file or tool tasks failCheck client permissions and the backend's model-specific tool parser and template. A textual description of a tool call is not a structured tool response.
Output appears only after completionInspect streaming at the backend, then proxy buffering and timeouts along the Router path.
A newer client triggers unsupported-field errorsRead the field named in the backend error and compare the current client and backend compatibility documentation. Avoid deleting request fields indiscriminately.

To check streaming, repeat the same Messages request with "stream": true in the JSON body and add --no-buffer to curl. Watch for events arriving as the answer is generated. If events arrive progressively through Router but Claude Code displays the full answer at once, investigate the client. If both buffer output, compare the backend and proxy paths.

Streaming depends on the complete path carrying events progressively. Use the existing LLM streaming guide for that topic. For a Router-side failure, retain the request ID and use the monitoring and troubleshooting guide to locate the matching event. Keep credentials and private source content out of shared diagnostics.

Claude Code's request format evolves. Anthropic's compatibility reference describes endpoint and header requirements, including anthropic-version and anthropic-beta. A backend may accept a simple prompt yet reject a newer reasoning or context-management option. Follow its supported configuration for the installed versions rather than treating the first successful response as full feature compatibility.

Questions about Claude Code custom endpoints

Should the API base URL include /v1?

For this Router setup, use the HTTPS origin, such as https://router.example.com. Claude Code appends /v1/messages itself. When you send the request directly with curl, specify the full endpoint. If the proxy log shows /v1/v1/messages, remove the extra path from the client configuration and restart the session.

Do I need to sign out of my Claude account?

Usually not. An active ANTHROPIC_AUTH_TOKEN takes precedence for the gateway connection while the saved account login can remain on the machine. Use /status to confirm what is active. Signing out is a separate choice, not a required step in this guide.

Does a custom endpoint make all Claude Code traffic private?

Setting the inference endpoint does not establish where every update check, integration, or tool request goes. Review the client's enabled features and outbound network policy for your environment. Keep that decision separate from whether the model request reaches Router.

Can I use an ordinary OpenAI-compatible backend?

Only if it also implements the Messages endpoint and the request behavior this client needs. For clients that use OpenAI Chat Completions, see the OpenCode guide above or the Pi custom provider guide for Pi’s models.json setup.

Does mapping the aliases give me Claude models?

No. The alias requests the model you configured and actually serve. It does not change that model's identity, abilities, license, or support arrangements. Evaluate the coding tasks you need on that model before relying on the setup for your daily work.

Your next workload belongs on Hivenet.

Pick one AI, compute, or storage workload and see the difference for yourself. Spin it up in minutes, or let our team map your fastest path to production.