OpenCode
![]()
Use OpenModels as a custom OpenAI-compatible provider for OpenCode. OpenCode keeps its terminal UI, CLI, agents, tools, permissions, and project configuration. OpenModels provides the model endpoint, API key, model IDs, and credit-based billing.
This guide focuses on OpenCode calling OpenModels through https://api.getopenmodels.com/v1.
When to use this
Use this setup when you want:
- OpenCode as an AI coding agent for a local repository.
- OpenModels as the upstream model marketplace.
- One
ale-...OpenModels API key for OpenCode model calls. - OpenAI-compatible chat completions through
@ai-sdk/openai-compatible. - Project-level config you can commit without committing secrets.
Prerequisites
- OpenCode installed on the machine where you will work.
- An OpenModels API key in the
ale-...format. - Available credits in your OpenModels account.
- A supported OpenModels chat or coding model ID, such as
qwen3.5-flashorkimi-k2.7-code.
1. Install OpenCode
Install OpenCode with the official install script:
Other supported install paths include npm, Bun, pnpm, Yarn, Homebrew, Arch Linux packages, Chocolatey, Scoop, Docker, and release binaries.
2. Add the OpenModels credential
The most direct way is to use OpenCode’s /connect flow and choose Other:
Use this provider ID:
Then paste your OpenModels API key:
OpenCode stores credentials in its auth store, not in opencode.json.
For headless or project-local setups, you can also use an environment variable:
Do not commit real ale-... keys to an application repository.
3. Configure OpenModels as a provider
Create or update opencode.json in the project root:
If you are using OM_API_KEY instead of /connect, add apiKey under options:
Notes:
openmodelsis the provider ID. It must match the ID used in/connect.npm: "@ai-sdk/openai-compatible"tells OpenCode to use the OpenAI-compatible chat completions adapter.modeluses theprovider_id/model_idformat.small_modelis used for cheaper lightweight tasks, such as title generation.limit.contextandlimit.outputhelp OpenCode understand available context. Check the OpenModels Models page before updating these values.
4. Start OpenCode
Run OpenCode from your project directory:
If this is a new project, initialize project instructions:
Then verify the selected model:
Choose openmodels/kimi-k2.7-code or another OpenModels model from your config.
5. Use OpenModels model IDs
The model IDs in opencode.json must match OpenModels model IDs.
Good starting points:
For production-like usage, check pricing, context, routes, supply, and live status in the Models page before relying on a model.
6. Keep secrets out of project config
Project-level opencode.json can be committed when it only contains provider config, model IDs, and limits. Do not commit API keys.
Use one of these instead:
/connect, which stores credentials in OpenCode’s auth store.options.apiKey: "{env:OM_API_KEY}", withOM_API_KEYset outside the repository.