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
- 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.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_* 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
- 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
The Hivenet Router provider does not appear
- 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`
OpenCode reports `ProviderModelNotFoundError`
Requests reach `/v1/responses`
Requests reach `/v1/responses`
Requests return a plain `404`
Requests return a plain `404`
Hivenet Router returns `model_not_found`
Hivenet Router returns `model_not_found`
- 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
Text works but file or shell tools do not
- 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
A tool call appears as plain text
- tool-call parser
- chat template
- model family
- backend version
- streaming tool-call support
OpenCode uses an unexpected model
OpenCode uses an unexpected model
- the
-mCLI flag - the model selected through
/models - project-level overrides
- agent-specific model settings
- command-specific model settings
Background requests fail
Background requests fail
- 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
OpenCode cannot modify files
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
Output stops or hangs during streaming
- backend SSE output
- reverse-proxy buffering
- proxy timeout
- router request timeout
- agent logs
- OpenCode logs
A backend request is rejected with `invalid_parameter`
A backend request is rejected with `invalid_parameter`
- context length
- output limit
- unsupported tool fields
- unsupported roles
- model-specific parameters
Requests return `504 request_timeout`
Requests return `504 request_timeout`
- 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

