Prerequisites
You need:- a reachable Hivenet Router router
- a Hivenet Router client API key
- an exact model ID visible to that key
- a healthy agent with the required capability
- a backend that accepts the request format your client sends
- HTTPS when the router is reached over an untrusted network
- Python 3.9 or later
- Node.js 20 LTS or a later supported non-EOL release
Set the connection values
Use the router’s root URL without a trailing/v1:
- OpenAI-compatible clients use
${HIVENET_ROUTER_URL}/v1 - Anthropic-compatible clients use
HIVENET_ROUTER_URL
Discover available models
Query the catalog with the same key your application will use:Test with curl
Before debugging an SDK, test the router directly.Non-streaming chat
Streaming chat
- authentication
- model access
- routing
- agent connectivity
- backend compatibility
- response forwarding
Python with the OpenAI SDK
Install the SDK:Non-streaming chat
Streaming
Async requests
Tool calling in Python
The backend must return structured OpenAI-format tool calls. A complete local tool loop can look like:tool_calls.
Embeddings in Python
Use the same OpenAI client:/v1/embeddings.
Reranking in Python
The OpenAI SDK does not define a standard/v1/rerank method.
Call it directly with httpx:
document field may be null.
Use index to map each result back to the original input document.
The model must be registered with:
JavaScript and TypeScript with the OpenAI SDK
Install the SDK:Non-streaming chat
Streaming
Embeddings
Reranking
Use the built-infetch available in current Node.js releases:
Do not expose the key in browser code
Use the JavaScript SDK from:- a backend service
- a serverless function
- a protected worker
- another trusted server runtime
- browser JavaScript
- a public mobile bundle
- a committed frontend environment file
- HTML or client-visible configuration
Python with the Anthropic SDK
Use this path only when the selected backend implements:/v1. The SDK appends /v1/messages.
auth_token parameter sends:
api_key, which sends the credential in:
Count Anthropic-format tokens
When the backend supports the endpoint:TypeScript with the Anthropic SDK
Install the package:ANTHROPIC_API_KEY environment value from adding an X-Api-Key header alongside the Hivenet Router bearer token.
LangChain
Install the current integration package:ChatOpenAI targets the standard OpenAI schema.
Backend-specific response fields outside that schema may not be preserved by LangChain even when Hivenet Router forwards them successfully.
Read request IDs and quota headers
Hivenet Router returns:-1.
Python
JavaScript
- Hivenet Router audit records
- router and agent logs
- OpenTelemetry traces
- support investigations
X-Request-ID is preserved only when it is a valid UUID. Hivenet Router replaces other values with a generated UUID.
Handle Hivenet Router errors
Most inference errors use the structured envelope below. A request body larger thanHIVENET_ROUTER_MAX_REQUEST_BYTES is rejected earlier with HTTP 413, before the normal inference-handler error path, so clients should also handle an ordinary HTTP response without a Hivenet Router error code.
Hivenet Router returns errors in this envelope:
error.code rather than matching error-message text.
Common codes include:
See Error codes for the complete reference.
Timeouts
Hivenet Router’s default request deadline is:504 request_timeout response before the SDK terminates the connection locally.
For example:
- a backend that failed to start
- an exhausted GPU
- a stalled stream
- a broken tool parser
- an unreachable agent
Retries
Current OpenAI and Anthropic SDKs retry selected failures automatically by default, including some combinations of:- connection errors
- timeouts
- HTTP
408 - HTTP
409 - HTTP
429 - HTTP
5xx
- consume additional request quota
- repeat prompt-token admission
- create several audit entries
- increase load while the fleet is already unavailable
- duplicate an operation after an ambiguous network failure
- retry only selected transient codes
- use exponential backoff and jitter
- set a maximum attempt count
- respect the application deadline
- avoid retrying malformed requests
- consider whether the operation can safely run twice
X-Request-ID.
Quota behavior in applications
Request quotas
X-RateLimit-Remaining-Requests describes the remaining capacity in the applicable request-rate bucket.
For per-model quotas, the effective limit is based on:
Token admission
Before a chat request is queued, Hivenet Router checks whether this worst case fits inside the remaining daily budget:Embeddings and reranking
Embedding and reranking requests currently participate in request-rate quotas. They do not currently charge their input against the chat token-per-day budget.Headers and trust boundaries
Hivenet Router preserves the original client request headers when forwarding an inference request through the selected agent to the backend, except for transport-specific adjustments such asContent-Length.
This supports:
- request correlation
- backend feature headers
- tracing
- client-specific compatibility fields
- database credentials
- unrelated service tokens
- user session cookies
- private headers intended only for the router
Production guidance
- Give each service its own Hivenet Router API key.
- Keep credentials in a secret manager or protected runtime environment.
- Restrict each key to the models the service needs.
- Set realistic request and token quotas.
- Use bounded client concurrency.
- Configure explicit timeouts and retry behavior.
- Log Hivenet Router request IDs.
- Validate all model-generated tool arguments.
- Keep the key out of browser and mobile bundles.
- Preserve SSE streaming through reverse proxies.
- Test the exact backend features your application uses.
- Monitor requests, failures, latency, and quotas by tenant.
- Rotate keys without sharing one credential across unrelated services.
Troubleshooting
The SDK returns 401 Unauthorized
Check that:
- the raw client key is being used
- the key has not expired
- the key is not a SHA-256 hash
- the environment variable reached the process
- the reverse proxy preserves
Authorization
The Anthropic SDK returns 401
Use:
api_key or apiKey sends X-Api-Key, which Hivenet Router does not accept for client authentication.
A request goes to /v1/responses
Call:
The endpoint returns a plain 404
Check the base URL.
Do not duplicate or omit
/v1.
Hivenet Router returns model_not_found
Compare the application model with:
- capitalization
- slashes and punctuation
- agent registration
- model capability
- API-key access
- agent health
Text works but tool calls are missing
Check:- model tool support
- backend tool parser
- backend chat template
- structured
tool_callsin the raw response - tool use while streaming
- model compliance with the supplied schema
Streaming arrives only at the end
Test the router with streaming curl. When curl streams but the application does not, check the SDK code. When neither streams, check:- backend SSE behavior
- Hivenet Router agent version
- reverse-proxy buffering
- proxy read and idle timeouts
- response
Content-Type
Streaming usage is missing
The backend may not support:A single request receives 429
Inspect the error code.
Also inspect:
The SDK makes more requests than expected
Check its retry configuration. The official SDKs retry selected failures by default. Set retries to zero while diagnosing:Hivenet Router returns 503
Check the specific error code:
no_agents_availableno_capacityagent_disconnectedbackend_unavailablequeue_full
Hivenet Router returns 504 request_timeout
The router deadline expired.
Check:
- backend readiness
- model loading
- prompt size
- requested output
- engine waiting requests
- router-side queueing
- client and proxy deadlines
The reranker response has no document text
This is expected for backends that return:index to retrieve the original input document.
Next steps
Chat completions and messages
Review the OpenAI and Anthropic request paths, forwarding, streaming, and headers.
Embeddings
Review embedding request and response behavior.
Reranking
Review reranking schemas, capabilities, and responses.
API keys
Configure service-specific access, quotas, expiration, and rotation.
Error codes
Handle Hivenet Router’s structured router and backend failures.
Audit logging
Correlate application requests with tenants, models, agents, and traces.

