This guide explains how to install OpenCode on Linux and edit the config file opencode.json so that the model service points to MyAI168.
Please follow steps 1 to 7 below in order. If you run into trouble, see "Common Notes" at the end.
This guide applies to the current OpenCode 1.x release; the newly released OpenCode 2 reads the same config file in the same locations and format, so the setup below works unchanged.
If OpenCode is not installed yet, open a terminal and run one of the following (official docs: https://opencode.ai/docs/):
# Option 1: official install script (recommended)
curl -fsSL https://opencode.ai/install | bash
# Option 2: Homebrew (also available on Linux)
brew install anomalyco/tap/opencode
# Option 3: npm (requires Node.js)
npm install -g opencode-ai
# Arch Linux (official repository, or AUR: paru -S opencode-bin)
sudo pacman -S opencode
After installing, launch it once (type opencode in the terminal, or open the desktop app) so the config folder gets created, then fully quit it following "Step 2".
* The official docs do not guarantee that the first launch creates the config file opencode.json; if "Step 3" cannot find it, see the note at the end of that step to create it manually.
* If you have already installed and used OpenCode and the config file exists, you may skip this step.
* To switch to OpenCode 2: it uses the same opencode command and cannot be installed alongside 1.x, so remove 1.x first and follow the official docs at https://opencode.ai/v2/docs (for example curl -fsSL https://opencode.ai/v2/install | bash).
Always quit the app before editing, otherwise your changes may be overwritten by the old settings.
Close the window, and make sure there is no OpenCode icon in the system tray / top status bar (if there is, right-click it and choose Quit). If you are not sure whether it is fully closed, open a terminal and run the following command to force quit:
pkill -f opencode
The config file is named opencode.json and lives in a hidden directory inside your user home folder.
xdg-open ~/.config/opencode/
The file manager will open that folder, and opencode.json is inside it.
* OpenCode also accepts the JSONC format (opencode.jsonc); if the folder already contains opencode.jsonc, just edit that file instead — the remaining steps are the same.
* If you cannot find opencode.json in the folder, search for the file name opencode.json directly in the file manager search box.
* On Linux, hidden folders (those starting with a dot) are not shown by default; in the file manager you can press Ctrl + H to toggle showing hidden files.
If you still cannot find opencode.json (the folder is empty or does not exist): the app has not auto-generated the config file yet, so create it manually. Open a terminal, paste the following two lines and press Enter after each:
mkdir -p ~/.config/opencode
touch ~/.config/opencode/opencode.json
Then open the folder as described above and you will see the newly created empty opencode.json. The manually created file is empty; go straight to "Step 5" and paste the full content into it.
Right-click opencode.json → "Open With" → choose a plain text editor (e.g. gedit, Kate, Text Editor, depending on your desktop environment). Or open it directly with an editor in the terminal, for example:
nano ~/.config/opencode/opencode.json
* Important: always use a plain text editor. Do not open it with word processors like LibreOffice Writer, as they may break the format when saving.
If the file is new or empty: copy and paste the whole block below. If the file already has content: do NOT overwrite it wholesale — that would delete your existing agent / permission / plugin / theme settings (OpenCode merges its config files rather than replacing them); instead, merge the two providers inside the "provider" block below into the "provider" block of your existing config (if there is no "provider" block yet, add the whole block).
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"myai168": {
"name": "MyAI168",
"npm": "@ai-sdk/openai",
"options": {
"baseURL": "https://www.myai168.com/en/api/openai/v1",
"apiKey": "YOUR_API_KEY"
},
"models": {
"gpt-6.1-sol": { "name": "GPT-6.1 Sol" }
}
},
"myai168_claude": {
"name": "MyAI168 Claude",
"npm": "@ai-sdk/anthropic",
"options": {
"baseURL": "https://www.myai168.com/en/api/anthropic/v1",
"apiKey": "YOUR_API_KEY"
},
"models": {
"claude-opus-5-5": { "name": "Claude Opus 5.5" }
}
}
}
}
The only thing you need to fill in: replace both occurrences of YOUR_API_KEY with your actual API key (use the same key in both places). Do not change anything else.
Press Ctrl + S to save. If you are using nano, press Ctrl + O then Enter to save, then Ctrl + X to exit.
* Note: after saving, make sure the file name is still opencode.json and the extension has not been changed to .txt.
After reopening OpenCode, type /models in the prompt box (or use the model menu in the desktop app) and you will see two models:
Pick one and verify with an arithmetic question: What is 123456 times 789? Reply with the number only. — if it answers 97406784 and the API usage on the Developer API Key page increases, the call went through MyAI168 (do not verify with "Who are you?"; a model's self-description is unreliable).
(Optional) To make OpenCode start with a MyAI168 model by default, add "model": "myai168/gpt-6.1-sol", at the top level of the config file (the same level as "provider"). The format is "provider ID/model ID"; for Claude use "myai168_claude/claude-opus-5-5".
/openai/v1 and the Claude one ends with /anthropic/v1. Do not unify or change them.models block following the existing format (remember to add a comma at the end of the previous line).opencode in a terminal to see the error message.models block is not on this site's accepted list; use this site's model IDs (list them with GET https://www.myai168.com/en/api/openai/v1/models)./connect command (choose Other at the bottom of the list and enter the provider ID myai168 or myai168_claude, which must match the config file) — OpenCode then keeps the key itself and you can omit apiKey from options. Another option is "apiKey": "{env:MYAI168_API_KEY}", which reads the key from an environment variable.Everything below is optional and goes in ~/.config/opencode/opencode.json. OpenCode merges its config files, so the snippets show only what to add or change — merge them into your existing content instead of overwriting it.
model is the model used on start-up. small_model handles light jobs such as generating conversation titles; without it those jobs also go to the main model, which costs one extra main-model call per new conversation. The small model must be listed under models of its provider:
{
"model": "myai168_claude/claude-opus-5-5",
"small_model": "myai168/gpt-5.4-mini",
"provider": {
"myai168": {
"models": {
"gpt-6.1-sol": { "name": "GPT-6.1 Sol" },
"gpt-5.4-mini": { "name": "GPT-5.4 mini" }
}
}
}
}
Models are always written as "provider/model"; the usable model IDs are those returned by GET https://www.myai168.com/en/api/openai/v1/models.
opencode models myai168
opencode run "Explain the layout of this project"
opencode run -m myai168/gpt-6.1-sol "Write unit tests for the utils module"
opencode run -c "Turn those changes into a commit message"
opencode models myai168 lists the models of that provider from your config — a quick way to confirm the file is being read; opencode run performs one task without opening the UI, -m selects a model and -c continues the previous conversation.
Type /init in a conversation inside your project; OpenCode analyses it and creates AGENTS.md. Keep build and test commands and coding style there, and every later conversation picks it up.
If long answers or long reasoning get cut off, add timeout (milliseconds) to that provider's options:
{
"provider": {
"myai168": {
"options": {
"timeout": 600000
}
}
}
}
To let OpenCode use this site's AI modules as tools, see the "OpenCode" section of the MYAI168 MCP CLI page.