Skip to content
← All articles

Published November 14, 2026 · 7 min read

OpenCode Custom Provider Setup (opencode.json) and Fixing 'Provider Not Loading'

Add zrouter to OpenCode as a custom OpenAI-compatible provider with opencode.json, reference models correctly, and fix the common reasons a custom provider does not load or a model is not found.


OpenCode can use any OpenAI-compatible endpoint, which makes it easy to run it against zrouter and pay one balance for many models. Most of the trouble people hit comes down to a few details in opencode.json: where the file lives, how the provider block is shaped, and how the model is referenced.

This guide gives a config that works, then a troubleshooting checklist for "my custom provider is not loading".

Step 1: store the key

In the OpenCode terminal UI, run /connect, scroll to Other, and enter a provider ID such as zrouter. Then paste your zrouter API key (it starts with zr_). OpenCode's providers documentation notes that this only stores a credential; you still have to describe the provider in opencode.json.

Step 2: describe the provider

Create or edit opencode.json in your project directory. This is the shape used by the v1 configuration format:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "zrouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "zrouter",
      "options": {
        "baseURL": "https://api.zrouter.dev/v1"
      },
      "models": {
        "deepseek-v4.1-flash": { "name": "DeepSeek V4.1 Flash" },
        "glm-5.3-flash": { "name": "GLM 5.3 Flash" }
      }
    }
  }
}

What each field does, according to the OpenCode docs:

  • zrouter (the key under provider) is the provider ID. It must match the ID you gave in /connect.
  • npm is the AI SDK package. @ai-sdk/openai-compatible is for providers that speak /v1/chat/completions. If a model should use /v1/responses, use @ai-sdk/openai instead.
  • options.baseURL is the endpoint. For zrouter it is https://api.zrouter.dev/v1, with /v1.
  • models lists the models to show. Use the zrouter model names exactly as they appear in the catalog.

Run /models and the zrouter models appear in the list. Select one and start working.

If you use the newer config format

The latest OpenCode documentation describes a newer layout: a providers object (plural), package and env fields, and settings.baseURL instead of options.baseURL. The same provider looks like this there:

{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "zrouter": {
      "name": "zrouter",
      "env": ["ZROUTER_API_KEY"],
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": { "baseURL": "https://api.zrouter.dev/v1" },
      "models": {
        "deepseek-v4.1-flash": { "name": "DeepSeek V4.1 Flash" }
      }
    }
  }
}

Which format applies depends on your OpenCode version. Check the docs page that matches the version you run. Mixing the two layouts is one of the most common reasons a provider never loads.

Referencing the model

Models are referenced as <providerId>/<modelId>. With the provider above, that is zrouter/deepseek-v4.1-flash. The troubleshooting page lists ProviderModelNotFoundError as the typical symptom of a wrong reference and suggests running opencode models to see exactly which models you can use.

Checklist: the provider does not load

Work through these in order:

  1. Valid JSON. A trailing comma or a missing brace in opencode.json stops the whole file from loading. Use .jsonc if you want comments and trailing commas.
  2. Right file, right place. Keep the config where OpenCode looks for it, such as the project directory or your user config folder, and check you are editing the file that is actually being read.
  3. Right layout for your version. provider with npm and options belongs to the v1 format; providers with package and settings belongs to the newer one. Do not mix them.
  4. Provider ID matches. The ID in /connect and the key under provider must be identical.
  5. Models are declared. A provider with an empty or missing models map shows nothing in /models.
  6. Credential stored. Run /connect again, or set options.apiKey, or the environment variable named in env. A 401 invalid_api_key from the gateway means the key is wrong or revoked.
  7. Corrupted state. The OpenCode troubleshooting page says a ProviderInitError usually points to an invalid or corrupted configuration, and suggests clearing the stored data in ~/.local/share/opencode (on Windows %USERPROFILE%\.local\share\opencode) and authenticating again.
  8. Stale provider package. OpenCode installs provider packages on demand and caches them. For AI_APICallError problems, the troubleshooting page suggests deleting the cache folder ~/.cache/opencode (on Windows %USERPROFILE%\.cache\opencode) and restarting OpenCode so it reinstalls the latest packages.

Test the endpoint without OpenCode

If the provider still misbehaves, take OpenCode out of the loop and call the endpoint directly:

curl https://api.zrouter.dev/v1/chat/completions \
  -H "Authorization: Bearer $ZROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"deepseek-v4.1-flash","messages":[{"role":"user","content":"Hello"}],"max_tokens":512}'

A 200 means the key, the model name and the base URL are right, and the problem is in the OpenCode config. A 402 means no Token Plan or balance is left. A 404 model_not_found means the model name is wrong or the model is hidden.

What it costs

At the time of writing, deepseek-v4.1-flash is $0.015 per 1M input tokens and $0.06 per 1M output tokens, and glm-5.3-flash is $0.015 and $0.05, both 90% below the official price. Plans start at $1. Token Plans are used before the pay-as-you-go balance, and the balance does not expire. Always check the pricing page for current numbers.

You can top up with QRIS, USDT or USDC without a credit card. For USDT and USDC the sender pays the blockchain network fee; QRIS checkouts may include a small service fee that is shown before you pay.

Ready? Browse the models and read the API docs.