Point Opencode at Any AI Provider on Windows
You can point Opencode at any AI provider by editing one small settings file on Windows. No reinstall, no juggling. This is the written companion to my video — the same six steps, but with the config file laid out so you can copy it directly.
How it works
Opencode ships knowing about the big providers. To send requests somewhere else — a self-hosted model, an OpenAI-compatible gateway, any endpoint that speaks the OpenAI chat format — you add a provider block to your settings file. That block tells Opencode the address, your key, and the model to use.
This edits Opencode's opencode.json. Unlike a plain key-value file, it defines a full provider using the @ai-sdk/openai-compatible package — so the JSON is a little larger, but you still only fill in three real values.
Step 1 — open PowerShell
Press Start, type PowerShell, and open it.
Step 2 — open the settings file in Notepad
Paste this and press Enter. It creates the config folder if it's missing and opens the settings file in Notepad:
if (!(Test-Path "$env:USERPROFILE\.config\opencode")) { New-Item -ItemType Directory "$env:USERPROFILE\.config\opencode" | Out-Null }
notepad "$env:USERPROFILE\.config\opencode\opencode.json"If Notepad asks to create a new file, click Yes. An empty file is fine — you'll fill it in next.
Step 3 — paste this config
You'll set three values: the address (baseURL), your key (apiKey), and the model name. Everything else is scaffolding. Paste this into Notepad and swap in your provider's details:
{
"$schema": "https://opencode.ai/config.json",
"model": "myprovider/the-model-name",
"provider": {
"myprovider": {
"npm": "@ai-sdk/openai-compatible",
"name": "My Provider",
"options": {
"baseURL": "https://your-provider.example.com/v1",
"apiKey": "{env:MY_PROVIDER_API_KEY}"
},
"models": {
"the-model-name": {
"name": "My Model"
}
}
}
}
}baseURL— your provider's API endpoint. Use@ai-sdk/openai-compatiblefor endpoints on/v1/chat/completions.apiKey— your key.{env:MY_PROVIDER_API_KEY}reads it from an environment variable so it stays out of the file. You can also paste a raw key here.- model name — appears in three spots: the top-level
modelasmyprovider/the-model-name, the key undermodels, and the provider idmyproviderties them together. Keep all three consistent.
opencode.json must be valid JSON — double quotes on every key and value, commas between entries, no trailing comma after the last one. A single typo stops Opencode from loading it.
Step 4 — save the file
Press Ctrl + S in Notepad to save. Keep the filename exactly opencode.json — if Notepad tries to append .txt, wrap the name in quotes in the Save dialog.
Step 5 — reopen Opencode
Close any running Opencode session and start it again so it picks up the new settings.
Verify it worked
Inside Opencode, run /models. Your provider and model should appear in the picker. If they don't show up, opencode auth list shows any stored credentials, and double-check that the provider id, baseURL, and model name all match across the file.
To switch back, delete your provider block (or the whole file) and reopen Opencode. Your settings live in one place, so there's nothing else to undo.
That's the whole trick — one file, three values, no reinstall.
