Skip to main content
OpenCode is a terminal coding agent that resolves its providers from the public models.dev catalog. NEAR AI Cloud is already in that catalog as the 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

Store the key in the environment variable the catalog declares for this provider, NEARAI_API_KEY:
Alternatively, run /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.
Do not paste a literal key into opencode.json. Config files are frequently committed to source control. Use NEARAI_API_KEY, /connect, or the {env:NEARAI_API_KEY} substitution syntax shown below.

Base URL

The catalog already sets the gateway base URL for the nearai provider:
You only set 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:
This is expected. The provider is 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, a model 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
With 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
Set 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’s nearai entry, define the provider outright:
opencode.json

Trimming the model picker

NEAR AI Cloud exposes 50+ models. OpenCode’s documented whitelist 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:
Compare that against the live list:
Anything present in the second list but not the first needs a manual 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:
Keep 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

Sources Checked

Sources checked on 2026-09-22, against OpenCode 1.18.31: