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:
curl -fsSL "https://nano-gpt.com/install/opencode_nanogpt.sh" | bash
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:
{
  "nanogpt": {
    "type": "api",
    "key": "your-nanogpt-api-key"
  }
}

2. Create the config file

Create ~/.config/opencode/.opencode.json:
{
  "model": "nanogpt/claude-sonnet-4-5-20250929",
  "provider": {
    "nanogpt": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "NanoGPT",
      "options": {
        "baseURL": "https://nano-gpt.com/api/v1"
      },
      "models": {
        "claude-opus-4-5-20251101": {
          "name": "Claude 4.5 Opus",
          "limit": { "context": 200000, "output": 32000 }
        },
        "claude-sonnet-4-5-20250929": {
          "name": "Claude Sonnet 4.5",
          "limit": { "context": 1000000, "output": 64000 }
        },
        "openai/gpt-5.2": {
          "name": "GPT 5.2",
          "limit": { "context": 128000, "output": 128000 }
        },
        "google/gemini-3-flash-preview": {
          "name": "Gemini 3 Flash (Preview)",
          "limit": { "context": 1048756, "output": 65536 }
        },
        "gemini-3-pro-preview": {
          "name": "Gemini 3 Pro",
          "limit": { "context": 1048756, "output": 65536 }
        },
        "zai-org/glm-4.7": {
          "name": "GLM 4.7",
          "limit": { "context": 200000, "output": 65535 }
        }
      }
    }
  }
}

Usage

After setup, start OpenCode:
opencode

Switching Models

Use the /model command inside OpenCode to switch between models, or edit the model field in your .opencode.json:
{
  "model": "nanogpt/claude-opus-4-5-20251101"
}

Available Models

The setup script preconfigures these models:
Model IDDescription
nanogpt/claude-sonnet-4-5-20250929Claude Sonnet 4.5 (default)
nanogpt/claude-opus-4-5-20251101Claude 4.5 Opus
nanogpt/openai/gpt-5.2GPT 5.2
nanogpt/google/gemini-3-flash-previewGemini 3 Flash (Preview)
nanogpt/gemini-3-pro-previewGemini 3 Pro
nanogpt/zai-org/glm-4.7GLM 4.7

Adding More Models

Add any of NanoGPT’s 250+ models to the models section in your config:
"models": {
  "zai-org/glm-4.7": {
    "name": "GLM 4.7",
    "limit": { "context": 200000, "output": 65535 }
  }
}
See all available models at nano-gpt.com/models/text.

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 (nanogpt).