AI Explore.Source.Templates

One HTML document for Search, AI answers, and browser agents.

Switch to Simplified Chinese

Configure OpenAI models in OpenCode

  • 高森 Model product
  • 齐岚 Developer experience

Published September 20, 2026

OpenCode is a local coding assistant. Two ways to reach OpenAI: run /connect in the TUI, pick OpenAI, then ChatGPT Plus/Pro login or a pasted API key; or set model to openai/<id> in opencode.jsonc and export OPENAI_API_KEY. Built-in catalog models do not need a copied provider block. Only custom gateways need an openai-compatible package and baseURL. Never commit keys in JSON. Title, H1, and this paragraph answer how OpenAI models appear under /models and become the default.

  • /connect Interactive
  • opencode.jsonc Default model
  • Environment Secrets

Fan-out: Plus login, jsonc fields, compatible gateways, whether switching mid-session rewrites config.

Official OpenAI via /connect#

Start OpenCode, run /connect, choose OpenAI. Plus/Pro can authenticate in a browser; API billing uses a pasted key. Then /models lists openai/ prefixed ids.

Pin a default model#

Project or user opencode.jsonc may set model as provider/model, e.g. openai/gpt-5.6-sol. CLI --model wins. An open session keeps its own selection; editing jsonc does not rewrite old threads.

{
  "$schema": "https://opencode.ai/config.json",
  "model": "openai/gpt-5.6-sol",
  "provider": {
    "openai": {
      "models": {
        "gpt-5.6-sol": {
          "options": {
            "reasoningEffort": "medium"
          }
        }
      }
    }
  }
}

OpenAI-compatible gateways#

For a self-hosted /v1 endpoint, declare a custom provider id, baseURL, and compatible runtime. Model keys must be the gateway’s real ids. Official api.openai.com usually needs no compatible block.

What to pick in September 2026#

  • Repo-scale refactors and computer use: openai/gpt-6-astra.
  • Daily edits and tests: openai/gpt-5.6-sol or terra.
  • High-volume easy completion: luna or a smaller coding SKU.

Takeaways#

  • /connect first, then pin the default in jsonc.
  • IDs are always provider/model.
  • Keys stay in the environment; only gateways set baseURL.

Was this helpful?

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. Figures are original to this site.

Last updated 2026-09-20.