OpenCode
Configure the LMU AI API in OpenCode as an OpenAI / Anthropic-compatible backend to use Claude, Codex, GLM, and other models.
Just install OpenCode by following the official docs — the website has a detailed tutorial:
- Official docs: https://opencode.ai/docs/
Configure models
After installation, edit the config file ~/.config/opencode/opencode.json. OpenCode supports two protocols for connecting to upstream services — just pick the one that matches your provider.
Choosing a protocol
| Protocol | npm | baseURL format | When to use |
|---|---|---|---|
| OpenAI protocol | @ai-sdk/openai | Ends in /v1, e.g. https://xxx.com/v1 | GPT, Codex, and most OpenAI-compatible services |
| Anthropic protocol | @ai-sdk/anthropic | Also ends in /v1, e.g. https://xxx.com/v1 | Claude's native protocol, plus Chinese models that declare the Anthropic protocol (such as GLM) |
A common baseURL pitfall
For both the OpenAI and Anthropic protocols, the baseURL must go all the way down to the /v1 level. The SDK only appends the specific endpoint after it (such as /chat/completions or /messages); if you omit /v1, the request is silently dropped — the model returns no error but responds with empty content.
Example 1 — OpenAI protocol
A minimal working config (you can configure multiple models under one provider):
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"openai": {
"options": {
"baseURL": "https://api.lmuai.com/v1"
},
"models": {
"gpt-5.5": { "name": "GPT-5.5" },
"gpt-5.4": { "name": "GPT-5.4" }
}
}
}
}Why use `openai` as the provider id?
OpenCode recognizes openai as a built-in provider id, so it automatically loads @ai-sdk/openai and uses the /v1/responses endpoint (with full support for reasoning models). So when connecting to an OpenAI-protocol service, just name the provider id openai and point baseURL at your own gateway — there's no need to write the npm field by hand.
If you need to refine a model's capability declaration (context length, reasoning-effort variants, etc.), just add fields to that model's entry:
"gpt-5.5": {
"name": "GPT-5.5",
"limit": { "context": 1050000, "output": 128000 },
"options": { "store": false },
"variants": { "low": {}, "medium": {}, "high": {}, "xhigh": {} }
}Here variants defines the switchable reasoning-effort levels; switch between them at runtime in OpenCode by pressing Ctrl + T.
Example 2 — Anthropic protocol (common for Chinese models)
Some Chinese models (such as GLM) are provided by domestic vendors but follow the Anthropic protocol in their API, so they need @ai-sdk/anthropic:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"lmuai": {
"npm": "@ai-sdk/anthropic",
"name": "lmuai",
"options": {
"baseURL": "https://api.lmuai.com/v1"
},
"models": {
"glm-5.1": {
"name": "GLM-5.1"
}
}
}
}
}How do I tell which protocol it is?
Check the request example in the provider's docs:
- Endpoint is
/v1/chat/completions→ OpenAI protocol - Endpoint is
/v1/messageswith ananthropic-versionrequest header → Anthropic protocol
Example 3 — Claude native models
To connect a native Claude model (such as claude-sonnet-4-6), the provider id must use the built-in anthropic — you cannot use a custom name:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"anthropic": {
"npm": "@ai-sdk/anthropic",
"options": {
"baseURL": "https://api.lmuai.com/v1"
}
}
}
}Verify:
opencode run --model anthropic/claude-sonnet-4-6 "Hello"Why can't Claude models use a custom provider id?
Like openai, anthropic is a built-in provider id in OpenCode, and OpenCode ships built-in definitions for the entire Claude model lineup (claude-sonnet-4-6, etc.) under it.
That's why opencode run --model anthropic/claude-sonnet-4-6 "Hello" works; but if you change the provider id to a custom name (such as lmuai/claude-sonnet-4-6), OpenCode can't find the model definition and the test fails.
In short: use anthropic for native Claude models, and only use a custom provider id (such as lmuai) for custom models like GLM.
If you need to use multiple protocols and multiple providers at once, just put them all under provider — they don't interfere with each other. For example, LMU AI offers the GPT series (openai), the Claude series (anthropic), and the GLM series (lmuai, Anthropic protocol) at the same time, and all three providers can share one gateway.
Configure keys
Method 1 — command line (recommended)
# Log in or update the key for a provider
opencode auth login
# List all configured providers and their key status
opencode auth list
# Remove the key for a specific provider
opencode auth logout <provider-name>Method 2 — edit the config file manually
Add the API key for the relevant provider in ~/.local/share/opencode/auth.json:
{
"provider-name": {
"type": "api",
"key": "your-api-key"
}
}Note
The provider name in auth.json must exactly match the provider name in opencode.json.
Don't put apiKey in the options block of opencode.json — OpenCode won't read the key there; it must go through auth.json or opencode auth login.
Verify the config
Once configured, verify quickly with a single command:
opencode run --model provider-name/model-name "Hello"For example, opencode run --model lmuai/glm-5.1 "Hello". A normal reply means the config works.
If there's no output at all (neither an error nor a reply), it's usually one of these two problems:
- The baseURL is missing
/v1— see the tip in the "Choosing a protocol" section above. - The key isn't configured in
auth.json— check whetheropencode auth listshows the relevant provider.
For more debugging information, add --print-logs --log-level INFO.
Tip
In OpenCode, press Ctrl + T to switch between reasoning-effort levels (variants).
Last updated:
Get an LMU AI key and start using Claude, Codex and more
Free sign-up, flexible plans, one key across Claude Code, Codex CLI, Cursor, VS Code, OpenCode, Cherry Studio and other AI tools.
Sign upCC Switch one-click import
Use the CC Switch desktop tool to import your LMU AI API config into Claude Code in one click, skipping the manual settings.json edit.
Cherry Studio
Connect Cherry Studio to the LMU AI API and set up Claude, Chinese, and OpenAI model channels, with a direct connection on domestic networks.