Skip to main content
Use Hivenet Router from your own scripts, applications, services, and frameworks through standard HTTP APIs and existing SDKs. Hivenet Router does not require a dedicated client library. Point a compatible client at the router, provide a Hivenet Router API key, and use an exact model ID registered by an agent.
Hivenet Router does not expose the OpenAI Responses API:
Call Chat Completions explicitly and configure frameworks not to switch to the Responses API automatically.

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
Current releases of the official OpenAI SDKs require:
  • Python 3.9 or later
  • Node.js 20 LTS or a later supported non-EOL release
Check the installed SDK version’s runtime requirements when upgrading.

Set the connection values

Use the router’s root URL without a trailing /v1:
The examples construct the endpoint appropriate to each SDK:
  • OpenAI-compatible clients use ${HIVENET_ROUTER_URL}/v1
  • Anthropic-compatible clients use HIVENET_ROUTER_URL
Do not store the raw key in source control.

Discover available models

Query the catalog with the same key your application will use:
The response is filtered by the key’s model access. Use one of the returned IDs exactly as shown. Model matching is case-sensitive.

Test with curl

Before debugging an SDK, test the router directly.

Non-streaming chat

Streaming chat

Output should arrive incrementally. A successful request confirms:
  • authentication
  • model access
  • routing
  • agent connectivity
  • backend compatibility
  • response forwarding

Python with the OpenAI SDK

Install the SDK:
Create a client:
This guide disables automatic SDK retries so one application operation produces one request to Hivenet Router. Add an intentional retry policy later when your application can safely handle duplicate attempts.

Non-streaming chat

The backend determines which roles, parameters, and content types it supports. Hivenet Router forwards the original request rather than adapting unsupported fields.

Streaming

When the backend supports final streaming usage, request it with:
Do not require this field unless you have tested it against the deployed backend. Hivenet Router can still meter streamed output when the backend does not return a final usage chunk.

Async requests

Use bounded concurrency in services rather than starting an unlimited number of requests. For example:
Hivenet Router also applies its own declared agent capacity and queue limits. Client-side bounds prevent one application from filling the router queue unnecessarily.

Tool calling in Python

The backend must return structured OpenAI-format tool calls. A complete local tool loop can look like:
Never execute a model-selected tool only because its name appears in the response.Validate:
  • the tool name
  • every argument
  • user permissions
  • allowed paths and resources
  • command or network boundaries
For vLLM, structured tool calls normally require:
When the model describes a tool call in plain text, correct the model, chat template, or backend parser. Hivenet Router does not convert plain text into tool_calls.

Embeddings in Python

Use the same OpenAI client:
The selected model must be registered with:
A model registered only as an LLM cannot serve /v1/embeddings.

Reranking in Python

The OpenAI SDK does not define a standard /v1/rerank method. Call it directly with httpx:
The response’s 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:
Create a server-side client:

Non-streaming chat

Streaming

Embeddings

Reranking

Use the built-in fetch 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
Do not put a Hivenet Router API key in:
  • browser JavaScript
  • a public mobile bundle
  • a committed frontend environment file
  • HTML or client-visible configuration
A user who can inspect the application can extract a client-side bearer key and use its complete model access and quota. Place your own authenticated application endpoint between the browser and Hivenet Router.

Python with the Anthropic SDK

Use this path only when the selected backend implements:
Install the SDK:
Create the client with bearer authentication:
Use the router root without /v1. The SDK appends /v1/messages.
The auth_token parameter sends:
This matches Hivenet Router client authentication. Do not use only api_key, which sends the credential in:
Hivenet Router does not authenticate client requests from that header.

Count Anthropic-format tokens

When the backend supports the endpoint:
Hivenet Router forwards the request to:
It does not calculate the Anthropic token count itself.

TypeScript with the Anthropic SDK

Install the package:
Setting:
prevents an unrelated ANTHROPIC_API_KEY environment value from adding an X-Api-Key header alongside the Hivenet Router bearer token.

LangChain

Install the current integration package:
Configure Chat Completions explicitly:
Set:
Hivenet Router does not expose /v1/responses. Current LangChain releases can infer the Responses API from model names or invocation parameters unless the choice is explicit.
LangChain’s 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:
on every HTTP response. It also returns quota headers when a finite quota applies:
Unlimited quota values are omitted rather than returned as -1.

Python

JavaScript

Log the request ID with your application operation so it can be correlated with:
  • Hivenet Router audit records
  • router and agent logs
  • OpenTelemetry traces
  • support investigations
A client-supplied 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 than HIVENET_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:
The SDK maps the HTTP status to its general exception type. Inspect the response body for the Hivenet Router-specific error code.
Use the structured 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:
A client timeout cannot extend that deadline. For a router using its default, set the client timeout slightly above 60 seconds so Hivenet Router can return its structured 504 request_timeout response before the SDK terminates the connection locally. For example:
When the router is configured with a five-minute deadline:
the client also needs a deadline long enough to receive that response. Check the actual backend before increasing timeouts. A long timeout does not correct:
  • 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
This can turn one application action into several Hivenet Router requests. Retries may:
  • 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
The examples use:
so retry behavior remains under application control. When retries are appropriate:
  1. retry only selected transient codes
  2. use exponential backoff and jitter
  3. set a maximum attempt count
  4. respect the application deadline
  5. avoid retrying malformed requests
  6. consider whether the operation can safely run twice
Hivenet Router does not currently deduplicate repeated requests by 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:
A request with:
can therefore be rejected even when the model would probably produce only a short response. Choose a realistic output limit rather than always sending the backend maximum.

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 as Content-Length. This supports:
  • request correlation
  • backend feature headers
  • tracing
  • client-specific compatibility fields
It also means you should not attach unrelated secrets to a Hivenet Router request.
Treat the router, selected agent, and inference backend as one trusted request path.The backend may receive the Hivenet Router Authorization header and other custom client headers.
Do not send:
  • database credentials
  • unrelated service tokens
  • user session cookies
  • private headers intended only for the router
unless the backend is explicitly trusted to receive them.

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
Test the same key with:

The Anthropic SDK returns 401

Use:
in Python or:
in TypeScript. Using only api_key or apiKey sends X-Api-Key, which Hivenet Router does not accept for client authentication.

A request goes to /v1/responses

Call:
rather than:
For LangChain, set:

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:
Check:
  • 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_calls in the raw response
  • tool use while streaming
  • model compliance with the supplied schema
The problem is usually in the model or backend rather than the SDK or router.

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:
Remove the field or handle a missing final usage chunk. Hivenet Router’s own stream meter can still record usage for quotas, audit data, and metrics.

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_available
  • no_capacity
  • agent_disconnected
  • backend_unavailable
  • queue_full
Then inspect:

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:
Use the result’s 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.