---
title: "opencode custom OpenAI-compatible provider setup | BroadRouter"
description: "Add BroadNet Inference to the opencode coding agent as a custom OpenAI-compatible provider in opencode.jsonc, with model aliases, capabilities and limits."
url: https://broadrouter.com/guides/opencode-custom-provider/
lang: en
updated: 2026-11-16
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# Add BroadNet Inference to opencode as a custom provider

Updated 2026-11-16

In opencode.jsonc, add a broadnet entry under providers with package @opencode/ai/providers/openai-compatible, settings.baseURL set to https://inference.broadnet.ai/v1 and env set to BROADNET\_API\_KEY. Map short model keys to BroadNet IDs with modelID, such as broadnet/glm-5.3, then pick the model with /models. Older V1 configs using npm @ai-sdk/openai-compatible and options.baseURL still work.

opencode is an open-source coding agent for the terminal. Providers that aren’t in its built-in catalog are added as **custom providers** in `opencode.jsonc`. BroadNet Inference speaks the OpenAI chat-completions format, so it uses opencode’s OpenAI-compatible runtime package. This guide follows the current (V2) opencode docs.

## Setup

1.  **Export your key** in the shell that starts opencode:

```bash
export BROADNET_API_KEY='your-broadnet-key'
```

2.  **Create the config.** Put it in your project as `opencode.jsonc`, or in `~/.config/opencode/opencode.jsonc` to use it everywhere.

```jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "model": "broadnet/glm-5.3",
  "providers": {
    "broadnet": {
      "name": "BroadNet Inference",
      "env": ["BROADNET_API_KEY"],
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": {
        "baseURL": "https://inference.broadnet.ai/v1"
      },
      "models": {
        "glm-5.3": {
          "modelID": "broadnet/glm-5.3",
          "name": "GLM 5.3",
          "capabilities": { "tools": true, "input": ["text"], "output": ["text"] },
          "limit": { "context": 1048576, "output": 16000 }
        },
        "deepseek-v4.1-flash": {
          "modelID": "broadnet/deepseek-v4.1-flash",
          "name": "DeepSeek V4.1 Flash",
          // BroadNet's docs don't list tool calling for this model: test it first
          "capabilities": { "tools": true, "input": ["text", "image"], "output": ["text"] },
          "limit": { "context": 1048576, "output": 16000 }
        },
        "qwen3.8-27b": {
          "modelID": "broadnet/qwen3.8-27b",
          "name": "Qwen3.8 27B",
          "capabilities": { "tools": true, "input": ["text", "image"], "output": ["text"] },
          "limit": { "context": 262144, "output": 16000 }
        }
      }
    }
  }
}
```

3.  **Start opencode and pick the model** with `/models`. The reference is `broadnet/<map key>`, for example `broadnet/glm-5.3`. opencode sends the `modelID` value to BroadNet.

Config files merge. opencode applies the global file first, then project files found from the current directory upward (farthest first), then any `.opencode/` config, so a project file can override the global provider. Managed system config, if your company uses it, overrides both. Keep the key in the environment, not in the file, so the config can go into version control.

## Why the aliases

BroadNet IDs already contain a slash (`broadnet/glm-5.3`). The `models` map key is what opencode shows and selects, and `modelID` is what it sends. Short keys keep references readable.

Set `capabilities` and `limit` yourself. For a model outside its catalog, opencode assumes JSON tool support, text and image input, a 200,000-token context and 32,000 output tokens. Its docs call these fallback assumptions, not detected values. The `output` value of 16000 above is our suggestion, not a BroadNet limit; it leaves room for reasoning.

### Older V1 configs

opencode V2 still reads the V1 format, so an existing block like this keeps working:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "broadnet": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "BroadNet Inference",
      "options": {
        "baseURL": "https://inference.broadnet.ai/v1",
        "apiKey": "{env:BROADNET_API_KEY}"
      },
      "models": {
        "broadnet/glm-5.3": { "name": "GLM 5.3" }
      }
    }
  }
}
```

In the native V2 form, `provider` becomes `providers`, `npm` becomes `package` (`aisdk:@ai-sdk/openai-compatible` if you want to keep the AI SDK package), and `options.baseURL` and `options.apiKey` move under `settings`. The [opencode V1 migration guide](https://opencode.ai/docs/migrate-v1/) maps each field.

## Which model to pick

| Task | Model | Notes |
| --- | --- | --- |
| Agent coding with tools | [GLM 5.3](https://broadrouter.com/models/glm-5.3/) | Tools and structured output listed; 1M context |
| Screenshots, Arabic | [Qwen3.8 27B](https://broadrouter.com/models/qwen3.8-27b/) | Tools and images; 262K context |
| All-day sessions, flat price | [DeepSeek V4.1 Flash](https://broadrouter.com/models/deepseek-v4.1-flash/) | Unlimited plans; tools not listed by BroadNet |

opencode relies on tool calls. BroadNet’s docs don’t list tool calling for DeepSeek V4.1 Flash, so the config marks it as an assumption to test. Run a real task on a Meteor hour ($1) before you buy a Full Moon month ($60).

## Troubleshooting

-   **401.** The key in `BROADNET_API_KEY` is wrong, expired, or out of pay-as-you-go allowance. Make sure the variable is set in the process that runs opencode.
-   **Model not found or rejected.** Select the map key (`broadnet/glm-5.3`), and check that `modelID` matches BroadNet’s ID exactly. References are case-sensitive. Paid models need a top-up; the $5 credit covers only `broadnet/gemma-4-26b-a4b` and the two Transcribe models.
-   **Empty answers.** Raise `limit.output`. [Why answers come back empty](https://broadrouter.com/guides/reasoning-tokens-empty-response/).
-   **429.** Pay-as-you-go keys allow 30 requests a minute and 4 in flight. Retries count too. See [errors and retries](https://broadrouter.com/guides/errors-and-retries/).
-   **Subagents on a plan.** Each [plan session](https://broadrouter.com/guides/unlimited-llm-api-sessions/) handles one request at a time, so parallel subagents queue unless each has its own session.

## Terms in this guide

[Tool calling](https://broadrouter.com/glossary/tool-calling/)

Tool calling, also called function calling, is an LLM API feature in which the model returns a structured request to run a function the developer has defined, with JSON arguments. The application runs the function and sends the result back; the model never runs code itself.

[Pay-as-you-go](https://broadrouter.com/glossary/pay-as-you-go/)

Pay-as-you-go is a pricing model in which you pay only for what you use, metered per unit such as tokens, requests or audio minutes, with no subscription or minimum commitment. Most LLM APIs bill this way, from a prepaid balance or a periodic invoice.

[Subagent](https://broadrouter.com/glossary/subagent/)

A subagent is a separate agent that a main agent starts to handle one focused task. It runs with its own context window, system prompt and tool access, does the work, and returns only a result or summary to the main agent, which keeps the main conversation small.

[Token](https://broadrouter.com/glossary/token/)

A token is the unit of text a language model reads and writes: a word, part of a word, a punctuation mark or a byte sequence produced by the model's tokenizer. LLM APIs count, limit and usually bill usage in tokens.

[AI coding agent](https://broadrouter.com/glossary/coding-agent/)

An AI coding agent is a software tool in which a language model works on a codebase in a loop: it reads files, edits them, runs commands such as tests, reads the output and decides the next step until the task is done or a limit is reached.

[Concurrency](https://broadrouter.com/glossary/concurrency/)

Concurrency is the number of requests a client has in flight at the same time. LLM APIs often cap it per key or plan, separately from requests per minute, because each open request holds GPU capacity until its response has finished.

[Input and output tokens](https://broadrouter.com/glossary/input-and-output-tokens/)

Input tokens are the tokens a language model reads in a request, including the system prompt, conversation history, tool definitions and images. Output tokens are the tokens it generates in reply, including any reasoning. LLM APIs usually price them separately, and output usually costs more.

[Prepaid credit](https://broadrouter.com/glossary/prepaid-credit/)

Prepaid credit is money added to an API account before use. Each request deducts its cost from the balance, and when the balance runs out, metered requests stop until you top up. It caps spend at what you have paid in.

## Questions

### Why can't opencode find my BroadNet model?

opencode resolves the reference as provider/map key, and IDs are case-sensitive. With the config below, select broadnet/glm-5.3, where glm-5.3 is the map key. The modelID value is only what gets sent to BroadNet.

### My config uses provider and npm with @ai-sdk/openai-compatible. Is that wrong?

No. That is the V1 format, and opencode's migration guide says it remains supported. The native V2 form renames provider to providers, npm to package (aisdk:@ai-sdk/openai-compatible) and options.baseURL to settings.baseURL.

### Why are opencode replies empty?

The model spent its output budget on reasoning. Raise limit.output for the model. Reasoning counts toward max\_tokens on BroadNet.

## Related guides

-   [Use Cline with BroadNet Inference (OpenAI Compatible provider)](https://broadrouter.com/guides/cline-openai-compatible/)
-   [How the unlimited LLM API plans work for agents](https://broadrouter.com/guides/unlimited-llm-api-sessions/)
-   [Why a reasoning model returns an empty answer](https://broadrouter.com/guides/reasoning-tokens-empty-response/)
-   [Use the Vercel AI SDK with BroadNet Inference](https://broadrouter.com/guides/vercel-ai-sdk-openai-compatible/)
-   [All tools that work with BroadNet Inference](https://broadrouter.com/integrations/): SDKs, coding agents, chat UIs and automation tools, with exact settings for each

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-opencode-custom-provider&utm_content=page-cta) ·

**Sources**

-   [opencode docs, Providers (custom provider) (checked 2026-11-14)](https://opencode.ai/docs/providers/)
-   [opencode docs, Models (aliases, capabilities, limits) (checked 2026-11-14)](https://opencode.ai/docs/models/)
-   [opencode docs, Config locations (checked 2026-11-14)](https://opencode.ai/docs/config/)
-   [opencode docs, Migrate from V1 (checked 2026-11-14)](https://opencode.ai/docs/migrate-v1/)
-   [BroadNet Inference API reference](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-opencode-custom-provider&utm_content=sources)
