> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nano-gpt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenCode

> OpenCode integration for NanoGPT

# OpenCode Integration

Use NanoGPT with [OpenCode](https://opencode.ai), the open source AI coding agent for your terminal.

## One-Click Setup (Mac/Linux)

Run this command in your terminal:

```bash theme={null}
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`:

```json theme={null}
{
  "nano-gpt": {
    "type": "api",
    "key": "your-nano-gpt-api-key"
  }
}
```

### 2. Create the config file

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

```json theme={null}
{
  "model": "nano-gpt/claude-sonnet-4-5-20250929",
  "provider": {
    "nano-gpt": {
      "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 }
        },
        "deepseek/deepseek-v4-pro": {
          "name": "DeepSeek V4 Pro",
          "limit": { "context": 1048576, "output": 384000 }
        },
        "deepseek/deepseek-v4-pro:thinking": {
          "name": "DeepSeek V4 Pro Thinking",
          "limit": { "context": 1048576, "output": 384000 }
        },
        "deepseek/deepseek-v4-flash": {
          "name": "DeepSeek V4 Flash",
          "limit": { "context": 1048576, "output": 384000 }
        },
        "deepseek/deepseek-v4-flash:thinking": {
          "name": "DeepSeek V4 Flash Thinking",
          "limit": { "context": 1048576, "output": 384000 }
        },
        "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:

```bash theme={null}
opencode
```

### Switching Models

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

```json theme={null}
{
  "model": "nano-gpt/deepseek/deepseek-v4-pro"
}
```

### Available Models

The setup script preconfigures these models:

| Model ID                                       | Description                 |
| ---------------------------------------------- | --------------------------- |
| `nano-gpt/claude-sonnet-4-5-20250929`          | Claude Sonnet 4.5 (default) |
| `nano-gpt/claude-opus-4-5-20251101`            | Claude 4.5 Opus             |
| `nano-gpt/openai/gpt-5.2`                      | GPT 5.2                     |
| `nano-gpt/deepseek/deepseek-v4-pro`            | DeepSeek V4 Pro             |
| `nano-gpt/deepseek/deepseek-v4-pro:thinking`   | DeepSeek V4 Pro Thinking    |
| `nano-gpt/deepseek/deepseek-v4-flash`          | DeepSeek V4 Flash           |
| `nano-gpt/deepseek/deepseek-v4-flash:thinking` | DeepSeek V4 Flash Thinking  |
| `nano-gpt/google/gemini-3-flash-preview`       | Gemini 3 Flash (Preview)    |
| `nano-gpt/gemini-3-pro-preview`                | Gemini 3 Pro                |
| `nano-gpt/zai-org/glm-4.7`                     | GLM 4.7                     |

### Adding More Models

Add any of NanoGPT's 250+ models to the `models` section in your config:

```json theme={null}
"models": {
  "zai-org/glm-4.7": {
    "name": "GLM 4.7",
    "limit": { "context": 200000, "output": 65535 }
  }
}
```

List available models with `GET https://nano-gpt.com/api/v1/models`.

## Requirements

* [OpenCode](https://opencode.ai) 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`).
