message for diagnostics. Do not make application logic depend on the exact message text.
Response fields
Error source
Possible values are:router value can describe an error generated by either the router process or Hivenet Router agent code.
The backend value is also intentionally coarse. It does not identify which engine, provider, or machine produced the error.
Response-format scope
The structured envelope is used by known client-facing/v1/* routes, including:
- authentication failures
- model discovery errors
- inference validation errors
- model-access denials
- quota failures
- routing and capacity failures
- classified backend errors
Administration endpoints
Many/admin/* validation responses use the simpler form:
Unknown routes
A request to a route that Hivenet Router has not registered may receive an ordinary HTTP404 rather than a structured Hivenet Router error.
For example:
- structured Hivenet Router errors
- ordinary HTTP errors
- connection failures
- truncated streams
Error-code summary
500 with backend_error, while forwarded backend or provider failures normally map it to HTTP 502.
Request and authorization errors
request_invalid
- malformed JSON
- empty request body
- missing
model - model ID longer than 256 characters
- an inference engine used with an unsupported capability
- request parsing failure inside a Hivenet Router agent
context_length_exceeded
- system or developer instructions
- conversation history
- tool definitions
- tool results
- multimodal content
- requested maximum output
- prompt size
- retained conversation history
- tool definitions
- retrieved documents
max_tokensmax_completion_tokens
invalid_parameter
temperaturetop_pmax_tokensmax_completion_tokensreasoning_effort- roles or content blocks
- tools or tool choice
- structured-output options
- model-specific parameters
unauthorized
- missing
Authorizationheader - incorrect bearer key
- client sending
x-api-keyinstead - expired static or dynamic key
- disabled dynamic key
- removed key
- using a key hash instead of the raw key
- using an administrator key on a client route
- using a client key on an administrator route
model_forbidden
quota.per_model does not produce model_forbidden.That strict-enumeration case produces rate_limit_exceeded.model_not_found
- correcting the model ID
- registering an agent
- restoring the agent
- changing the key’s access
model_redirected
/v1/embeddings and /v1/rerank. It is not a failure: the body explains the redirect to clients that do not follow redirects automatically.
follow_redirects=True with httpx. An invalid X-Hivenet-Scope request header is refused with 400 request_invalid instead.
model_waking
scale_from_zero: true:
- the model did not wake within the hold budget;
- a hold limit is reached: per model, per API key and model, or in total;
- the model woke, but the request still found no room in the admission gate before its hold budget ended. In this case a healthy agent already serves the model.
model_waking for the three messages. Match on code, not on the message.
retry_after repeats the Retry-After header, in seconds. Retry after that delay. To have the retry recognized as the same request, send a UUID of your own in X-Client-Request-ID (or X-Request-ID) and resend the same one; the router ignores an ID that is not a UUID. If the router already sent keepalive bytes to the held request, the status on the wire is 200 and this error is written in the body instead: as a final SSE event for a streaming request, as the JSON envelope after leading spaces otherwise.
Request-size rejection
HTTP 413
Hivenet Router limits request bodies under /v1/* to:
HIVENET_ROUTER_MAX_REQUEST_BYTES is rejected before it reaches the normal inference handler. That means the response body is not guaranteed to use Hivenet Router’s structured error envelope or a stable error.code.
Handle this case using the HTTP status:
Quota errors
rate_limit_exceeded
RPM bucket exhausted
Serverless per-key limits
For amode: serverless policy, this code also reports:
per-key occupancy share exceeded, please retryinput token rate exceeded, please retryoutput token rate exceeded, please retry
Retry-After: 1. Occupancy and input-token limits reject the current request. Output tokens are charged after a response finishes, so an exhausted output bucket rejects a subsequent request.
Missing per-model quota declaration
A key usingquota.per_model must enumerate every permitted model.
An undeclared model returns:
token_limit_exceeded
Before routing
The router checks whether this worst case fits:- prompt size
max_tokensmax_completion_tokens
After non-streaming inference
The backend may complete the request before Hivenet Router knows the actual output-token count. When the completion no longer fits:- the response body is discarded
- Hivenet Router returns
429 - the prompt-token deduction remains
- actual usage and the selected agent are preserved in the audit record
Streaming responses
Once a stream has started, Hivenet Router cannot replace the HTTP200 response with a later JSON 429.
Streaming output is accounted for after delivery. When it exceeds the remaining budget, Hivenet Router records the quota event in metrics, but the client retains the already delivered response.
Admission errors
input_too_long
max_input_tokens, or the image count exceeds images_max. Prompts closer to the limit are forwarded, and the backend answers context_length_exceeded if they do not fit:
concurrency_limit_exceeded
- the request would exceed the model’s token-weighted occupancy budget or
max_inflightlimit and capacity did not become available withinHIVENET_ROUTER_ADMIT_PARK_TIMEOUT; or - aggregate healthy-pool engine pressure breached a configured
shed_ifthreshold before queueing.
Routing and capacity errors
no_agents_available
- agents offline or unhealthy
- unhealthy inference backends
- capability mismatch
- static
matchfilters - dynamic
exclude_ifgates - agents excluded after earlier failed attempts
- a model-specific policy that matches no agents
- all fallback steps exhausted
no_capacity
- wait in the per-model capacity queue
- retry selection after a slot becomes available
- advance through fallback steps
- agent
--capacity - fleet size
- request duration
- engine queues
- context and output lengths
- per-model wait-queue depth
agent_disconnected
- stale peer connection
- unreachable announced address
- firewall or NAT change
- agent restart
- lost network path
- process termination
no_agents_availableno_capacityrequest_timeout
agent_disconnected.
When the code does reach the client, retry with backoff and inspect the agent connection path.
queue_full
queue_full; the final response is normally no_capacity or no_agents_available.
Retry with exponential backoff and investigate:
- request arrival rate
--queue-size--max-concurrent- agent capacity
- backend latency
- router CPU and memory
request_timeout
- waiting for processor concurrency
- waiting in the per-model capacity queue
- policy selection
- retries
- agent redial
- agent forwarding
- inference
- provider fallback
- returns
504withrequest_timeout - keeps the agent registered and does not reset its connection, so the agent’s other in-flight streams continue
- does not retry the request on another agent
- does not count the timeout against the agent’s success rate, failure streak, or SRTT
consecutive_timeouts count. Any successful forward resets it to 0. The default policy excludes an agent once consecutive_timeouts reaches 3 or more, which removes an agent whose backend hangs from rotation. See Exclude hung agents to tune or disable this gate:
agent_disconnected.
Retry only when the application operation is safe to repeat.
For systematic timeouts, inspect the request path before increasing:
Backend errors
backend_unavailable
- backend connection failure
- model still loading
- backend HTTP
429 - backend HTTP
503 - temporary engine overload
- another agent
- another local fallback step
- an external provider fallback
no_agents_available rather than backend_unavailable.
Retry with backoff when the backend condition is temporary.
backend_error
- inference backend HTTP
500or502 - unexpected backend response
- invalid response JSON
- provider fallback failure
- unstructured error from a transparent proxy endpoint
- storage or authentication-provider failure
- another internal processing error
backend_error directly because no routing step remains after that fallback.
Retry once only when:
- the request is safe to repeat
- the failure appears transient
- retrying will not worsen an overloaded backend
How native Chat Completions errors are classified
The Hivenet Router agent classifies non-success responses from the native:JSON error types
The classifier recognizes both:HTTP and text fallback
When the error type is not recognized:429 is classified as backend_unavailable, not as Hivenet Router’s rate_limit_exceeded.rate_limit_exceeded describes Hivenet Router client-key quota admission.Errors from transparent proxy endpoints
These paths use the agent’s generic transparent proxy:- It checks whether the body already contains a Hivenet Router structured error.
- If it does, that code and source are preserved.
- Otherwise, the router wraps the body as
backend_error.
400.
Internal routing retries
A backend or agent error is not necessarily returned to the client immediately. Hivenet Router distinguishes several categories.Request-level errors
These stop the routing session immediately:Connection failures
A stale or disconnected agent connection receives one free redial attempt per request. That redial does not consume the policy step’smax_tries budget.
Retryable forwarding failures
Other agent and backend errors can:- mark the selected agent as failed in the current policy step
- select another eligible agent
- continue until
max_triesis reached - advance through the fallback chain
- use provider fallback where configured
Streaming error behavior
A structured JSON error with a non-200 status can be returned only before response headers and body have started.
After an SSE stream begins:
- the HTTP status is already
200 - some output may already have reached the client
- Hivenet Router cannot replace the stream with a JSON error envelope
finish_reason or [DONE] for OpenAI, message_stop for Anthropic). See stream_truncated for the frame format.
If the upstream stream is cut in the middle of an SSE line, Hivenet Router drops the incomplete line rather than forwarding a broken event. The client receives only complete events, followed by the error frame.
When the client itself disconnects, Hivenet Router does not send a frame and does not count the stream as truncated.
A stream can still end without a terminal frame when the connection between the client and the router fails. The client should treat any stream that ends without the normal completion marker or with a stream_truncated frame as a failed or partial operation, even when the initial HTTP status was 200.
Use the request ID to inspect the associated audit record, router logs, agent logs, and trace.
stream_truncated
/v1/chat/completions, the frame is:
/v1/messages, the frame is an Anthropic error event with an api_error whose message starts with stream_truncated:
hivenet_stream_truncated_total metric, labeled by model and reason. See Streaming responses for how the router relays SSE streams.
Error response headers
Hivenet Router can add the following headers.Correlate an error
Every router response includes:- tenant
- dynamic key ID
- model
- status
- error code
- selected agent
- latency
- token counts
- trace ID
Diagnose by status
HTTP 400
Check:
- request JSON
- required model and message fields
- context length
- model-specific parameter support
- tools and structured-output schemas
- backend logs
HTTP 401
Check:
- raw bearer key
- credential expiration
- dynamic key state
- correct client or administrator key type
- reverse-proxy header forwarding
HTTP 403
Check the explicit model allowlist.
HTTP 404
Check:
- endpoint path
- base URL construction
- exact model ID
- client model visibility
- registered agents
404 may mean an unsupported route. A structured model_not_found refers to model discovery or routing.
HTTP 413
Reduce the request body or split a large batch. Check both HIVENET_ROUTER_MAX_REQUEST_BYTES and any reverse-proxy or ingress body limit.
HTTP 429
Inspect:
- RPM exhaustion
- undeclared per-model quota
- insufficient worst-case token budget
- exhausted daily token budget
HTTP 503
Inspect the specific code.
HTTP 504
Check:
- global queueing
- per-model queueing
- policy retries
- connection resets
- backend queue depth
- model loading
- prompt and output size
- router request timeout
Client retry guidance
Before retrying, determine both:- whether the error is temporary
- whether repeating the application operation is safe
- request quotas
- application deadlines
- maximum attempts
- concurrency
- audit expectations
Production handling
A production client should:Parse structured errors
Preserve the HTTP status and X-Request-ID
X-Request-ID.Handle ordinary HTTP errors when no structured envelope exists
Distinguish temporary capacity failures from request defects
Apply bounded retries with exponential backoff and jitter
Avoid retrying unsafe or ambiguous operations automatically
Log the code, status, source, request ID, and model
Avoid logging credentials or complete sensitive prompts
Alert on sustained error rates rather than individual transient failures
Use audit records and traces for detailed investigation
Next steps
Performance characteristics
Use from code
Routing concepts
API keys
429 responses.
