Documentation
How to connect ChatGPT to OpenCode
Last updated:
Setting up OpenCode to work with ChatGPT takes a couple of minutes: put your key and our OpenAI-compatible base URL in the config, and the agent starts reaching OpenAI models through ChatGPT API - no plugins, no code changes.
What OpenCode is
OpenCode calls itself the open source AI coding agent, available in the terminal, in your IDE or as a desktop app. What sets it apart from built-in assistants is that nothing is locked down: the client is open source and the model can come from any of 75+ providers, local ones included.
opencode
Ask anything... "Fix broken tests"
Build · GPT-5.6 Luna OpenAI · medium
tab agents ctrl+p commands
Open source
The project is fully open and installs locally - you are not locked into one vendor or its plans.
Any model
75+ providers to choose from, including local models. Our endpoint plugs in as a regular OpenAI provider.
Understands the project via LSP
OpenCode starts the right language servers itself, so the model works with types and errors rather than plain file text.
Terminal, IDE or desktop
The same agent in three forms, with several sessions running in parallel and a share link for any session.
What you need
- OpenCode installed on your machine
- A ChatGPT API key from the dashboard - sign-up comes with $0.25 of balance to test with
- A project you want to run the agent in
Setting up OpenCode
1. Install OpenCode
If OpenCode is not installed yet, get it from the official site - there are builds for macOS, Linux and Windows. Run it once so it creates its config folder.
Download OpenCode2. Declare the provider in the config
All OpenCode settings live in one file. Open it in any editor:
~/.config/opencode/opencode.jsonc
- No file yet - create it along with the parent folders.
- File already there - do not replace it, just add the provider.openai block to what is already in it.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"openai": {
"options": {
"baseURL": "https://api.llm-gate.tech/v1",
"apiKey": "[Generated key]"
}
}
}
}3. Run it and check
Save the file and start OpenCode in a project folder. Every request to the openai provider now goes through ChatGPT API - replace [Generated key] with the key from your dashboard.
Create API keyFAQ
Do I need a ChatGPT Plus subscription?
No. OpenCode talks to the API, not to the ChatGPT web app, so no subscription is involved. You pay per token, and sign-up comes with $0.25 of balance so you can test the setup before topping up.
Do I have to delete my current OpenCode config?
No. Adding the provider.openai block to the existing file is enough. Themes, agents and key bindings stay exactly as they were.
Which models are available in OpenCode through ChatGPT API?
Everything we serve over the API: the GPT-5.6 family (sol, terra, luna) plus GPT-5.5, GPT-5.4 and GPT-5.4-mini. Switch models in the config or from inside OpenCode.
How is this different from an official OpenAI key?
Same models, same request format - only the base URL and the key change. The difference is price: the same tokens cost 50% less than official list price.
Can I keep the key in an environment variable?
Yes. Instead of a literal string in the config you can read the key from an environment variable, which keeps it out of a file that is easy to commit by accident.
Next steps
OpenCode is connected. Now pick the model that fits your work and see what it costs.