Skip to content

OpenCode Integration

OpenCode is an open-source terminal-based (TUI/CLI) AI coding assistant that supports arbitrary OpenAI-compatible custom providers.

This guide shows you how to connect KoboiLLM to OpenCode for terminal-driven development, debugging, and automated refactoring using flagship models such as GPT-4o, Claude 3.5 Sonnet, or Gemini 2.5 Flash.


Step 1: Obtain API Key & Base URL

  1. API Key: Create a new API key under Virtual Keys in your KoboiLLM dashboard (sk-xxxx). Ensure All Team Models is selected.
  2. Base URL: Point to KoboiLLM’s standard OpenAI-compatible gateway:
    https://api.koboillm.com/v1

Step 2: Configure opencode.json

OpenCode manages custom provider definitions via a JSON configuration file. You can configure this globally or per-project.

Configuration File Locations

  • Global (All Projects):
    • Linux / macOS: ~/.config/opencode/opencode.json
    • Windows: %USERPROFILE%\.config\opencode\opencode.json
  • Per-Project:
    • Create opencode.json in your project root directory.

Example Configuration

Create or edit your opencode.json file to include the KoboiLLM provider setup:

{
"$schema": "https://opencode.ai/config.json",
"provider": {
"koboillm": {
"npm": "@ai-sdk/openai-compatible",
"name": "KoboiLLM",
"options": {
"baseURL": "https://api.koboillm.com/v1",
"apiKey": "{env:KOBOILLM_API_KEY}"
},
"models": {
"anthropic/claude-3-5-sonnet": {
"name": "Claude 3.5 Sonnet",
"limit": {
"context": 200000,
"output": 8192
}
},
"openai/gpt-4o": {
"name": "GPT-4o",
"limit": {
"context": 128000,
"output": 16384
}
}
}
}
}
}

Step 3: Export API Key & Run OpenCode

Export your KoboiLLM API key in your terminal session:

Terminal window
export KOBOILLM_API_KEY="sk-xxxx"
opencode --provider koboillm