Connect Claude Code to Hivenet Router through the Anthropic Messages API and configure authentication, model aliases, streaming, and tool use.
Claude Code can use Hivenet Router as an Anthropic-format inference gateway.Claude Code sends requests to the router’s:
POST /v1/messages
endpoint. Hivenet Router authenticates the client, checks model access and quotas, selects an eligible llm agent, and forwards the original request to the backend at the same path.
Hivenet Router does not translate OpenAI Chat Completions into the Anthropic Messages format.The inference backend must serve /v1/messages itself. The model and backend must also support the tool-calling behavior Claude Code needs.Anthropic documents how Claude Code connects to gateways, but does not provide support for running Claude Code against non-Claude models through them.
at least one healthy agent registered with the llm capability
a backend that implements the Anthropic Messages API
a model with reliable structured tool calling
HTTPS when the router is reached over an untrusted network
The backend should support:
POST /v1/messagesPOST /v1/messages/count_tokens
Token counting is optional in the Claude Code gateway protocol, but implementing it gives Claude Code exact context measurements and avoids relying on local estimates.
with the tool-call parser required by that model.Tool-call configuration differs by model family. Check that the selected parser is supported by the exact model and vLLM version you deploy.
Prefer a short, stable alias for the model Claude Code will request:
hivenet-router-code-model
Current vLLM guidance recommends avoiding slash-containing Hugging Face IDs in this integration path.The alias also separates the client-facing model name from the underlying model repository:
Then test the Messages endpoint through Hivenet Router:
curl -X POST \ https://router.example.com/v1/messages \ -H "Authorization: Bearer <hivenet-router-api-key>" \ -H "Content-Type: application/json" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "hivenet-router-code-model", "max_tokens": 32, "messages": [ { "role": "user", "content": "Reply with one short sentence." } ] }'
This verifies:
client authentication
model access
routing
agent connectivity
backend Messages support
response forwarding
max_tokens is required by the Anthropic Messages request format.A hand-written request without it may be rejected by the backend even though the equivalent Chat Completions request succeeds.
Use current Claude Code and inference-backend releases.Pin a client or backend version only after reproducing a specific compatibility regression in your deployment. Treat old version pins from earlier setup notes as historical workarounds rather than permanent requirements.
for a Hivenet Router client key.Claude Code sends it as:
Authorization: Bearer <hivenet-router-api-key>
This is the authentication header Hivenet Router accepts.Do not use only:
ANTHROPIC_API_KEY
Claude Code sends that value as:
x-api-key: <value>
Hivenet Router client authentication does not read x-api-key.Unsetting ANTHROPIC_API_KEY also prevents an unrelated Anthropic API key from taking part in credential selection:
unset ANTHROPIC_API_KEY
You do not normally need to sign out of an existing claude.ai account.ANTHROPIC_AUTH_TOKEN takes precedence while it is set. The saved login remains available and becomes active again after you remove the gateway variables.Run /logout only when you deliberately want to remove the saved login or Claude Code reports an unresolved authentication conflict.
The helper must print the current raw Hivenet Router key to standard output.Claude Code sends a helper-generated credential in both:
Authorization: Bearer <value>x-api-key: <value>
Hivenet Router uses the Authorization header.By default, Claude Code caches the helper result for five minutes and runs it again after an HTTP 401.Change the cache period with:
export CLAUDE_CODE_API_KEY_HELPER_TTL_MS=900000
The value is in milliseconds.
ANTHROPIC_AUTH_TOKEN has higher credential precedence than apiKeyHelper.Remove the static token when the helper should become authoritative.
However, current Claude Code discovery ignores returned IDs that do not begin with:
claudeanthropic
Typical open-model IDs therefore do not appear automatically.Use alias mappings or ANTHROPIC_CUSTOM_MODEL_OPTION instead of renaming an open model to imply that it is a Claude model.
Do not combine gateway model discovery with:
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
The nonessential-traffic setting disables discovery.
Claude Code can make non-inference requests outside the configured gateway path for update checks, telemetry, release information, and other auxiliary behavior.On a network that permits access only to Hivenet Router, set:
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
This is optional and should not be part of the default configuration.It also:
disables automatic updates
disables gateway model discovery
suppresses the fast-mode availability check
leaves some WebFetch safety traffic subject to separate settings
Plan another update process before enabling it permanently.
Claude Code sends Anthropic-format requests, including evolving:
anthropic-version headers
anthropic-beta headers
tool schemas
system content
context-management fields
reasoning and output-configuration fields
Hivenet Router forwards the original request body and headers through the selected agent to the backend.The backend must understand the fields that arrive.
Do not place an intermediary between Hivenet Router and the backend that removes unfamiliar anthropic-* headers or request fields.Claude Code adds capabilities over time. A fixed allowlist of observed headers can break a later Claude Code release.
The preferred fix is to update the backend and use a model integration that supports the request.For diagnosis, you can temporarily disable adaptive thinking:
export CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1
You can also disable experimental beta capabilities:
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
These variables remove capabilities from the client request. They do not make an incompatible model support tools or other missing behavior.Use them as targeted compatibility controls rather than permanent defaults.
Claude Code can automatically recover from some upstream capability rejections only when it receives the original error wording.Hivenet Router currently preserves structured Hivenet Router errors but can wrap an unstructured backend error. When a new client field causes a backend 400, inspect the backend log directly rather than relying only on the final router response.
The backend does not implement the Anthropic Messages endpoint.A backend that supports only:
/v1/chat/completions
cannot serve Claude Code through the current Hivenet Router passthrough.Use an Anthropic-compatible backend or another coding client that speaks OpenAI Chat Completions.
Text works but tools fail
Check that:
the model supports structured tool calls
vLLM uses --enable-auto-tool-choice
the selected --tool-call-parser matches the model
the backend returns Anthropic-format tool-use blocks
the model follows tool schemas reliably
Test the backend directly to isolate it from Hivenet Router.
The backend rejects `system` messages
Upgrade the backend and test the current Claude Code request against it directly.Do not begin by pinning an old Claude Code release. First confirm whether the backend’s current Anthropic Messages implementation accepts the system-content shape the client sends.
The backend rejects `thinking` or `adaptive`
Update the backend first.As a compatibility test:
export CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1
Restart Claude Code after changing the variable.
The backend rejects beta fields
As a temporary diagnostic:
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
This may disable context management and newer tool features.
Claude Code retries and Hivenet Router later reports no eligible agent
Inspect the backend’s first error.A backend rejection that Hivenet Router treats as retryable can cause the request session to try other agents and exclude agents that already failed.Check: