Skip to main content
Hivenet Router authenticates three kinds of access separately:
  • agents joining the inference network
  • clients calling /v1/* endpoints
  • operators calling /admin/* endpoints
Agent authentication is always required. Client authentication may be disabled for local development. Administrator authentication is secure by default: the router refuses to start with unauthenticated /admin/* endpoints unless HIVENET_ROUTER_ALLOW_INSECURE_ADMIN=true is set explicitly. Auth

Authentication boundaries

When no client authentication configuration is provided, /v1/* is accessible to any client that can reach the router./admin/* does not become public automatically. The router refuses insecure administrator mode unless HIVENET_ROUTER_ALLOW_INSECURE_ADMIN=true is set explicitly. Use that override only in an isolated development environment.
Agent authentication is separate from the two HTTP authentication surfaces. Setting the client API to none does not disable router-agent authentication.

Agent authentication

Every agent must authenticate before it can register with the router. The router and every agent share one high-entropy secret. Hivenet Router uses that secret for two related purposes:
  • signing and validating agent JWTs
  • deriving the gRPC TLS identity used during authentication
The secret must contain at least 32 bytes. Generate one:
Use the same file on the router:
and every agent:
You can also provide the value through the case-sensitive environment variable:
Anyone who obtains this secret can authenticate an agent and derive the gRPC server identity.Distribute it through your normal secrets-management system and restrict access on every host.

Agent authentication flow

An agent joins the network in two stages.

1. Authenticate over gRPC

The agent:
  1. creates a JWT signed with HMAC-SHA256
  2. includes its libp2p peer ID as the JWT subject
  3. connects to the router’s gRPC authentication endpoint
  4. verifies the router’s pinned TLS public key
  5. sends the JWT and its agent metadata
The router:
  1. verifies the JWT signature
  2. validates its issuer, issue time, expiry, and subject
  3. validates required agent metadata
  4. creates a random session token
  5. returns the session token, router libp2p addresses, and runtime configuration
The gRPC endpoint uses TLS 1.3. Hivenet Router deterministically derives an Ed25519 certificate and public key from the shared JWT secret using HKDF-SHA256. The agent pins that public key, so the deployment does not need a separate certificate authority or pre-distributed gRPC certificate files. A router and agent using different secrets fail the TLS identity check before registration.

2. Register over libp2p

After gRPC authentication, the agent connects to the router’s libp2p endpoint and presents the session token. The router links:
  • the authenticated agent identity
  • the agent’s libp2p peer ID
  • its registered model and metadata
  • the short-lived session
Router-agent traffic then uses libp2p with Noise encryption.

Agent metadata validation

The router rejects authentication when required metadata is missing or invalid. Required fields include:
  • model
  • positive capacity
  • agent version
  • engine
  • region
  • organization
Other metadata can include:
  • capability
  • machine identifier
  • tags
  • GPU model
  • display name and model description
If metadata validation fails, the agent receives an unsuccessful gRPC authentication response and does not register.

Agent sessions

The session token is separate from the initial JWT. Configure the router session lifetime:
or:
The value must be greater than five minutes. The agent reads the session lifetime returned by the router and reauthenticates five minutes before expiry. After receiving a new session token, it registers that token against the same libp2p peer ID without interrupting normal heartbeats and routing signals. If renewal fails, the agent retries after 30 seconds.

Client API authentication

Client authentication protects the /v1/* endpoints, including:
  • chat completions and messages
  • embeddings
  • reranking
  • model discovery
Hivenet Router supports three client-authentication modes.

No authentication

When no auth.yaml is configured and HIVENET_ROUTER_AUTH_MODE is unset, the client API uses:
Requests do not require an Authorization header. The authenticated tenant is recorded internally as:
Use this only on a protected local or private network.

Static API keys

Static mode loads hashed API keys from auth.yaml.
Generate a key and the matching YAML entry:
The command prints:
  • the raw client key, shown once
  • its SHA-256 hash
  • a masked preview
  • a ready-to-paste auth.yaml entry
The generated key begins with:
Store the raw value securely. Hivenet Router stores and compares only its SHA-256 hash. Start the router with the file:
Send the raw key as a bearer token:
Static API keys can define:
  • tenant identity
  • human-readable metadata
  • expiration
  • model restrictions
  • request-rate limits
  • daily token limits
  • per-model quotas
Send SIGHUP after changing auth.yaml:
Hivenet Router validates the updated file before replacing the active static-key provider.
A successful authentication reload rebuilds in-memory quota state. Request-rate buckets reset. Daily token usage also resets with the memory quota backend, while the badger backend preserves and restores daily token state.

Dynamic API keys

Dynamic mode uses an in-memory key registry managed through protected administration endpoints. Enable it when no auth.yaml is provided:
The registry starts empty. An external control service must add or replace client keys through:
Dynamic entries contain SHA-256 key hashes rather than plaintext client keys. The registry is not persisted. It must be repopulated after every router restart.
Administration authentication is mandatory in dynamic mode.Hivenet Router refuses to start without HIVENET_ROUTER_ADMIN_API_KEYS, because the administration endpoints control the client-key registry itself.
See Admin endpoints for the dynamic registry API.

Client request format

Send the raw client key in the standard bearer header:
For example:
Hivenet Router also accepts the raw token without the Bearer prefix, but the standard bearer format is recommended for clients and proxies.

What successful authentication provides

After a client key is authenticated, Hivenet Router adds its resolved access information to the request context. This includes:
  • tenant or owner ID
  • dynamic key ID, when applicable
  • masked key preview
  • allowed models
  • quota configuration
Downstream middleware and handlers use these values for:
  • model authorization
  • request-rate enforcement
  • token-budget enforcement
  • tenant metrics
  • audit records
Authentication confirms the key. Separate authorization and quota checks decide whether the request may use the selected model and capacity.

Model access control

A client key can be limited to specific models. For static keys:
An empty model list grants access to all registered models unless a per-model quota configuration defines a narrower set. A request for a disallowed model returns HTTP 403:
The model catalog is also filtered to the models visible to the calling key. When quota.per_model is configured, its model names become the effective allowlist. A model missing from that map is hidden from discovery and rejected for inference with HTTP 429 rate_limit_exceeded, rather than 403 model_forbidden. See Model restrictions for the complete behavior.

Administration authentication

Administration authentication protects /admin/*. Configure it separately in auth.yaml:
Raw admin keys come from:
The values are comma-separated. Hivenet Router hashes them at startup for request comparison. They are not added to auth.yaml. Changing a systemd environment file, Docker .env file, Kubernetes Secret, or shell configuration does not change the environment of an already running router. Restart or recreate the router after changing HIVENET_ROUTER_ADMIN_API_KEYS. Use an admin key:
Use different credentials for the client and administration surfaces.
Client API keys do not automatically grant administration access, and admin keys do not automatically act as client API keys.
When admin.mode is none, the router refuses to start unless you also set:
That override makes the administration API accessible to any network client that can reach it. Use it only for isolated development and testing.

Configuration precedence

When an auth configuration file is provided:
the file controls the API and admin sections. The client API can otherwise use:
when no auth file is configured. In practical terms: Invalid modes, empty required key lists, malformed hashes, duplicate hashes, invalid expiry dates, or invalid quotas prevent the router from starting or reloading the configuration.

Authentication failures

Missing, malformed, expired, and unknown client or admin credentials receive the same response.
Hivenet Router deliberately does not reveal whether:
  • the header was missing
  • the key was unknown
  • the key had expired
  • the key was disabled
This reduces information leakage to unauthenticated callers. Agent-authentication failures are reported to the agent through the gRPC authentication response and router logs rather than through the public HTTP error envelope.

Transport security

Hivenet Router protects different network paths differently. For production client traffic, place Hivenet Router behind a reverse proxy, ingress, or load balancer that provides HTTPS. For example:
Authentication does not replace network security. Restrict:
  • gRPC and router libp2p ports to agent hosts
  • administration endpoints to operators or management networks
  • Prometheus endpoints to monitoring systems

Secret responsibilities

Do not reuse one value for several roles. Compromise has different consequences:
  • the agent secret allows unauthorized agents to join
  • a client key allows requests within that key’s permissions and quotas
  • an admin key allows operational access and possibly key-registry changes
  • a provider key allows billable external-provider use
  1. Generate a strong shared agent secret.
  2. Store it through a secrets manager on the router and agents.
  3. Enable static or dynamic authentication for /v1/*.
  4. Enable administration API-key authentication.
  5. Use distinct client, admin, agent, and provider credentials.
  6. Restrict each port at the network layer.
  7. terminate client-facing HTTPS before the router.
  8. Apply least-privilege model access and quotas.
  9. Enable audit logging and authentication metrics.
  10. Define and test a rotation process.

Troubleshooting

An agent reports a TLS key mismatch

The router and agent are using different JWT secrets. Compare their secret files without printing their contents:
The hashes must match. Restart the affected process after correcting the secret.

The router rejects the agent metadata

Check the agent logs for the field named in the rejection. Required values include:
  • model
  • positive capacity
  • version
  • engine
  • region
  • organization

A client receives 401 unauthorized

Check that:
  • the correct key is being sent
  • the header uses the expected value
  • the router loaded the intended auth configuration
  • the static key has not expired
  • a dynamic key is enabled and present after the latest router restart
  • the request is reaching the intended router environment
Do not expect the response to distinguish these cases. Check operator logs and configuration.

A valid client key receives 403 model_forbidden

Authentication succeeded, but the key may not use the requested model. Review:
  • models for static keys
  • allowed_models for dynamic keys
  • quota.per_model
  • exact model spelling and capitalization

Administration requests receive 401

Client and administration credentials are separate. Confirm that:
and that the submitted value appears in:
Restart the router after changing the environment variable.

Static changes do not take effect

Send SIGHUP:
Then inspect the router logs for parsing or validation errors. Dynamic registry entries are not reloaded from auth.yaml.

Dynamic keys disappear

The dynamic registry is stored in memory. Repopulate it through the administration API after every router restart.

Next steps

API keys

Generate, configure, manage, and revoke static and dynamic client keys.

auth.yaml reference

Review the complete static authentication and quota schema.

Key rotation

Rotate agent, client, administrator, and provider credentials safely.