llm agent, and forwards the request to the backend.
Prerequisites
Before configuring OpenCode, you need:- a reachable Hivenet Router router
- a Hivenet Router client API key
- at least one healthy agent registered with the
llmcapability - an inference backend that supports OpenAI Chat Completions
- a model with reliable tool-calling behavior
- HTTPS when the router is reached over an untrusted network
Prepare the inference backend
A text-generation model can answer basic prompts without supporting the structured tool calls OpenCode needs for coding work. The model and inference engine must support operations such as:- reading files
- editing files
- creating files
- running shell commands
- invoking custom tools or MCP tools
Tool support is model-specific.A parser that works for one model family may produce malformed or plain-text tool calls with another.
- the backend’s served-model name
- the Hivenet Router agent registration
- the OpenCode provider configuration
- the client key’s model restrictions or per-model quotas
Test Hivenet Router directly
Before installing or configuring OpenCode, send a basic Chat Completions request:- the client key works
- the key can access the model
- an eligible agent is registered
- the backend accepts Chat Completions
- the router can return the response
Install OpenCode
- Install script
- npm
- Homebrew
- Windows
Choose a configuration location
OpenCode supports both global and project configuration.
OpenCode merges its configuration sources. Project settings override conflicting global settings while preserving unrelated global values.
Use a global file when the same Hivenet Router provider should be available everywhere.
Use a project file when the model, permissions, or router should be tied to one repository.
Configure the provider
Create:https://router.example.comwith the router addresshivenet-router-code-modelwith an exact model ID from/v1/models- the context and output limits with values supported by that model and backend
Set the API key
Export the raw Hivenet Router client key:HIVENET_ROUTER_API_KEY is an environment variable used by the OpenCode client.It does not need to follow the lower-case hivenet_router_* convention used by the Hivenet Router router process.Read the key from a file
OpenCode can also substitute the contents of a file:Understand the provider configuration
Provider ID
hivenet-router is the OpenCode provider ID.
It is an arbitrary local identifier, but it must match the prefix used in:
Provider adapter
Base URL
Use:Model entries
name value is only the label displayed by OpenCode.
For example:
Model limits
OpenCode cannot infer these values automatically for an arbitrary custom provider.
Set them according to the actual model, backend configuration, and deployment limits.
Incorrect limits can cause:
- premature context compaction
- requests that exceed the backend context window
- unexpectedly short output
- backend
400validation errors
Configure several models
Add each model visible through Hivenet Router:Set the small model explicitly
OpenCode can usesmall_model for lightweight background tasks such as title generation.
Set it explicitly:
Restrict OpenCode to Hivenet Router
The example uses:enabled_providers controls model providers.It does not block every other network feature, such as web tools, plugins, update checks, remote MCP servers, or schema retrieval.Disable session sharing
OpenCode’s default sharing mode is manual, not automatic. The example sets:/share command.
This is appropriate when sessions may contain:
- proprietary source code
- credentials or configuration
- internal documentation
- customer information
- security findings
Review tool permissions
OpenCode tools can read, edit, and create files or run commands in the project environment. Current OpenCode defaults allow tool operations without requiring explicit approval. The example changes two consequential tools to:edit permission covers every file-modification tool, including edit, write, and patch operations. You do not need a separate write permission entry.
For a more restrictive initial test, require approval for every action and then allow only the operations you have reviewed:
Verify the loaded configuration
Print OpenCode’s merged configuration:hivenet-routerappears inenabled_providersmodelandsmall_modeluse thehivenet-router/prefixbaseURLends in/v1- the API-key value resolved
- the expected model IDs appear under
models
Start OpenCode
Run OpenCode from the project directory:- the Hivenet Router provider appears
- the expected models are listed
- the intended model is selected
Test a coding workflow
Begin with a read-only task:- proposes the appropriate tool call
- asks for permission when configured to do so
- invokes the file tool
- creates the expected file
- continues after receiving the tool result
Keep the configured models synchronized
Hivenet Router’s model catalog is dynamic. Models can appear or disappear as agents connect, disconnect, or change registration. OpenCode’s custom-provider model entries are configured locally and are not automatically rebuilt from Hivenet Router’s live catalog. Compare them periodically:opencode.json when:
- a model is added
- a model alias changes
- context or output limits change
- a model is retired
- the client key gains or loses access
Streaming
OpenCode uses streaming for interactive responses and tool workflows. The complete path must preserve server-sent events:- whether the backend streams Chat Completions
- whether the response uses
text/event-stream - whether the reverse proxy buffers responses
- whether proxy read and idle timeouts are long enough
- whether the agent is current
Request timeouts
Hivenet Router’s default end-to-end request timeout is:Quotas and model access
OpenCode requests use the same controls as every Hivenet Router client. The API key may be subject to:- an explicit model allowlist
- strict
quota.per_modelenumeration - request-per-minute limits
- daily token limits
- expiration
- routing and fallback policies
Restricted-egress environments
OpenCode can perform network activity unrelated to model inference, including update checks and remote model-catalog requests. On a network that permits only the Hivenet Router inference path, you can disable those two activities:- web tools
- remote MCP servers
- plugins
- language-server downloads
- external instructions or references
Observe OpenCode traffic
Give OpenCode its own Hivenet Router client key when you need separate access and attribution. For example:Troubleshooting
The Hivenet Router provider does not appear
Check the merged configuration:- the file is in a supported configuration location
- the JSON is valid
hivenet-routeris included inenabled_providers- it is not also present in
disabled_providers - the current project does not override the provider
OpenCode reports ProviderModelNotFoundError
Model references must use:
Hivenet Router returns 401 Unauthorized
Check that:
HIVENET_ROUTER_API_KEYcontains the raw client key- the variable reached the OpenCode process
- the key has not expired
- the configured
apiKeyuses the correct environment-variable name
Requests reach /v1/responses
The wrong provider adapter is configured.
Use:
Requests return a plain 404
Check the base URL.
It must end in:
Hivenet Router returns model_not_found
Compare:
- capitalization
- slashes and punctuation
- backend served-model alias
- agent registration
- client-key model access
- agent health
Text works but file or shell tools do not
The likely issue is model or backend tool-call support. Check that:- the model supports tools
- vLLM uses
--enable-auto-tool-choice - the configured parser matches the model
- the backend returns OpenAI-format
tool_calls - OpenCode permissions allow or ask for the operation
- the model follows tool schemas reliably
tools array.
A tool call appears as plain text
The backend did not convert the model output into a structured OpenAI tool call. Review:- tool-call parser
- chat template
- model family
- backend version
- streaming tool-call support
OpenCode uses an unexpected model
Inspect:- the
-mCLI flag - the model selected through
/models - project-level overrides
- agent-specific model settings
- command-specific model settings
Background requests fail
Check the configured:- be defined under the provider
- appear in Hivenet Router’s client catalog
- be permitted by the API key
- have an available
llmagent
small_model is valid when no separate lightweight model is available.
OpenCode cannot modify files
Check the permission prompt and configuration:edit permission also covers file creation and patch operations. The operation may be waiting for approval rather than failing.
Output stops or hangs during streaming
Test the same model directly with streaming curl. Check:- backend SSE output
- reverse-proxy buffering
- proxy timeout
- router request timeout
- agent logs
- OpenCode logs
A backend request is rejected with invalid_parameter
Hivenet Router now treats structured backend validation failures such as invalid parameters or context-length errors as non-retryable request failures.
It returns the error without trying every other agent serving the same model.
Inspect the backend message and correct:
- context length
- output limit
- unsupported tool fields
- unsupported roles
- model-specific parameters
Requests return 504 request_timeout
The request exceeded Hivenet Router’s deadline.
Check:
- model startup state
- prompt and requested output size
- backend queue depth
- router-side capacity queueing
- current
--request-timeout
Read the relevant logs
- OpenCode
- Router
- Agent
- Backend
Next steps
Pi
Connect another terminal coding agent through OpenAI Chat Completions.
Open WebUI
Add a browser-based chat interface backed by Hivenet Router.
Use from code
Call Hivenet Router from SDKs, scripts, and custom services.
Chat completions and messages
Review request forwarding, streaming, headers, and error behavior.
API keys
Configure model access, quotas, expiration, and rotation.
vLLM agent
Deploy and register an OpenAI-compatible inference backend.

