nearai provider, so in the common case you do not write a provider block at all: set an API key, point model at a NEAR AI model, and OpenCode handles the rest.
You only need a manual provider entry when the model you want is newer than the catalog or your OpenCode version predates the catalog’s nearai entry. Both cases use the Gateway configuration below.
Prerequisites
- OpenCode installed (verified against
1.18.31). - A NEAR AI Cloud API key from the NEAR AI Cloud Dashboard.
NEARAI_API_KEY:
/connect inside the OpenCode TUI, pick NEAR AI Cloud, and paste the key. OpenCode stores it in ~/.local/share/opencode/auth.json so you do not need the environment variable.
Base URL
The catalog already sets the gateway base URL for thenearai provider:
options.baseURL yourself in a full provider block. Do not append /chat/completions; OpenCode adds the path when it calls the API.
Model ID
OpenCode addresses a model as<provider>/<model-id>. Because NEAR AI model IDs already contain a slash, the resulting string has two:
nearai; everything after the first slash is the NEAR AI model ID.
Check Model Discovery and Refresh for the current list.
Configure
Catalog models
For any model already in the models.dev catalog, amodel line is the whole configuration. Put it in ~/.config/opencode/opencode.json for all projects, or opencode.json in a project root to override it there:
opencode.json
NEARAI_API_KEY exported, opencode starts against NEAR AI Cloud. You can also skip the config file entirely and pick the model with /models in the TUI.
z-ai/glm-5.3-flash is not in the catalog yet, so it needs the extra step in the next section. Use the check under Refresh models to see which side of the line a given model falls on.
Models newer than the catalog
The catalog lags NEAR AI Cloud releases. If/models does not list the model you want, declare it under provider.nearai.models. OpenCode merges this with the catalog entry, so you only supply what is missing:
opencode.json
tool_call and reasoning to match the model’s supported_features in /v1/models, and set limit from its context_length and max_output_length. OpenCode uses these to decide whether to offer tool use and thinking-effort variants; a model with tool support left at the default will behave as though it has none.
Full provider block
If your OpenCode version predates the catalog’snearai entry, define the provider outright:
opencode.json
Trimming the model picker
NEAR AI Cloud exposes 50+ models. OpenCode’s documentedwhitelist and blacklist options keep /models short:
opencode.json
Refresh models
OpenCode does not call NEAR AI Cloud’s/v1/models. Its picker comes from the models.dev catalog, so a newly released NEAR AI model appears only after the catalog updates.
To check whether a model is available without a manual entry:
provider.nearai.models entry until the catalog catches up. opencode models nearai shows what OpenCode currently resolves, catalog plus your config combined.
NEAR AI model IDs are aliased. Retired IDs often keep working because they resolve to their successor —
z-ai/glm-5.2 and zai-org/GLM-5.1-FP8 both route to z-ai/glm-5.3-flash today. Prefer the canonical ID from /v1/models; an alias can be repointed without notice.Quick test
Verify the key, base URL, and model against the API before debugging OpenCode:max_tokens generous on reasoning models. GLM 5.3 Flash spends its first tokens on reasoning_content, so a tight limit returns "content": null with "finish_reason": "length" and looks like a failure.
Once curl succeeds, test the same path through OpenCode:
Troubleshooting
Related guides
- Model Discovery and Refresh
- OpenAI Compatibility
- Available Models
- Goose
- Cline, Roo Code, and Kilo Code
Sources Checked
Sources checked on 2026-09-22, against OpenCode1.18.31:
- OpenCode providers
- OpenCode config
- models.dev catalog —
nearaiprovider entry - NEAR AI Cloud
GET /v1/models