This guide explains how to install OpenCode on Windows 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 PowerShell and run one of the following (official docs: https://opencode.ai/docs/; the official docs recommend WSL on Windows for best compatibility, but native Windows also works with the commands below):
# Option 1: Chocolatey
choco install opencode
# Option 2: Scoop
scoop install opencode
# Option 3: npm (requires Node.js)
npm install -g opencode-ai
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. OpenCode 2 on Windows is not available through Chocolatey / Scoop or other package managers; download the official standalone binary instead.
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 taskbar (system tray) at the bottom-right (if there is, right-click it and choose Exit).
The config file is named opencode.json and lives in a hidden directory inside your user home folder.
Win + R to open "Run".%USERPROFILE%\.config\opencode\
File Explorer 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 Explorer search box.
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 "Run" (Win + R), paste the line below and press Enter to create the folder:
cmd /c "mkdir %USERPROFILE%\.config\opencode 2>nul & type nul > %USERPROFILE%\.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 "Notepad".
* Important: always use a plain text editor. Do not open it with word processors like Word, 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.
* Note: after saving, make sure the file name is still opencode.json and the extension has not been changed to .txt. If Notepad accidentally saves it as opencode.json.txt, delete the extra .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 %USERPROFILE%\.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.