Post

Connect OpenAI-Compatible APIs to OpenCode

Configure OpenCode to use any OpenAI-compatible endpoint like Poe with provider and auth JSON files.

Connect OpenAI-Compatible APIs to OpenCode

Use OpenCode with any OpenAI-compatible API (In my case I will use Poe API) by configuring provider and auth files.

Prerequisites

  • Create an API key: https://poe.com/api_key
  • Endpoint base URL: https://api.poe.com/v1

Provider Configuration

Add a Poe provider pointing to the OpenAI-compatible endpoint.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// ~/.config/opencode/config.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "poe": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "poe.com",
      "options": {
        "baseURL": "https://api.poe.com/v1"
      },
      "models": {
        "Claude-Sonnet-4.5": {
          "name": "Claude Sonnet 4.5"
        },
        "GPT-5-Codex": {
          "name": "GPT-5-Codex"
        }
      }
    }
  }
}
  • npm: adapter implementing the OpenAI-compatible schema.
  • baseURL: target endpoint (Poe).
  • models: friendly labels mapped to remote model identifiers.

Authentication Configuration

Store your Poe API key for the provider.

1
2
3
4
5
6
7
// ~/.local/share/opencode/auth.json
{
  "poe": {
    "type": "api",
    "key": "YOUR_POE_API_KEY"
  }
}
  • type: api for static token auth.
  • key: paste the token from poe.com/api_key.

Usage

  • Restart OpenCode if running.
  • Use the command palette or slash menu to select “poe.com” provider and pick a model.
  • Switch models quickly via slash commands.

Notes

  • Replace model names with the exact identifiers exposed by your endpoint if they differ.
  • Keep auth.json out of version control.
  • If behind a proxy, set HTTPS proxy env vars before launching OpenCode.

According to the “Dependency Deep Dives” series guide, keep posts concise, technical, and consistent in structure.

☕ Support My Work

If you found this post helpful and want to support more content like this, you can buy me a coffee!

Your support helps me continue creating useful articles and tips for fellow developers. Thank you! 🙏

This post is licensed under CC BY 4.0 by the author.