OpenCode access

Configure the site address, independent keys and available models in OpenCode.

OpenCode can connect to this site through custom providers. This article distinguishes between 2.x and 1.x configurations; the field structures of the two are different. You should confirm the version first and then merge the corresponding configurations.

Preparation before starting

Create a standalone key in API Key and press Quick Start to verify that the model supports Chat Completions. Coding tasks also require model support tool calls.

Install the client suitable for the current platform from OpenCode official portal. Run opencode --version on the CLI, and check the version on the desktop in the About page of settings. Back up the current configuration before editing.

Step 1: Find the configuration file

User-level configuration is located at .config/opencode/opencode.json or .config/opencode/opencode.jsonc in the user directory; project-level configuration is usually opencode.json in the project. For specific loading rules, see Official Configuration Instructions.

Prioritize placing personal provider configurations in user-level files to avoid submitting them to the project. Existing configurations should be merged with corresponding objects, retaining other vendors, permissions, and project settings.

Step 2: Configure the corresponding version

OpenCode 2.x

Merge the following into the configuration file, replacing MODEL_ID with the exact model ID available for the current key:

{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "dundun": {
      "name": "DunDun",
      "env": [
        "DUNDUN_API_KEY"
      ],
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": {
        "baseURL": "https://dunduntoken.com/v1"
      },
      "models": {
        "MODEL_ID": {
          "name": "DunDun model"
        }
      }
    }
  }
}

The configuration reads credentials from the DUNDUN_API_KEY environment variable of the running process. Hide input and start in Bash/zsh:

printf 'API Key: '
read -rs DUNDUN_API_KEY
printf '\n'
export DUNDUN_API_KEY
opencode

PowerShell:

$credential = Get-Credential -UserName "api" -Message "在密码栏填写本站 API Key"
$env:DUNDUN_API_KEY = $credential.GetNetworkCredential().Password
Remove-Variable credential
opencode

OpenCode 1.x

Run /connect in OpenCode, select Other, fill in dundun as the supplier ID, and enter the site key as prompted. Then merge the following configuration:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "dundun": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "DunDun",
      "options": {
        "baseURL": "https://dunduntoken.com/v1"
      },
      "models": {
        "MODEL_ID": {
          "name": "DunDun model"
        }
      }
    }
  }
}

The vendor ID must be the same as /connect when the key was saved. Do not mix 1.x provider/npm/options and 2.x providers/package/settings. The old version of the field is based on OpenCode 1.x official description.

Step 3: Select the model and verify it

  1. Save the configuration and completely restart OpenCode or the corresponding service process.
  2. Open the model selector; interfaces that support slash commands can also run /models.
  3. Select the actual model under DunDun and send “Reply only OK”.
  4. Go to Call Record on this site to confirm the time, model, status and usage.
  5. In the test project, read the README and explain the directory structure, confirm the tool call, and then try the actual coding task.

When adding multiple models, add the actual model IDs in the models object respectively. The context, output length, and image capabilities are configured according to the actual support of the model. Do not directly copy the capability statements of other models.

Desktop and remote environment

The desktop may not inherit terminal variables. When using the 2.x environment variable method, DUNDUN_API_KEY should be provided for the actual service process on the desktop. After saving, exit completely and reopen. WSL, remote hosts and containers should check their configuration files and credential sources respectively.

FAQ

Phenomenon Priority Check
DunDun does not appear Configuration location, JSON syntax and field structure used in the current version
Supplier appears but no model Model ID in models, has the service been restarted
401 Whether the supplier ID matches the credential source, and whether the service process reads the key
404 Base URL up to /v1, check the actual request protocol
Can chat but cannot read files or codes Tool calling capabilities, context, and parameters emitted by the client

Continue reading

Tool call · CC-Switch · Error troubleshooting

Configuration based on: OpenCode Current Vendor Description.