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:
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.
| Setting | What it does |
|---|---|
npm | @ai-sdk/openai-compatible makes OpenCode call POST /v1/chat/completions. OpenCode fetches the package itself the first time. |
options.baseURL | The 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. |
models | The models of OpenCode's picker. auto is one; any id from the Models page can be another. |
variants | The reasoning levels OpenCode offers for the model, each sent as reasoning_effort. |
model | The 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 see | What to check |
|---|---|
The Model API's models are not in /models | The config is not valid JSON, or SAMRESHUUU_API_KEY is not set in the shell that started OpenCode. Run opencode models. |
401 | The key is wrong or revoked. Check it under API keys in the console. |
404 on every request | baseURL has no /v1 at the end. |
model_not_found | The model id under models is not in the catalogue: take one from GET /v1/models. |
402 | The balance does not cover the call's hold, or the key's spend limit is reached. |
| HTTP | type | Code | message | Retry |
|---|---|---|---|---|
| 401 | authentication_error | invalid_api_key | The 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 |
| 404 | not_found_error | model_not_found | The model does not exist. GET /v1/models lists the models this API sells. | no |
| 400 | invalid_request_error | no_auto_model | No model meets the request for auto. | no |
| 402 | billing_error | insufficient_balance | The 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 |
| 402 | billing_error | key_limit_exceeded | This 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.