← Blog
Published on
2026-11-24

Pi coding agent custom provider setup with Hivenet Router

To connect the Pi coding agent to Hivenet Router, add a custom provider to ~/.pi/agent/models.json. Set the base URL to your Router endpoint ending in /v1, choose openai-completions, and supply your Router API key through an environment variable. Select a model ID from Router’s catalog, then try a short prompt before you give Pi access to project files.

This guide is for developers who use Pi as their terminal coding agent and already have access to a team inference endpoint. You’ll need Pi installed, an HTTPS Router address, and a healthy Router agent connected to a backend that streams OpenAI Chat Completions. For the file-reading example, the backend must also return structured tool calls. The examples follow the Router integration reference for Pi and Pi’s model configuration reference. They were checked against documentation on November 24, 2026. The checks below are for your deployment.

Which model ID can your Router API key use?

Ask the Router operator for the endpoint and an inference key scoped to the model you need. In the shell where you will launch Pi, have your secret manager supply the raw client key in HIVENET_ROUTER_API_KEY. The curl example uses Bash syntax. Replace the example host with your team’s host before sending the request.

curl --fail-with-body --silent --show-error --max-time 30 \
  -H "Authorization: Bearer $HIVENET_ROUTER_API_KEY" \
  https://router.example.com/v1/models

Copy an exact id from the returned list. The examples use team-code as a placeholder. If the request returns 401, check the secret in the current shell. If it returns a list without the model, check registration and model access with the operator. Editing the local model picker cannot grant access to a model.

Configure a custom provider in Pi’s models.json

Pi supports several built-in model providers. For Hivenet Router, you can add the endpoint and its models in a static JSON file because the service speaks OpenAI Chat Completions. Some custom providers need a TypeScript extension instead. For example, an extension can implement an OAuth login flow or use refreshModels to discover models at runtime. Pi explains that distinction in its custom provider reference.

Where does the provider JSON go?

Open ~/.pi/agent/models.json in your editor. If you already use other providers, merge the hivenet-router entry into the existing providers object. For a new file, start with the full example below. Replace the host, model ID, and token limits with the values for your deployment.

{
  "providers": {
    "hivenet-router": {
      "baseUrl": "https://router.example.com/v1",
      "api": "openai-completions",
      "authHeader": true,
      "apiKey": "$HIVENET_ROUTER_API_KEY",
      "models": [
        {
          "id": "team-code",
          "name": "Team coding model",
          "input": [
            "text"
          ],
          "contextWindow": 32768,
          "maxTokens": 2048
        }
      ]
    }
  }
}

The provider name hivenet-router is a label you choose inside Pi. In the example, Team coding model is a display name. Router receives team-code in the request’s model field, so its spelling and capitalization must match the catalog. For this integration, the base URL ends in /v1 and the openai-completions adapter adds /chat/completions. Copying the full path into baseUrl can send the request to the wrong address.

Keep the dollar sign in $HIVENET_ROUTER_API_KEY. Pi resolves the environment variable, and authHeader tells it to send the value as a bearer credential. The settings file can then describe the connection without containing the secret itself.

Match the context window to the backend

The example assumes a deployment with a 32,768-token context and a 2,048-token output limit. Confirm both with the operator. A model’s advertised context can exceed the limit configured on the serving backend. Pi enables automatic compaction by default to summarize older conversation history. If Pi assumes a larger context window than the backend accepts, the backend may reject the next message before compaction starts. Account for the system prompt, tool output, and requested response when you check the token budget.

Select the Router model in Pi

If you have used Pi with local GGUF files, you may recognize the /llama command. That command manages Pi’s llama.cpp router integration. For a model served through Hivenet Router, use the model picker and the provider name you added to your JSON file.

In an interactive Pi session, open /model after you save the file. This reloads the provider configuration. Pick hivenet-router/team-code, substituting your model ID. To use it by default for new sessions, highlight it in the picker and press Ctrl+S. You can also select it for one command with --model, as in the example below. See Pi’s model selection guide.

For a repeatable project setup, set defaultProvider and defaultModel in .pi/settings.json. Pi reads user-level defaults from ~/.pi/agent/settings.json. A trusted project can override those values for a new session. Keep the raw API key out of any file you commit to Git. The Pi settings reference lists the startup options.

How do I add a second Router model?

Add a second entry to the same models array. Give it its own ID, display name, context window, and output limit. Both models can share the provider URL and API key if the key grants access to both IDs. Open /model to load the recent changes. You usually don’t need to restart Pi after editing this file.

Test text generation and a read-only tool call

Run the following commands from a disposable directory. The first asks Pi which configured models match the provider name. The second sends a short prompt using the selected model with tools disabled. Substitute your actual model ID in each command that uses team-code.

pi --list-models hivenet-router
pi --model hivenet-router/team-code --no-extensions --no-tools --print "Reply with a short greeting."

What does a successful tool call look like?

A greeting shows that one prompt reached a working chat backend. To check the tool loop, create a file named route-check.txt containing a short, non-sensitive phrase. Keep the phrase out of the prompt. Pi reads the file locally and sends the tool result through Router so the model can answer. Open an interactive session with the file reader enabled:

pi --model hivenet-router/team-code --no-extensions --tools read

Ask Pi to read route-check.txt and quote its contents. Look for a file-read tool call in the terminal, then compare the answer with the file. An answer that merely describes how to read a file tells you to inspect the model’s tool calling and the backend’s parser or chat template. The Pi CLI reference describes the options used here.

Which files can the Pi coding agent access?

Pi runs tools with the operating-system permissions of the user who started the process. Its usual built-in tools can read, write, edit, and run Bash commands. Pi can ask whether you trust a project at startup, and it can execute a tool call without a separate permission popup. The examples disable extensions and limit the tools available during the check. See Pi’s security guide.

Use a dedicated account or container if a project requires a filesystem boundary. Router keys control inference access, while the local Pi process reads the file. Our Router security guide covers the endpoint side.

Troubleshoot the Pi coding agent’s connection to Router

The command works in an empty directory but fails in my project

Start with the same model, prompt, and flags in both directories. If both calls work, check what Pi loads during normal project startup. A trusted project can supply settings, extensions, skills, prompt templates, and a system prompt. These can change the selected model, available tools, or text sent with a request.

Pi extensions are TypeScript modules. An extension in the user’s ~/.pi/agent/extensions/ can load at startup even in an empty directory. Extensions can subscribe to session events, add slash commands, and change tool behavior. Keeping --no-extensions on for the connection test helps isolate those changes. See the Pi extensions reference.

Why does a resumed session select my old model?

A Pi session records model changes in its JSONL history. When you resume it, the session can restore an earlier selection. Start a new session to test the startup default, or open /model in the existing one and select your Router model. A session file can contain prompts and tool output, so share only the relevant, redacted error when asking for help. See Pi’s session file reference.

The same request fails in both directories

  • Pi cannot find the provider. Check that the file contains valid JSON and that hivenet-router sits inside providers. If PI_CODING_AGENT_DIR is set, Pi reads models.json from that directory. Reopen /model after saving, and confirm the shell that launched Pi has the key.
  • The model is listed, but the request gets a 404. For a plain 404, check that the request path ends in /v1/chat/completions. If Router returns model_not_found, compare the ID in Pi with the live /v1/models response for the same key. If the ID is missing, ask the operator to check registration, access, and agent health.
  • A short exchange works, but longer sessions fail. Check the deployed context limit and the requested output length. Tool definitions, file contents, and previous responses also use context.
  • The backend rejects a field. Preserve the error and compare it with Pi’s documented compat options. For example, change the maximum-token field only if the backend specifically needs a different field name. Changing several compatibility settings together makes the next error harder to interpret.

If the failure also occurs on a direct Router request, use the request ID and model name in the Router troubleshooting guide. If it occurs only inside Pi, record the failing command, selected provider and model, and the first error message. Remove secrets and project text before sharing the report. Those details let the operator compare the two requests.

Your next workload belongs on Hivenet.

Pick one AI, compute, or storage workload and see the difference for yourself. Spin it up in minutes, or let our team map your fastest path to production.