Get your API key

Terminal coding agent · setup guide

Connect OpenCode to AllModelAPI

A free, open-source coding agent for the terminal (and desktop). It works well with every AllModelAPI model, and you can switch models inside the app.

About 10 minutesWindows · macOS · LinuxUses the Chat Completions APIChecked 19 November 2026
1 · Your computer
Stays in this browser tab. It is never saved or sent anywhere. No key yet? Create one.

Pick the easy way

Easiest

Let an AI agent do it

Already use an AI coding agent (any one: Codex, OpenCode, Cursor, another assistant)? Copy this prompt, paste it into that agent and press Enter. It installs OpenCode, writes the settings, saves your key and tests everything. It will ask you for your API key.

See what the prompt says
# Task: connect OpenCode to AllModelAPI

You are a coding agent on my computer. Set up **OpenCode** so it uses **AllModelAPI** as its model provider. Work step by step, tell me briefly what you are doing, and ask me before doing anything not listed here.

## Facts
- Service: AllModelAPI, an API gateway for DeepSeek, Qwen, GLM, Kimi and MiniMax models.
- OpenCode talks to it with the Chat Completions API.
- Base URL: `https://api.allmodelapi.com/v1`
- Main model: `deepseek-v4-pro` (DeepSeek V4 Pro, 1000K context). Fast background model: `deepseek-flash`.
- Model IDs are case-sensitive. Full list: https://api.allmodelapi.com/v1/models
- API key: not included. **Ask me to paste my AllModelAPI API key** (I can create one at https://allmodelapi.com/customer/api-keys).
- Human guide: https://allmodelapi.com/documentation/opencode

## Steps
1. Detect my operating system (macOS, Linux or Windows) and shell.
2. Check whether OpenCode is installed: `opencode --version`. If it is not, install it with the official command:
   - macOS: `curl -fsSL https://opencode.ai/install | bash`
   - Linux: `curl -fsSL https://opencode.ai/install | bash`
   - Windows (PowerShell): `winget install OpenJS.NodeJS.LTS ; npm install -g opencode-ai`
3. Settings file location:
   - macOS / Linux: `~/.config/opencode/opencode.json`
   - Windows: `%USERPROFILE%\.config\opencode\opencode.json`
4. If the file exists, copy it to `<file>.bak` first. If it contains other settings, **merge**: keep everything unrelated and only add or replace the keys shown below. If it does not exist, create it with exactly this content:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "allmodelapi/deepseek-v4-pro",
  "small_model": "allmodelapi/deepseek-flash",
  "provider": {
    "allmodelapi": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "AllModelAPI",
      "options": {
        "baseURL": "https://api.allmodelapi.com/v1",
        "apiKey": "{env:ALLMODELAPI_API_KEY}"
      },
      "models": {
        "deepseek-v4-pro": {
          "name": "DeepSeek V4 Pro",
          "limit": {
            "context": 1000000,
            "output": 131072
          }
        },
        "qwen4-max": {
          "name": "Qwen 4 Max",
          "limit": {
            "context": 991808,
            "output": 131072
          }
        },
        "glm-5.3": {
          "name": "GLM 5.3",
          "limit": {
            "context": 1000000,
            "output": 128000
          }
        },
        "kimi-k3.1-pro": {
          "name": "Kimi K3.1 Pro",
          "limit": {
            "context": 1048576,
            "output": 131072
          }
        },
        "deepseek-flash": {
          "name": "DeepSeek V4.1 Flash",
          "limit": {
            "context": 1000000,
            "output": 131072
          }
        },
        "qwen3.7-plus": {
          "name": "Qwen 3.7 Plus",
          "limit": {
            "context": 1000000,
            "output": 128000
          }
        },
        "qwen3.8-flash": {
          "name": "Qwen 3.8 Flash",
          "limit": {
            "context": 1000000,
            "output": 128000
          }
        },
        "glm-5.3-flash": {
          "name": "GLM 5.3 Flash",
          "limit": {
            "context": 1000000,
            "output": 128000
          }
        },
        "kimi-k3": {
          "name": "Kimi K3",
          "limit": {
            "context": 1048576,
            "output": 131072
          }
        },
        "MiniMax-M3.1-Flash": {
          "name": "MiniMax M3.1 Flash",
          "limit": {
            "context": 1000000,
            "output": 131072
          }
        }
      }
    }
  }
}
```
5. API key: Save it as a persistent user environment variable named `ALLMODELAPI_API_KEY`: append `export ALLMODELAPI_API_KEY="<key>"` to ~/.zshrc (macOS) or ~/.bashrc (Linux), or on Windows run `[Environment]::SetEnvironmentVariable("ALLMODELAPI_API_KEY", "<key>", "User")`. Replace an existing line instead of duplicating it.
6. Verify. Run:
```
opencode --version
opencode run "Reply with just: OK"
```
   A short reply such as "OK" means it works. On 401 re-check the key; on 400 "unknown model" re-check the model ID; on 402 I need more credit.
7. Report: what you changed, where the backup is, and how I start OpenCode.

## Rules
- Only touch the files named above. Do not remove other providers, models or settings.
- Never print my full API key in your replies or logs, and never put it in a git repository or project file.
- Use JSON that parses: no comments in JSON, no trailing commas.
One paste

Do it in your terminal

Install OpenCode (step 3 below), save your key (step 4), then paste this one command into PowerShell. It backs up your old settings and writes the complete new file.

Or edit the file yourself: open %USERPROFILE%\.config\opencode\opencode.json, delete everything inside, paste the full file, and save.

No key pasted above, so copied text contains PASTE_YOUR_ALLMODELAPI_KEY_HERE. Paste your key at the top first, or replace that text later.

Step by step, for Windows

Never used a terminal before? That's fine. Follow each step in order. Every grey “Why?” box explains what you just did.

  1. Get your AllModelAPI API key

    Sign in, open API Keys and create a key. Copy it and keep it private: anyone with the key can spend your credit. You will see it only once.

    Why? An API key is like a password for apps. It lets a tool use AI models on your account, and your usage is billed to it.

    Create your key here: https://allmodelapi.com/customer/api-keys

  2. Open a terminal

    Press the Windows key, type PowerShell and press Enter. A blue or black window opens. That is your terminal. Use PowerShell, not Command Prompt.

    Why? A terminal is a window where you type commands instead of clicking buttons. Every command on this page is pasted there.

    To paste in a terminal: Ctrl + V in PowerShell, Cmd + V on Mac, Ctrl + Shift + V on Linux. Then press Enter.

  3. Install OpenCode

    Paste this command and press Enter. Wait until it finishes. Then close the terminal and open a new one so it can find OpenCode.

    Why? This downloads the tool from its official website and adds it to your computer.

    Install (PowerShell)
    winget install OpenJS.NodeJS.LTS
    # close PowerShell, open a new one, then:
    npm install -g opencode-ai
    Check it installed: this should print a version number
    opencode --version

    Already installed? Skip to the next step.

  4. Save your API key on this computer

    Run the command below once. Replace PASTE_YOUR_ALLMODELAPI_KEY_HERE with your key first, or paste your key in the box at the top of this page. The check should print your key.

    Why? An environment variable is a named value your computer remembers. OpenCode reads your key from ALLMODELAPI_API_KEY, so the key never sits inside a config file you might share by mistake.

    Save your key (PowerShell)
    [Environment]::SetEnvironmentVariable("ALLMODELAPI_API_KEY", "PASTE_YOUR_ALLMODELAPI_KEY_HERE", "User")
    Close PowerShell, open a new one, then check
    echo $env:ALLMODELAPI_API_KEY

    The new value only appears in terminals you open after running the command.

  5. Save the OpenCode settings file

    Paste this one command and press Enter. It creates the folder if needed, keeps a backup of any old file (.bak), and writes the complete settings file. Prefer doing it by hand? Use "Copy full config file" at the top, open the file in a text editor, select everything, paste, and save.

    Why? OpenCode reads its settings from %USERPROFILE%\.config\opencode\opencode.json. This file tells it to send requests to AllModelAPI and which model to use.

    Write the settings file
    $file = Join-Path $HOME ".config\opencode\opencode.json"
    New-Item -ItemType Directory -Force -Path (Join-Path $HOME ".config\opencode") | Out-Null
    if (Test-Path $file) { Copy-Item $file "$file.bak" -Force; Write-Host "Backup saved: $file.bak" }
    [System.IO.File]::WriteAllText($file, @'
    {
      "$schema": "https://opencode.ai/config.json",
      "model": "allmodelapi/deepseek-v4-pro",
      "small_model": "allmodelapi/deepseek-flash",
      "provider": {
        "allmodelapi": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "AllModelAPI",
          "options": {
            "baseURL": "https://api.allmodelapi.com/v1",
            "apiKey": "{env:ALLMODELAPI_API_KEY}"
          },
          "models": {
            "deepseek-v4-pro": {
              "name": "DeepSeek V4 Pro",
              "limit": {
                "context": 1000000,
                "output": 131072
              }
            },
            "qwen4-max": {
              "name": "Qwen 4 Max",
              "limit": {
                "context": 991808,
                "output": 131072
              }
            },
            "glm-5.3": {
              "name": "GLM 5.3",
              "limit": {
                "context": 1000000,
                "output": 128000
              }
            },
            "kimi-k3.1-pro": {
              "name": "Kimi K3.1 Pro",
              "limit": {
                "context": 1048576,
                "output": 131072
              }
            },
            "deepseek-flash": {
              "name": "DeepSeek V4.1 Flash",
              "limit": {
                "context": 1000000,
                "output": 131072
              }
            },
            "qwen3.7-plus": {
              "name": "Qwen 3.7 Plus",
              "limit": {
                "context": 1000000,
                "output": 128000
              }
            },
            "qwen3.8-flash": {
              "name": "Qwen 3.8 Flash",
              "limit": {
                "context": 1000000,
                "output": 128000
              }
            },
            "glm-5.3-flash": {
              "name": "GLM 5.3 Flash",
              "limit": {
                "context": 1000000,
                "output": 128000
              }
            },
            "kimi-k3": {
              "name": "Kimi K3",
              "limit": {
                "context": 1048576,
                "output": 131072
              }
            },
            "MiniMax-M3.1-Flash": {
              "name": "MiniMax M3.1 Flash",
              "limit": {
                "context": 1000000,
                "output": 131072
              }
            }
          }
        }
      }
    }
    '@)
    Write-Host "Saved: $file"

    Your old file had other settings you care about? Use the agent prompt instead. It merges instead of replacing.

  6. Check that it works

    You should see a short reply such as OK. If you see an error instead, look it up in "Something went wrong?" below.

    Why? This sends one tiny request, so you know the key, the address and the model are all correct before you start a real project.

    Check the install
    opencode --version
    Ask one question without opening the app
    opencode run "Reply with just: OK"
    Test your key directly (PowerShell)
    Invoke-RestMethod -Method Post -Uri "https://api.allmodelapi.com/v1/chat/completions" `
      -Headers @{ Authorization = "Bearer $env:ALLMODELAPI_API_KEY" } `
      -ContentType "application/json" `
      -Body '{"model":"deepseek-v4-pro","max_tokens":20,"messages":[{"role":"user","content":"Reply with just: OK"}]}'
  7. Start building

    Open a terminal in your project folder and type opencode. Type /models to switch between AllModelAPI models.

The complete settings file

This is the whole file. Every line matters, so copy it with the button instead of selecting it by hand.

%USERPROFILE%\.config\opencode\opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "allmodelapi/deepseek-v4-pro",
  "small_model": "allmodelapi/deepseek-flash",
  "provider": {
    "allmodelapi": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "AllModelAPI",
      "options": {
        "baseURL": "https://api.allmodelapi.com/v1",
        "apiKey": "{env:ALLMODELAPI_API_KEY}"
      },
      "models": {
        "deepseek-v4-pro": {
          "name": "DeepSeek V4 Pro",
          "limit": {
            "context": 1000000,
            "output": 131072
          }
        },
        "qwen4-max": {
          "name": "Qwen 4 Max",
          "limit": {
            "context": 991808,
            "output": 131072
          }
        },
        "glm-5.3": {
          "name": "GLM 5.3",
          "limit": {
            "context": 1000000,
            "output": 128000
          }
        },
        "kimi-k3.1-pro": {
          "name": "Kimi K3.1 Pro",
          "limit": {
            "context": 1048576,
            "output": 131072
          }
        },
        "deepseek-flash": {
          "name": "DeepSeek V4.1 Flash",
          "limit": {
            "context": 1000000,
            "output": 131072
          }
        },
        "qwen3.7-plus": {
          "name": "Qwen 3.7 Plus",
          "limit": {
            "context": 1000000,
            "output": 128000
          }
        },
        "qwen3.8-flash": {
          "name": "Qwen 3.8 Flash",
          "limit": {
            "context": 1000000,
            "output": 128000
          }
        },
        "glm-5.3-flash": {
          "name": "GLM 5.3 Flash",
          "limit": {
            "context": 1000000,
            "output": 128000
          }
        },
        "kimi-k3": {
          "name": "Kimi K3",
          "limit": {
            "context": 1048576,
            "output": 131072
          }
        },
        "MiniMax-M3.1-Flash": {
          "name": "MiniMax M3.1 Flash",
          "limit": {
            "context": 1000000,
            "output": 131072
          }
        }
      }
    }
  }
}

Something went wrong?

Model unavailable: allmodelapi/…

The model ID is not in the models list of the file, or has a typo. Copy the full file from this page again.

On Windows, OpenCode ignores my settings

Save the same file as opencode.json inside your project folder. A project file always works and overrides the global one.

401 even though I saved the key

OpenCode reads the key from ALLMODELAPI_API_KEY when it starts. Close OpenCode and your terminal, open a new terminal and start it again.

401 / invalid API key

The key is missing, mistyped or revoked. Copy it again from https://allmodelapi.com/customer/api-keys and save it again. Keys start with the same prefix you see in your dashboard.

402 / insufficient credit

Your plan credit and pay-as-you-go credit are used up for this request. Add credit or pick a coding plan in Billing, or choose a cheaper model.

400 / unknown model

Model IDs are case-sensitive and must match the AllModelAPI list exactly, for example MiniMax-M3.1-Flash, not minimax-m3.1-flash.

command not found / is not recognized

The tool is not installed, or your terminal was opened before the install finished. Close the terminal, open a new one and try again.

Still stuck? Copy the agent prompt above into any AI assistant and paste the exact error message after it, or write to support@allmodelapi.com. See all models and IDs in the model list.

OpenCode is a product of the OpenCode project. AllModelAPI is an independent service and is not affiliated with or endorsed by the OpenCode project. The guide only shows how to point the tool at AllModelAPI.

Sources we checked on 19 November 2026. Tools change often; if a step looks different on your screen, follow the official page.