OpenCode

OpenCode takes any provider that speaks OpenAI Chat Completions, so the Model API is one entry in opencode.json. Nothing to install besides OpenCode itself. The model is auto, which picks a model of the catalogue for the conversation.

Requirements: OpenCode (opencode --version shows the version), a Model API key and money on the organization balance.

1. Create a key

In the developer console, open API keys, keep Model API key in the Access field and create the key. The secret is shown once. Put it into your shell profile (~/.zshrc, ~/.bashrc) so OpenCode can read it:

bash
export SAMRESHUUU_API_KEY="sk-org-your_api_key"

2. Add the provider

OpenCode's global config is ~/.config/opencode/opencode.json; an opencode.json at the root of a project applies to that project only. Create the file if there is none, or add the provider entry to the one you have.

json
{ "$schema": "https://opencode.ai/config.json", "provider": { "samreshuuu": { "npm": "@ai-sdk/openai-compatible", "name": "Samreshuuu", "options": { "baseURL": "https://api.samreshuuu.ru/v1", "apiKey": "{env:SAMRESHUUU_API_KEY}" }, "models": { "auto": { "name": "auto", "variants": { "low": { "reasoningEffort": "low" }, "medium": { "reasoningEffort": "medium" }, "high": { "reasoningEffort": "high" } } } } } }, "model": "samreshuuu/auto" }
SettingWhat it does
npm@ai-sdk/openai-compatible makes OpenCode call POST /v1/chat/completions. OpenCode fetches the package itself the first time.
options.baseURLThe Model API's address. Keep /v1 at the end.
options.apiKey{env:SAMRESHUUU_API_KEY} reads the key from the environment, so it never sits in the file.
modelsThe models of OpenCode's picker. auto is one; any id from the Models page can be another.
variantsThe reasoning levels OpenCode offers for the model, each sent as reasoning_effort.
modelThe model new sessions start on, as samreshuuu/<id>.

OpenCode does not know the window of auto and plans its compaction for a default one. If you add a model of the catalogue with a smaller window, give it "limit": {"context": …, "output": …} from context_length and max_output_tokens in GET /v1/models.

3. Start OpenCode

Run opencode and pick the model with /models: the Model API's models read samreshuuu/<id>. To check the setup without a session, opencode models lists the models OpenCode knows, samreshuuu/auto among them.

Send a prompt. The call shows up in the call log of the console with the model auto picked and its cost. Tools work as OpenAI functions: OpenCode runs them, the model calls them.

Undo the setup

Remove the samreshuuu entry from provider, and the model line if it points at it. OpenCode then goes back to your other providers.

Troubleshooting

What you seeWhat to check
The Model API's models are not in /modelsThe config is not valid JSON, or SAMRESHUUU_API_KEY is not set in the shell that started OpenCode. Run opencode models.
401The key is wrong or revoked. Check it under API keys in the console.
404 on every requestbaseURL has no /v1 at the end.
model_not_foundThe model id under models is not in the catalogue: take one from GET /v1/models.
402The balance does not cover the call's hold, or the key's spend limit is reached.
HTTPtypeCodemessageRetry
401authentication_errorinvalid_api_keyThe API key is unknown, disabled, revoked or expired. Switch a disabled key back on in the developer console; create a new one in place of a revoked or expired key.no
404not_found_errormodel_not_foundThe model does not exist. GET /v1/models lists the models this API sells.no
400invalid_request_errorno_auto_modelNo model meets the request for auto.no
402billing_errorinsufficient_balanceThe organization balance does not cover this request (max_tokens is held in full until the answer is settled). Top up the balance or lower max_tokens.no
402billing_errorkey_limit_exceededThis API key has reached its spending limit. Raise the limit or use another key.no

If an error persists, write to support with the x-request-id of the answer.

Frequently asked questions

Does OpenCode load the list of models from the API?

No. OpenCode offers the models listed under models in opencode.json and asks no GET /v1/models for a custom provider. auto is enough: it picks a model of the catalogue for the conversation. Add more ids from the Models page if you want them in the picker.

Can OpenCode use the Responses API instead?

Yes: with npm set to @ai-sdk/openai, OpenCode calls POST /v1/responses, which the Model API serves as well. Chat Completions is the Model API's main wire, so the page uses @ai-sdk/openai-compatible.

Was this page helpful?