Connect OpenCode to OpenLLM Buddy

This guide shows how to use OpenCode with your OpenAI-compatible OpenLLM Buddy endpoint and model gemma4:26b.

Integration guide

What is OpenCode?

OpenCode is an open-source AI coding agent for your terminal, IDE, or desktop. It supports many providers — including any OpenAI-compatible API — so you can point it at your own hosted models.

Why connect OpenLLM Buddy?

OpenLLM Buddy serves /v1/chat/completions on dedicated GPU instances. OpenCode can use @ai-sdk/openai-compatible with a custom base URL — perfect for our proxy endpoint.

How this guide is structured

  • Install — official installer from opencode.ai
  • /connect — add provider openllmbuddy + API key
  • config.json — set baseURL and models
  • Optional — environment variables
  • /models — pick your model in the TUI
  • curl test — verify the endpoint before debugging OpenCode

Tip: run the curl test in Step 6 before OpenCode if anything fails — OpenCode cannot fix a broken endpoint. Get your API key from the console.

1

Install OpenCode

Install OpenCode using the official script from opencode.ai. Run this in your terminal (macOS or Linux).

Terminal
bash
curl -fsSL https://opencode.ai/install | bash

After install, launch the TUI with opencode to connect your provider.

2

Connect your custom provider

The easiest way to add OpenLLM Buddy is the /connect command inside OpenCode.

Launch OpenCode
bash
opencode
In the TUI
bash
# Inside the OpenCode TUI:
/connect
# Scroll to "Other" → enter your provider ID → paste your API key
  1. Run opencode in your project directory.
  2. Type /connect.
  3. Scroll to Other.
  4. Enter a unique provider ID (example: openllmbuddy).
  5. Paste your OpenLLM Buddy API key when prompted.

After connecting, set the base URL in config.json (next step) — /connect stores the key; the config file wires the endpoint and model list.

3

Configure base URL in config.json

Edit your OpenCode config at ~/.config/opencode/config.json (or opencode.json in your project). Use the same provider ID you chose in /connect (example: openllmbuddy).

config.json
json
{
  "provider": {
    "openllmbuddy": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://openllmbuddy-proxy.botbuddytech.workers.dev/v1"
      },
      "models": {
        "gemma4:26b": {}
      }
    }
  }
}

Use @ai-sdk/openai-compatible for providers that expose /v1/chat/completions (like OpenLLM Buddy). If your provider uses /v1/responses instead, use @ai-sdk/openai.

Set baseURL to your /v1 root (HTTPS). Add each model id you want under models as an empty object ({}).

4

Use environment variables (optional)

For a quick setup without editing JSON, export these two variables before running OpenCode:

Shell
bash
export OPENAI_API_KEY=YOUR_API_KEY
export OPENAI_BASE_URL=https://openllmbuddy-proxy.botbuddytech.workers.dev/v1

Replace the placeholder with your real API key from the console. You may still need config.json for custom provider IDs and multiple models — env vars are the fastest path for a single OpenAI-compatible endpoint.

5

Select your model

Inside the OpenCode TUI, run /models to pick which model to use for this session.

In the TUI
text
/models

Your custom provider and configured models should appear in the list. For this guide, choose gemma4:26b (or the matching entry under your provider id).

Examples: Gemma 4 26B → gemma4:26b, Qwen 3.6 27B → qwen3.6:27b

6

Test with curl (recommended)

Recommended: verify your endpoint with curl before relying on OpenCode. If this request fails, OpenCode will not fix it for you.

Terminal
bash
curl https://openllmbuddy-proxy.botbuddytech.workers.dev/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gemma4:26b", "messages": [{"role": "user", "content": "Reply with OK"}]}'

You should get a JSON response with an assistant message (e.g. "OK"). Use your API key from the console. If you see 401/404, fix base URL, key, or model id before continuing with OpenCode.