OpenCode Provider
OpenCode model provider configuration.
OpenCode is an open-source code model runtime that specializes in code generation, analysis, and optimization. Rensei integrates with OpenCode to enable local or self-hosted code-focused LLM inference.
Provider Summary
| Attribute | Value |
|---|---|
| Provider ID | opencode |
| Display name | OpenCode |
| Config namespace | openai (OpenAI-compatible endpoint config) |
| Supported auth modes | byok, local |
| Requires endpoint | Yes (must provide OpenCode server URL) |
| Category | Local |
A profile may include either or both modes in auth_modes. The resolver prefers byok over local. For self-hosted deployments with no API key, use auth_modes: ["local"] only. See Auth Modes.
When to Use OpenCode
Use OpenCode when you want:
- Code-specialized models - Optimized for code generation, refactoring, and analysis.
- Local or self-hosted - Run on your infrastructure; no cloud dependency.
- Privacy - All code stays on your network.
- Custom endpoints - Integrate with your own OpenCode deployment.
Prerequisites
- OpenCode runtime installed and running - See OpenCode GitHub.
- An accessible endpoint URL - e.g.,
http://localhost:8000orhttps://code.company.internal. - API key (if required by your deployment) - Some OpenCode deployments enforce authentication.
Auth Modes
Local
For OpenCode running on your local machine or internal network without authentication:
- In Settings → Model Profiles, create a profile with:
- Provider:
opencode - Auth mode:
local - Endpoint:
http://localhost:8000(adjust port as needed) - Model ID: the model name your OpenCode instance recognizes
- Provider:
- Click Test Connection - Rensei validates the endpoint.
- Click Create.
No API key required for local mode.
BYOK (Bring Your Own Key)
For OpenCode deployments that require authentication:
- In Settings → Integrations, click Add Provider and select OpenCode.
- Paste your endpoint URL and API key.
- Click Test Connection.
- In Settings → Model Profiles, create a profile with:
- Provider:
opencode - Auth mode:
byok - Select your credential from the dropdown.
- Provider:
- Click Create.
Setup
1. Start Your OpenCode Endpoint
If running locally:
opencode serve --port 8000Or connect to a remote endpoint:
https://code.company.internal:80002. Verify the Endpoint
curl http://localhost:8000/v1/modelsShould return a JSON list of available models.
3. Create a Rensei Profile
Via UI:
- Settings → Model Profiles → New Profile
- Name: e.g., "opencode-code-generation"
- Provider: OpenCode
- Auth mode: local (or byok if you have a key)
- Endpoint:
http://localhost:8000 - Model ID:
opencode(or your custom model name) - Click Test Connection
- Click Create
Via CLI:
rensei profile create \
--name "opencode-code-generation" \
--provider opencode \
--model-id "opencode" \
--auth-mode local \
--scope project \
--project-id my-project4. Dispatch
In a workflow:
nodeId: generate_code
nodeType: action/llm.inference
config:
profileId: prof_opencode_code_generation
systemPrompt: "You are an expert software engineer. Generate clean, tested code."
inputs:
- type: text
source: $trigger.descriptionOr from CLI:
rensei dispatch \
--project my-project \
--profile prof_opencode_code_generation \
"Generate a Python script that reads a CSV file and prints statistics"Configuration
OpenCode shares the openai config namespace (since it exposes an OpenAI-compatible API):
{
"providerConfig": {
"openai": {
"endpoint": "http://localhost:8000",
"temperature": 0.3,
"topP": 0.95,
"maxTokens": 2048,
"contextWindow": 4096
}
}
}Recommended settings for code generation:
| Field | Recommended | Reason |
|---|---|---|
temperature | 0.3-0.5 | Low randomness for deterministic code |
topP | 0.9-0.95 | Focused sampling for precise generation |
maxTokens | 1024-4096 | Leave room for typical code blocks |
contextWindow | Model-dependent | Use full context for large files |
Example: Local Code Generation Setup
# Pull and start OpenCode
docker run -p 8000:8000 opencode/opencode:latest
# Create a profile
rensei profile create \
--name "local-opencode" \
--provider opencode \
--model-id "opencode" \
--auth-mode local \
--scope project \
--project-id my-project
# Route code work through OpenCode
rensei routing set \
--scope project \
--project-id my-project \
--work-type development \
--profile-id prof_local_opencodeThen all development stage workflows route code generation to your local OpenCode instance.
Advanced: Self-Hosted OpenCode
For production deployments:
- Deploy OpenCode on your infrastructure (Kubernetes, Docker Compose, VM).
- Configure authentication (OAuth, API key, mutual TLS).
- Set up monitoring and logging.
- In Rensei, create a profile pointing to your endpoint.
- Use BYOK auth mode with your API key.
Example Kubernetes deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: opencode
spec:
replicas: 3
template:
spec:
containers:
- name: opencode
image: opencode/opencode:latest
ports:
- containerPort: 8000
env:
- name: OPENCODE_AUTH_TOKEN
valueFrom:
secretKeyRef:
name: opencode-secret
key: auth-tokenPerformance Tuning
OpenCode performance depends on:
- Hardware - GPU (CUDA/Metal) is 5-20× faster than CPU.
- Model size - Smaller models are faster but less capable.
- Batch size - Process multiple requests together if latency permits.
- Context window - Larger context = more memory and slower inference.
Monitor performance:
# Tail logs
curl http://localhost:8000/logs
# Check resource usage
docker stats (if containerized)For production, use a reverse proxy (nginx) to:
- Load-balance across multiple OpenCode replicas.
- Cache responses.
- Apply rate limiting.
- Handle timeouts gracefully.
Troubleshooting
"Connection refused at http://localhost:8000"
OpenCode server is not running. Start it:
opencode serve"Invalid API key" (BYOK mode)
Your key is expired or malformed. Regenerate it and update Settings → Integrations.
"Endpoint validation failed"
Endpoint URL is wrong or unreachable. Verify:
curl http://localhost:8000/v1/modelsCode generation is slow
Running on CPU. Enable GPU acceleration if available:
OPENCODE_GPU=1 opencode serveOr deploy on a machine with NVIDIA CUDA or Apple Metal support.
Model not found
The model ID doesn't match what your OpenCode instance recognizes. List available models:
curl http://localhost:8000/v1/models | jq .data[].idThen update your profile with the correct model ID.
Pricing & Cost
OpenCode incurs zero platform cost beyond your infrastructure. All compute stays on-premises.
Cost events emit for audit purposes, but show $0.00 usage.
Further Reading
- Auth Modes - Local/BYOK mode details
- Model Catalog & Routing - Profile and routing management
- Ollama Provider - Alternative local provider
- OpenCode GitHub - Official documentation and deployment guides