Skip to content

Connect OpenCode

Overview

OpenCode is a terminal-based AI coding assistant that supports custom OpenAI-compatible API endpoints via a configuration file. Wuliang Open AI provides a fully OpenAI-compatible API that works as a drop-in backend for OpenCode.

Prerequisites

  • OpenCode installed (npm install -g opencode-ai or see official docs)
  • An API Key created on the Wuliang Open AI platform

Configuration Steps

1. Edit opencode.json

Locate and edit the following file for your operating system (create it if it doesn't exist):

OSFile Path
macOS / Linux~/.config/opencode/opencode.json
Windows%APPDATA%\opencode\opencode.json

Write the following content, replacing your-api-key with your Wuliang Open AI API Key:

json
{
  "models": {
    "gpt-5.5": {
      "name": "GPT-5.5"
    }
  },
  "npm": "@ai-sdk/openai-compatible",
  "options": {
    "apiKey": "your-api-key",
    "baseURL": "https://open.dieyuyun.com/v1"
  }
}
FieldDescription
modelsAvailable model definitions, keys are model codes
npmFixed value @ai-sdk/openai-compatible
options.apiKeyYour Wuliang Open AI API Key
options.baseURLWuliang Open AI OpenAI-compatible base URL

2. Launch OpenCode

After saving the config file, run:

bash
opencode

Type /models inside the session to view and switch between available models.

OpenCode switch models successfully

OpenCode launched successfully

API Endpoint Reference

Wuliang Open AI OpenAI-compatible endpoint details:

FieldValue
Base URLhttps://open.dieyuyun.com/v1
Auth HeaderAuthorization: Bearer your-api-key
FormatJSON

Example request:

bash
curl --request POST 'https://open.dieyuyun.com/v1/chat/completions' \
  --header 'Authorization: Bearer your-api-key' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-5.5",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Introduce yourself."}
    ],
    "temperature": 0.7,
    "max_tokens": 1024
  }'

Notes

  • JSON Validity: Ensure the config file is valid JSON.
  • Model IDs: The models[].id field must exactly match the model codes listed on the Models & Pricing page.
  • API Key Security: Avoid committing opencode.json to version control if it contains your API Key. Consider passing the key via the OPENAI_API_KEY environment variable instead.