Skip to main content

OpenCode Integration

Use NanoGPT with OpenCode, the open source AI coding agent for your terminal.

One-Click Setup (Mac/Linux)

Run this command in your terminal:
This will:
  1. Open your browser to authenticate with NanoGPT (or let you paste an API key)
  2. Configure OpenCode to use NanoGPT as your AI provider
  3. Set up popular models like Claude Sonnet 4.5, Claude 4.5 Opus, GPT 5.2, Gemini 3 Flash (Preview), Gemini 3 Pro, GLM 4.7

Manual Setup

If you prefer to configure manually:

1. Create the auth file

Add your NanoGPT API key to ~/.local/share/opencode/auth.json:

2. Create the config file

Create ~/.config/opencode/.opencode.json:

Usage

After setup, start OpenCode:

Switching Models

Use the /model command inside OpenCode to switch between models, or edit the model field in your .opencode.json:

Available Models

The setup script preconfigures these models:

Adding More Models

Add any of NanoGPT’s 250+ models to the models section in your config:
List available models with GET https://nano-gpt.com/api/v1/models.

Requirements

  • OpenCode installed (curl -fsSL https://opencode.ai/install | bash)
  • A NanoGPT account with API access

Troubleshooting

OpenCode not finding the config? OpenCode searches for config in this order:
  1. ./.opencode.json (current directory)
  2. $XDG_CONFIG_HOME/opencode/.opencode.json
  3. $HOME/.opencode.json
Authentication errors? Check that your API key is correctly set in ~/.local/share/opencode/auth.json (as an object with type and key) and that the key name matches the provider ID (nano-gpt).