OwnLLM Docs
APIIntegrations

OpenCode

Connect OpenCode (the open-source AI coding agent) to OwnLLM.

OpenCode is an open-source AI coding agent that talks any OpenAI-compatible endpoint. It pairs naturally with OwnLLM since both are OpenAI-shape.

Setup

export OPENAI_BASE_URL=https://acme-prod.ownllm.app/v1
export OPENAI_API_KEY=sk-ownllm-...

OpenCode picks those up automatically. To override per-invocation:

opencode --base-url https://acme-prod.ownllm.app/v1 \
         --api-key sk-ownllm-...

OpenCode's primary loop is plan → call tool → observe → repeat. Pick a tool-capable model:

  • qwen2.5-coder:32b — fast code-tuned model.
  • qwen3:32b with thinking: medium — better planning at higher latency.
  • llama-3.3-70b — heaviest, best for complex refactors.

For a coding agent that bursts requests, set:

ownllm models config qwen2.5-coder:32b
# keep_alive: 30m   ← keep the model warm between user prompts
# num_parallel: 4   ← OpenCode often parallelises tool calls

Tool calling

OpenCode passes tools for filesystem ops, shell commands, and HTTP. Make sure the model you pick has capabilities.tools = true — otherwise OwnLLM returns model_does_not_support_tools and OpenCode falls back to plain text completions, which breaks the agent loop.

Streaming

OpenCode uses streaming SSE by default. OwnLLM streams faithfully — you should see the response materialise token-by-token in the terminal.

Troubleshooting

Tool result truncation. Some shells buffer SSE — pipe through unbuffer or stdbuf -o0 if completions appear in big chunks.

Slow first token. The model is loading. Set keep_alive: 30m so the first call after a coffee break doesn't pay the cold-start cost.

On this page