Rensei docs
Providers

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

AttributeValue
Provider IDopencode
Display nameOpenCode
Config namespaceopenai (OpenAI-compatible endpoint config)
Supported auth modesbyok, local
Requires endpointYes (must provide OpenCode server URL)
CategoryLocal

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

  1. OpenCode runtime installed and running - See OpenCode GitHub.
  2. An accessible endpoint URL - e.g., http://localhost:8000 or https://code.company.internal.
  3. 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:

  1. 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
  2. Click Test Connection - Rensei validates the endpoint.
  3. Click Create.

No API key required for local mode.

BYOK (Bring Your Own Key)

For OpenCode deployments that require authentication:

  1. In Settings → Integrations, click Add Provider and select OpenCode.
  2. Paste your endpoint URL and API key.
  3. Click Test Connection.
  4. In Settings → Model Profiles, create a profile with:
    • Provider: opencode
    • Auth mode: byok
    • Select your credential from the dropdown.
  5. Click Create.

Setup

1. Start Your OpenCode Endpoint

If running locally:

opencode serve --port 8000

Or connect to a remote endpoint:

https://code.company.internal:8000

2. Verify the Endpoint

curl http://localhost:8000/v1/models

Should return a JSON list of available models.

3. Create a Rensei Profile

Via UI:

  1. Settings → Model Profiles → New Profile
  2. Name: e.g., "opencode-code-generation"
  3. Provider: OpenCode
  4. Auth mode: local (or byok if you have a key)
  5. Endpoint: http://localhost:8000
  6. Model ID: opencode (or your custom model name)
  7. Click Test Connection
  8. Click Create

Via CLI:

rensei profile create \
  --name "opencode-code-generation" \
  --provider opencode \
  --model-id "opencode" \
  --auth-mode local \
  --scope project \
  --project-id my-project

4. 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.description

Or 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:

FieldRecommendedReason
temperature0.3-0.5Low randomness for deterministic code
topP0.9-0.95Focused sampling for precise generation
maxTokens1024-4096Leave room for typical code blocks
contextWindowModel-dependentUse 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_opencode

Then all development stage workflows route code generation to your local OpenCode instance.

Advanced: Self-Hosted OpenCode

For production deployments:

  1. Deploy OpenCode on your infrastructure (Kubernetes, Docker Compose, VM).
  2. Configure authentication (OAuth, API key, mutual TLS).
  3. Set up monitoring and logging.
  4. In Rensei, create a profile pointing to your endpoint.
  5. 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-token

Performance 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/models

Code generation is slow

Running on CPU. Enable GPU acceleration if available:

OPENCODE_GPU=1 opencode serve

Or 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[].id

Then 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

On this page