OpenCode CLI
This guide shows how to install and configure OpenCode CLI with Infer.
OpenCode is a terminal-based AI coding agent that accepts custom
OpenAI-compatible providers via opencode.jsonc.
Prerequisites
Before you begin
- Node.js 20 or later — download from https://nodejs.org, then verify with `node --version`.
- Create an Infer API key in the [API Keys dashboard](/dashboard/api-keys).
Steps
- 1Install OpenCode.
- 2Export `OPENAI_API_KEY` and `OPENAI_BASE_URL` in your shell.
- 3If `~/.config/opencode/opencode.jsonc` does not exist yet, create it and add an Infer provider.
- 4Launch `opencode`, pick the Infer model with `/model`, and send a test prompt.
Install
Run the official OpenCode installer. Alternatives: `npm install -g opencode-ai`, or see [the OpenCode docs](https://opencode.ai/docs) for Homebrew, Arch, WinGet, and other packages.
curl -fsSL https://opencode.ai/install | bashAfter the installer finishes, verify the binary is on your PATH:
opencode --versionA successful install prints a single version line (for example, 0.x.y). If you
see opencode: command not found, open a fresh terminal so the new PATH entry
is picked up, or follow the installer’s manual PATH instructions.
Environment (macOS / Linux)
Add these exports to your shell profile (~/.zshrc or ~/.bashrc), or run them
directly in your current session.
export OPENAI_API_KEY="your_api_key"
export OPENAI_BASE_URL="https://api-agenthub-pre.riema.xyz/v1"If you edited your shell profile, reload it so the new values take effect in the current terminal (or just open a fresh one).
source ~/.zshrc # or: source ~/.bashrcOPENAI_API_KEY in your shell. If you also use the official OpenAI API directly, prefer a project-local .env file or a tool like direnv so the Infer override only applies to the projects that need it.Verify the variables are set
First, confirm the values are present in the current shell — they should print your key and the Infer base URL:
printenv OPENAI_API_KEY
printenv OPENAI_BASE_URLIf either command prints nothing, the variable is not set in this terminal.
Next, confirm they are also written to your shell profile so new terminals
pick them up automatically. Match against ~/.zshrc (zsh) or ~/.bashrc
(bash):
# Use ripgrep if you have it:
rg -n "OPENAI_API_KEY|OPENAI_BASE_URL" ~/.zshrc
# Or with grep (always installed):
grep -nE "OPENAI_API_KEY|OPENAI_BASE_URL" ~/.zshrc- If grep prints two matching lines, the exports are persisted — every new shell will get them for free.
- If grep prints nothing, the values only live in the current terminal
session. Re-open the file in your editor and add the two
exportlines from above so the next terminal you open also has them.
Environment (Windows PowerShell)
Set the variables for the current session.
$env:OPENAI_API_KEY = "your_api_key"
$env:OPENAI_BASE_URL = "https://api-agenthub-pre.riema.xyz/v1"To persist them across sessions, run setx instead and restart PowerShell.
setx OPENAI_API_KEY "your_api_key"
setx OPENAI_BASE_URL "https://api-agenthub-pre.riema.xyz/v1"OPENAI_API_KEY in your shell. If you also use the official OpenAI API directly, prefer a project-local .env file or a tool like direnv so the Infer override only applies to the projects that need it.Verify the variables are set
Confirm both values are present in the current PowerShell session:
echo $env:OPENAI_API_KEY
echo $env:OPENAI_BASE_URLIf you used setx, also open a fresh PowerShell window and re-run the same
two commands — setx only takes effect in newly-spawned shells, never the one
you ran it in.
OpenCode provider
OpenCode reads provider settings from a plain-text JSON file at:
- macOS / Linux:
~/.config/opencode/opencode.jsonc - Windows:
%USERPROFILE%\.config\opencode\opencode.jsonc
The first time you set up OpenCode this file (and usually the parent folder)
does not exist yet — you have to create it. Open it with any plain-text
editor afterwards (VS Code, Notepad, TextEdit set to
Format → Make Plain Text, nano, vim, etc.).
Create the file (first-time setup)
On macOS / Linux, the easiest path is one mkdir plus one editor command:
mkdir -p ~/.config/opencode
nano ~/.config/opencode/opencode.jsonc # or: code, vim, etc.On Windows PowerShell:
$configDir = Join-Path $env:USERPROFILE ".config\opencode"
New-Item -ItemType Directory -Force -Path $configDir | Out-Null
notepad (Join-Path $configDir "opencode.jsonc")Paste the provider block
Inside the editor, paste the block below. Replace "your_api_key" with your
Infer key — OpenCode reads the key from this file rather than from
OPENAI_API_KEY. If the file already had unrelated settings, add the new
"infer" entry under provider instead of replacing the whole file.
{
// OpenCode configuration
// Docs: https://opencode.ai/docs
"$schema": "https://opencode.ai/config.json",
"provider": {
"infer": {
"name": "Infer",
"npm": "@ai-sdk/openai-compatible",
"models": {
"your_model": {
"name": "Infer your_model"
},
"gpt-5.4": {
"name": "Infer gpt-5.4"
},
"claude-opus-4-6": {
"name": "Infer claude-opus-4-6"
},
"claude-sonnet-4-6": {
"name": "Infer claude-sonnet-4-6"
},
"gemini-3.1-pro-preview": {
"name": "Infer gemini-3.1-pro-preview"
}
},
"options": {
"baseURL": "https://api-agenthub-pre.riema.xyz/v1",
"apiKey": "your_api_key"
}
}
}
}Save the file and exit the editor (in nano: Ctrl-O, Enter, Ctrl-X).
The fields you actually need to know
Most of the block is boilerplate you can paste as-is. Only three fields matter:
options.apiKey— your Infer API key. OpenCode reads it from here, not fromOPENAI_API_KEY.options.baseURL— the Infer endpoint. Must include the/v1suffix.models— which Infer models to expose to/modelinside OpenCode. The keys must match Infer model IDs exactly (case-sensitive); thenameis just the cosmetic label OpenCode shows in its picker.
Add more models
The block above ships a small starter set. To use other models on Infer —
Gemini, Qwen, Kimi, GLM, DeepSeek, etc. — open the
Models page, copy the model ID exactly (case-sensitive),
and add another entry under provider.infer.models. For example, to add
gemini-3.1-pro-preview:
"models": {
"gpt-5.4": { "name": "Infer gpt-5.4" },
"claude-opus-4-6": { "name": "Infer claude-opus-4-6" },
"gemini-3.1-pro-preview": { "name": "Infer gemini-3.1-pro-preview" }
}Save the file again and OpenCode will surface the new entries the next time you
run /model.
The baseURL must include /v1. OpenCode sends requests directly to the
URL you paste; copy it verbatim from the Base URL section of the
Quickstart. No trailing slash.
Launch
This is a three-action sequence — the first one is in your terminal, the next two are inside the OpenCode TUI.
1. Start OpenCode from your project directory (in your terminal):
cd your-project
opencode2. Once OpenCode opens, you will see its interactive prompt. Type the following slash command and press Enter:
/model3. A model picker appears. Use the arrow keys to highlight one of the Infer
entries (for example, Infer gpt-5.4) and press Enter to select it.
OpenCode will route subsequent prompts through Infer using that model.
Verify
After selecting an Infer model with /model, send a short prompt. A reply confirms the provider, base URL, and key are all wired up.
> Reply with 'ok' if you can see this.A short reply (typically just ok) confirms three things at once: OpenCode
loaded the Infer provider from opencode.jsonc, the base URL is reachable, and
your API key is valid. The call shows up on the Usage page
within a few seconds, and your available balance on the
Billing page should update according to the request cost.
If OpenCode shows an error banner instead of a reply, jump to
Troubleshooting below — the most common causes are a missing
or mistyped apiKey in opencode.jsonc, a model key that is not on the
Models page, or a baseURL missing the /v1 suffix.