Skip to main content
Connect an SGLang inference server to Hivenet Router by running an agent beside the backend. The agent discovers the model exposed by SGLang, registers it with the router, forwards OpenAI-compatible chat-completion requests, and reports engine and hardware metrics.
Each Hivenet Router agent registers one model. If an SGLang server exposes several models, run a separate agent for each model and use --model to select the model that agent represents.

Before you start

You need:
  • a running Hivenet Router router
  • an NVIDIA GPU with CUDA support
  • SGLang installed or available as a Docker image
  • network access between the agent host and router
  • the Hivenet Router agent binary or Docker image
  • the same JWT secret used by the router
  • access to the model you want to serve
The examples use:
Replace these values with addresses and model names from your deployment.

Start SGLang

Start SGLang with host networking:
Follow the startup logs:
Start SGLang with --enable-metrics. Without it, Hivenet Router can still forward requests, but SGLang’s cache, queue, and time-to-first-token metrics will not be available.
For a multi-GPU deployment, set the tensor-parallel size:
Wait for the model to load, then check the health endpoint:
A ready SGLang server returns HTTP status 200. List the models reported by SGLang:
The model ID returned here is the value clients must use when sending requests through Hivenet Router.

Prepare the Hivenet Router agent

From the Hivenet Router repository, build the agent image if you have not already done so:
Create a directory for the shared secret and persistent agent identity:
Place the router’s JWT secret at:
Protect it:

Start the agent

The /data mount preserves the agent’s peer identity across container replacement and restarts.The agent container receives GPU access so it can collect NVIDIA hardware metrics. SGLang continues to run as a separate process or container.
The agent waits for SGLang to become healthy and expose a model before registering with the router. If SGLang is still loading, the agent continues polling rather than exiting permanently.

Understand the agent settings

You can also add comma-separated routing tags:
Policies can match these values when selecting agents.

Select the model

The agent can discover the model automatically or use an explicit model name.

Automatic discovery

When --model is omitted, the agent requests:
It registers the first model returned by SGLang. For an SGLang server exposing one model, automatic discovery is usually sufficient.

Explicit model selection

Use --model to pin the agent to a particular model:
The explicit value overrides automatic discovery.
The model registered by the agent must match the model name clients send to Hivenet Router.

Set agent capacity

--capacity controls how many concurrent requests Hivenet Router may assign to the agent. It does not change SGLang’s own scheduler or memory configuration. Start with a conservative value based on:
  • available VRAM
  • model size
  • tensor-parallel configuration
  • expected context length
  • request concurrency
  • acceptable latency
For example:
When the agent reaches its declared capacity, Hivenet Router stops assigning new requests to it and considers other matching agents or configured fallback steps. Test the backend under representative load before increasing capacity.
For streaming responses, Hivenet Router releases the agent capacity slot when response headers arrive, while backend generation can continue. Treat --capacity as a routing-admission setting rather than a hard limit on ongoing streams, and verify SGLang concurrency under sustained streaming load.

Verify the connection

On the router, check agent health:
List the models available to clients:
Inspect the SGLang agent:
Send a chat-completion request:
Applications call Hivenet Router’s OpenAI-compatible endpoint. The agent forwards the request to SGLang’s OpenAI-compatible API.

SGLang metrics

The agent scrapes SGLang’s /metrics endpoint every 500 milliseconds by default. It sends the resulting engine data to the router, which exposes it through the router’s Prometheus endpoint. The agent does not expose a separate Prometheus port. SGLang does not expose an inter-token-latency histogram through this integration. Hivenet Router therefore does not populate average or P90 ITL values for SGLang agents. SGLang also has no preemption metric equivalent to the one collected from vLLM. View engine metrics on the router:
Useful exported metrics include:
View current values through the routing table:

Use SGLang metrics in routing policies

Exclude agents whose token cache is under pressure:
Exclude agents with queued requests:
Exclude agents whose time to first token is too high:
When a metric is unavailable for an agent, Hivenet Router skips that gate for the agent rather than excluding it. See Policy YAML reference for the full policy schema.

Tune SGLang

Use more than one GPU

Set the tensor-parallel size:
Choose a value that matches the number of GPUs assigned to the SGLang process.

Enable RadixAttention

Start SGLang with:
RadixAttention can improve prefix reuse for workloads that share prompt prefixes.

Increase the static memory fraction

Set:
This allocates a larger fraction of GPU memory to SGLang’s static memory pool.
Higher memory allocation leaves less headroom for the runtime and other processes. Test the setting with your model and workload before using it in production.

Troubleshooting

SGLang is not ready

Check the health endpoint:
Check model discovery:
Inspect the server logs:
The agent waits and retries while SGLang is unavailable or still loading.

Metrics are missing

Confirm that SGLang was started with:
Check the metrics endpoint directly:
Without metrics enabled, the endpoint may return HTTP 404. A metrics scrape failure does not stop the agent from forwarding requests.

The wrong model is registered

Automatic discovery selects the first model returned by /v1/models. Pin the correct model:
Restart the agent after changing the value.

The agent does not register

Check the agent logs:
Test connectivity from the agent to the router:
Check that:
  • the router and agent use the same JWT secret
  • the router’s libp2p interface is reachable
  • the router advertises a libp2p address the agent can reach
  • SGLang is healthy and exposes a model

The peer ID changes after restart

Make sure --identity-path points to persistent storage. For Docker:
For bare metal:

Requests time out

The agent’s backend HTTP timeout defaults to two minutes. Increase it for long-running requests:
Also check SGLang’s queue length, cache pressure, and the capacity declared by the agent.

GPU metrics are missing

Check that NVIDIA tools work on the host:
For Docker, confirm the agent received GPU access:
The agent continues to operate without NVML. It reports CPU and memory metrics but omits GPU measurements.

Next steps

llama.cpp agent

Connect a llama.cpp server and enable its Prometheus metrics.

Routing concepts

Learn how Hivenet Router filters and ranks matching agents.

Engine metrics

Understand the metrics collected from SGLang and other engines.