Skip to main content
Connect an Ollama server to Hivenet Router by running an agent beside the backend. The agent checks Ollama through its /api/tags endpoint, registers one available model with the router, and forwards chat-completion requests to Ollama’s OpenAI-compatible API.
One Hivenet Router agent represents one model. If your Ollama server contains several models, pin each agent to a model with --model and run a separate agent process for each one.
Ollama does not provide the engine metrics collected from vLLM, SGLang, or metrics-enabled llama.cpp servers. Hivenet Router still records routing, request, latency, health, and available hardware metrics for the agent.

Before you start

You need:
  • a running Hivenet Router router
  • Ollama on the agent host
  • at least one model pulled in Ollama
  • network access between the agent and router
  • the Hivenet Router agent binary or Docker image
  • the same JWT secret used by the router
The examples use:
Replace these values with addresses and model names from your deployment.

Start Ollama

Install Ollama:
Start the server:
OLLAMA_KEEP_ALIVE=-1 keeps loaded models in memory instead of unloading them after an idle period.To store models in another directory, set OLLAMA_MODELS before starting the server:
The agent runs on the same host, so Ollama does not need to listen on a public interface. Bind it to 0.0.0.0 only when another machine must connect directly and your network controls restrict access appropriately.

Pull a model

List the available models:
Check that the Ollama server is ready:
The response should contain the model you pulled.

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 examples pin the agent to llama3.1:8b. This avoids ambiguity when more than one model is available in Ollama.
The agent container receives GPU access so it can collect NVIDIA hardware metrics. For a CPU-only host, omit:
The /data mount preserves the agent’s peer identity across container replacement and restarts.
The agent waits until Ollama responds and the selected model is available. If Ollama is still starting or loading its model list, the agent continues polling instead of exiting permanently.

Understand the agent settings

You can provide more routing metadata:
Policies can match these values when selecting agents.

Model discovery and naming

If you omit --model, the agent requests:
It registers the first model returned by Ollama. Automatic discovery is convenient when the Ollama server contains one model. Pin the model explicitly when more than one is available.

The :latest suffix

Ollama adds :latest when a model has no explicit tag. Hivenet Router removes that implicit suffix during discovery. Explicit tags remain unchanged. When using --model, provide the model name expected by Ollama:
The model name clients send to Hivenet Router must match the model registered by the agent.

Run several Ollama models

Run one agent for each model you want Hivenet Router to expose. For the first model:
For another model:
Each agent on the same host needs a separate --identity-path so every process keeps a distinct peer identity. The agents can share the same Ollama backend URL.

Set agent capacity

--capacity controls how many concurrent requests Hivenet Router may assign to the agent. It does not change Ollama’s own parallelism or memory settings. A conservative starting point is: These values are starting points, not fixed limits. The right setting depends on:
  • model size
  • available RAM or VRAM
  • context length
  • Ollama’s parallelism configuration
  • acceptable response time
  • whether several models share the same hardware
Test the backend under representative load before raising capacity. When the agent reaches capacity, Hivenet Router stops assigning new requests to it. Depending on your router configuration, requests may wait in the per-model queue, move through a fallback chain, or fail when no capacity is available.
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 Ollama concurrency under sustained streaming load.

Verify the connection

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

Available observability

The Ollama integration does not scrape an engine-specific Prometheus endpoint. Hivenet Router can still expose:
  • agent health
  • routed request counts
  • failed request counts
  • active request and capacity state
  • smoothed round-trip time
  • success and failure history
  • CPU and memory metrics
  • NVIDIA GPU utilization, memory, temperature, and power when NVML is available
View metrics through the router:
View current agent state:
Engine-specific values such as KV cache utilization, waiting requests, time to first token, and inter-token latency are not available from the Ollama integration.

Troubleshooting

No model is found

List the pulled models:
Pull the missing model:
Check the endpoint used by the agent:

The wrong model is registered

When --model is omitted, the agent registers the first model returned by /api/tags. Restart the agent with an explicit model:

A model appears without :latest

This is expected. Hivenet Router converts:
to:
Explicit tags such as :8b or :7b are preserved.

Ollama is unreachable

Check the server:
For a Linux process, inspect its log:
For Docker:
Confirm that the agent’s --backend-url matches the address where Ollama is listening.

The first response is slow

Ollama may need to load the model into memory before serving the first request. Check loaded models:
Using:
keeps the model loaded after it has been used.

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
  • Ollama contains the selected model

The agent gets a new peer ID after restart

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

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.

Requests time out

The agent’s backend HTTP timeout defaults to two minutes. Increase it for long-running requests:
Also check whether the agent capacity is too high for the model and hardware.

Next steps

SGLang agent

Connect an SGLang backend and collect engine metrics.

Routing concepts

Learn how metadata, capacity, and policies affect agent selection.

Hardware metrics

Understand the CPU, memory, and GPU signals reported by agents.