Complete structure
Top-level fields
The
models field is ignored for a global policy loaded through:
--policy-file_default.yamlPUT /admin/policy
Admission control fields
The admission fields are top-level properties of the policy, not fields insiderouting_policy. They apply to POST /v1/chat/completions and POST /v1/messages; the count-tokens, embedding, and reranking paths are exempt.
0, which disables the corresponding check. Negative values are rejected. mode defaults to reserved and accepts only reserved or serverless.
mode
reserved enables the shared B1, B2, and B3 safety gates without serverless per-key caps. serverless enables the same safety gates plus the B4 fields resolved from the authenticated key. An empty value is normalized to reserved; any other value is a load-time error.
max_input_tokens and images_max
These are the B1 hard caps. The token check uses the same learned estimate used by occupancy and token quotas. It includes message text, the Anthropic top-level system prompt, and raw tool-definition JSON. The image check counts OpenAI image_url parts and Anthropic image blocks. Either breach returns HTTP 400 input_too_long.
admit_budget_tokens and max_inflight
Both values are per replica. The router recomputes the number of healthy replicas for every request and floors that count at 1:
HIVENET_ROUTER_ADMIT_PARK_TIMEOUT before the router returns 429 concurrency_limit_exceeded. Existing reservations are not canceled when the healthy pool shrinks; the smaller limit affects new admissions until work completes.
Benchmark-derived values are not loaded automatically from router_limits.yaml. Operators or provisioning tooling must copy the certified per-model values into the policy.
shed_if
kv_cache_utilization and waiting_requests in shed_if, with exactly one of gt, lt, gte, or lte per field. At admission, the router averages each reported signal across healthy agents serving the requested model. Missing signals pass. If a threshold fails, the router returns 429 concurrency_limit_exceeded with Retry-After: 1 before queueing the request.
This is additive to per-agent exclude_if gates. Use exclude_if to remove an unhealthy or overloaded replica from a routing step; use shed_if to stop admitting new work when the serving pool as a whole is under pressure.
Cross-config validation
At startup and on auth or policy reload, the router validates every static and dynamic key against the effective serverless policies. Dynamic admin writes run the same checks. A configured occupancy share must be in(0, 1], and a nonzero input_tokens_per_minute must be at least max_input_tokens for every reachable serverless model. Invalid reloads leave the previous policy active.
See Admission control for request-footprint calculation, parking, per-key limits, and error responses.
Primary routing policy
The router rejects a policy whose primary step has no
strategy.
Static matching
Thematch object filters agents using metadata supplied during registration.
Engine values
Built-in agent engine names are:llamacpp, not llama.cpp.
Match logic
This policy:EU-France and whose engine is exactly vllm.
It does not match:
Tag logic
Every tag listed in the policy must be present on the agent.Match every eligible agent
Use:match when the policy should not restrict agents by metadata.
Model, health, capability, previous failures, and capacity still apply as hard routing constraints.
Dynamic metric gates
Theexclude_if object removes agents whose live metrics violate a threshold.
Comparison operators
Each metric accepts exactly one operator.
Valid:
Missing metrics
When a metric is unavailable for an agent, Hivenet Router skips that gate for the agent. For example:Metric units
Use:
0 to 100 scale. Hivenet Router normalizes these values to fractions before policy evaluation.
Universal metrics
These gates can apply to any agent once the necessary runtime history exists.Capacity utilization
capacity_utilization rule.
Success rate
Smoothed latency
Consecutive failures
Engine metrics
These gates depend on metrics exposed by the inference backend.
Backend support differs:
Preemption and throughput values are available for observability but are not currently valid
exclude_if fields.
Cache pressure
Backend queue
Time to first token
Hardware metrics
Hardware gates use the most recent snapshot reported by the agent.
When a host has several GPUs, Hivenet Router evaluates the highest reported value for:
- temperature
- compute utilization
- VRAM utilization
Ranking strategy
Every policy step requires a ranking strategy. The only implemented strategy is:Forward attempts
max_tries is the number of failed forwards allowed in one policy step before Hivenet Router advances to the next fallback step.
A value of 0, a negative value, or an omitted field uses the router-wide default:
- backend unavailability
- backend overload or rate-limit responses
- retryable backend errors
- transport failures after connection recovery is exhausted
request_invalid, invalid_parameter, context_length_exceeded, and token_limit_exceeded stop immediately. They do not consume additional tries or advance through other local agents.
The following do not consume a forward try:
- no matching agents
- agents excluded by policy gates
- all agents already at capacity
- losing an atomic capacity-slot race
- the first connection-level recovery attempt for an agent
Fallback chain
fallback_chain contains ordered local policy steps.
routing_policy always runs first.
Each fallback entry supports:
When
name is omitted, Hivenet Router generates a name based on the step’s array position.
A step advances when it has no viable candidates or exhausts its forward budget.
Model and capability remain fixed throughout the fallback chain. A fallback step cannot route a request to another model or workload capability.
See Fallback chains for examples and execution behavior.
Provider fallback
fallback_provider defines one external API used after every local step is exhausted.
fallback_chain.
Supported engines are:
Credentials do not belong in the policy YAML.
The router rejects a policy when:
- the provider engine is unsupported
- the corresponding API key is not configured
- the provider model is empty
Global policy file
Load one global policy:Per-model policy directory
Use a directory when different models need different policies:.yaml and .yml files are loaded.
_default.yaml
The special file:
models field is ignored.
_default.yaml takes precedence.
A parse or validation error in _default.yaml is fatal during router startup.
Named per-model files
Every other policy file must contain at least one model:models is skipped with a warning.
A model can belong to only one named policy document.
Model ownership conflicts
At initial startup, policy files are processed by modification time, oldest first. When two files claim the same model:- the older file claims the model
- the later conflicting file is skipped entirely
Per-model file errors
During initial loading:- invalid
_default.yamlstops router startup - an invalid named policy file is logged and skipped
- a named file without
modelsis logged and skipped - other valid named policies still load
Policy selection
For each request, Hivenet Router:- looks for a named policy assigned to the requested model
- uses that policy when one exists
- otherwise uses the active global policy
- global
matchvalues - global gates
- global fallback steps
- global provider fallback
Reload policies with SIGHUP
Reload policies without restarting the router:- Hivenet Router parses and validates the file
- valid changes replace the active policy
- invalid changes are rejected
- the previous active policy remains in use
- unchanged files are not reapplied
- valid changed files replace their named policies
- deleted named files lose their policies
- invalid existing files keep their previous active policy
- conflicting changed files are skipped
- unrelated valid policies remain active
If
_default.yaml is deleted during a directory reload, the current implementation reverts the global policy to Hivenet Router’s built-in least-loaded default.Manage policies through the admin API
Global policy
models field is ignored for this endpoint.
Named policies
--policy-model-dir for persistent configuration.
See Admin endpoints for the complete API behavior.
Global example
Per-model example
BAAI/bge-m3 is an embedding model, a configured fallback_provider would not be used for its requests.
Validation checklist
Before loading a policy, check that:routing_policy.strategyis present- every fallback step has a supported strategy
- the strategy is
least-loaded - every
exclude_iffield is spelled correctly - every metric has exactly one comparison operator
- percentage thresholds use fractions
- SRTT uses milliseconds
- TTFT and ITL use seconds
- provider credentials are set when provider fallback is configured
- every named file declares at least one model
- no two named files claim the same model
- YAML indentation is valid
Troubleshooting
The router rejects the policy
Check its logs for the first validation error. Common causes include:- missing
strategy - unsupported strategy
- unknown metric field
- missing comparison operator
- several operators on one metric
- missing provider engine or model
- provider API key not configured
- invalid YAML indentation
A policy file is ignored
For a named file, check that:- its extension is
.yamlor.yml - it contains a non-empty
modelsarray - another file does not already claim one of its models
- it passed YAML and policy validation
A model uses the global policy
Confirm that the model name in the file exactly matches the model registered by the agent:A gate does not exclude an agent
Inspect the live value:A changed policy does not take effect
File changes are not watched continuously. SendSIGHUP:
Next steps
Fallback chains
Build ordered local alternatives with independent filters and retry budgets.
Provider fallback
Configure OpenAI or Anthropic as a final fallback for chat requests.
Policy gates
Review practical gate patterns for health, latency, cache, and hardware pressure.

