> ## 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.

# Claude Code

> Use Claude Code with Claude and other models on NanoGPT

> [!NOTE]
>
> These examples use the direct API host, `https://api.nano-gpt.com`. It has no IPv6 address, so clients with only IPv6 should use `https://nano-gpt.com` with the same paths. See [API Hosts](https://docs.nano-gpt.com/api-reference/miscellaneous/api-hosts.md).

# Claude Code

> Use Claude Code with NanoGPT to access Claude and every other NanoGPT text model through a single API key.

> [!TIP]
>
> [Get started with NanoGPT](https://nano-gpt.com/api) for pay-as-you-go pricing with no monthly fees.

NanoGPT provides an Anthropic API-compatible endpoint that works seamlessly with Claude Code. This allows you to:

* Use Claude Code with your NanoGPT credits
* Access the real Claude models (Sonnet, Opus, Haiku)
* Optionally route to other models (GPT-4o, Gemini, DeepSeek, and more)

## Step 1: Install Claude Code

> [tab] Recommended Installation Method
>
> Prerequisites: [Node.js 18 or newer](https://nodejs.org/en/download/)
>
> ```bash theme={null}
> # Install Claude Code
> npm install -g @anthropic-ai/claude-code
>
> # Navigate to your project
> cd your-awesome-project
>
> # Start Claude Code
> claude
> ```

> [tab] Cursor Guided Installation Method
>
> If you are not familiar with npm but have Cursor, enter the command below in Cursor and it will guide you through the installation of Claude Code.
>
> ```
> https://docs.anthropic.com/en/docs/claude-code/overview Help me install Claude Code
> ```

> [!NOTE]
>
> **Note**: If you encounter permission issues during installation, try using `sudo` (macOS/Linux) or running the command prompt as an administrator (Windows) to re-execute the installation command.

## Step 2: Configure NanoGPT

**1. Get API Key**

* Go to [NanoGPT API](https://nano-gpt.com/api)
* Create an account or log in
* Copy your API key

**2. Configure Environment Variables**

Set up environment variables using one of the following methods:

> [!TIP]
>
> **Note**: Some commands show no output when setting environment variables. This is normal as long as no errors appear.

> [tab] One-Click Setup (Mac/Linux)
>
> Run this command in your terminal:
>
> ```bash theme={null}
> curl -O "https://nano-gpt.com/install/claude_code_nanogpt.sh" && bash ./claude_code_nanogpt.sh
> ```
>
> The script will prompt for your API key and automatically configure `~/.claude/settings.json`:
>
> ```json theme={null}
> {
>   "env": {
>     "ANTHROPIC_AUTH_TOKEN": "your_nanogpt_api_key",
>     "ANTHROPIC_BASE_URL": "https://api.nano-gpt.com/api",
>     "API_TIMEOUT_MS": "600000"
>   }
> }
> ```
>
> The installer now supports browser-based login. When the script starts, choose:
>
> 1. Browser login (recommended) - it will open a verification URL, wait for approval, and then save your key in `~/.claude/settings.json`.
> 2. Paste API key - manual fallback if you prefer.
>
> If a browser does not open automatically, copy the printed URL into your browser and approve the request.
>
> For more details on the browser login flow, see [CLI login](https://docs.nano-gpt.com/integrations/cli-login.md).

> [tab] Manual Configuration (All Platforms)
>
> **macOS & Linux**: Edit `~/.claude/settings.json` (create the file if it doesn't exist):
>
> ```json theme={null}
> {
>   "env": {
>     "ANTHROPIC_AUTH_TOKEN": "your_nanogpt_api_key",
>     "ANTHROPIC_BASE_URL": "https://api.nano-gpt.com/api"
>   }
> }
> ```
>
> **Windows Cmd**:
>
> ```cmd theme={null}
> setx ANTHROPIC_AUTH_TOKEN your_nanogpt_api_key
> setx ANTHROPIC_BASE_URL https://api.nano-gpt.com/api
> ```
>
> **Windows PowerShell**:
>
> ```powershell theme={null}
> [System.Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', 'your_nanogpt_api_key', 'User')
> [System.Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', 'https://api.nano-gpt.com/api', 'User')
> ```
>
> Replace `your_nanogpt_api_key` with your actual API key. A new terminal window is required for changes to take effect.

## Step 3: Start Using Claude Code

Once configured, start Claude Code in your terminal:

```bash theme={null}
cd your-project-directory
claude
```

> If prompted with "Do you want to use this API key," select "Yes."

Grant Claude Code permission to access files in your folder and you're ready to go.

***

## FAQ

### What Models Does This Use?

Claude Code sends its selected model ID to NanoGPT. To choose our current Claude recommendations explicitly, add these variables to the `env` section of `~/.claude/settings.json`:

```json theme={null}
{
  "ANTHROPIC_DEFAULT_OPUS_MODEL": "anthropic/claude-opus-5.5",
  "ANTHROPIC_DEFAULT_SONNET_MODEL": "anthropic/claude-sonnet-5.5",
  "ANTHROPIC_DEFAULT_HAIKU_MODEL": "anthropic/claude-haiku-latest"
}
```

| Claude Code Model | NanoGPT Routes To |
| - | - |
| Opus | Claude Opus 5.5 |
| Sonnet | Claude Sonnet 5.5 |
| Haiku | Claude Haiku 5.5 (adaptive thinking) |

These settings select the public NanoGPT model IDs shown above. Haiku Latest now uses Haiku 5.5 with a 1M-token context window and 128K maximum output. Its adaptive thinking defaults to medium effort. Existing configurations pinned to Haiku 4.5 keep using Haiku 4.5.

### Can I Use Other Models?

Yes. You can configure Claude Code to use different models by adding model mappings to your `~/.claude/settings.json`:

```json theme={null}
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "your_nanogpt_api_key",
    "ANTHROPIC_BASE_URL": "https://api.nano-gpt.com/api",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "openai/gpt-6.1-sol",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "anthropic/claude-opus-5.5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "google/gemini-flash-latest"
  }
}
```

Recommended models:

| Use Case | Recommended Model |
| - | - |
| Best overall | `openai/gpt-6.1-sol`, `anthropic/claude-opus-5.5` |
| Fast/cheap | `google/gemini-flash-latest` |

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

### Configuration Not Working?

If your configuration changes don't take effect:

1. **Restart Claude Code**: Close all Claude Code windows, open a new terminal, and run `claude` again
2. **Check JSON syntax**: Ensure your `settings.json` has valid JSON (no trailing commas, proper quotes)
3. **Reset configuration**: Delete `~/.claude/settings.json` and reconfigure from scratch

### How Do I Check My Configuration?

Run `/status` inside Claude Code to see your current model configuration.

### Recommended Claude Code Version

We recommend using the latest version of Claude Code:

```bash theme={null}
# Check current version
claude --version

# Upgrade to latest
claude update
```

NanoGPT is compatible with Claude Code 1.0.0 and newer.

### How Is This Different From Using Anthropic Directly?

| Feature | Anthropic Direct | NanoGPT |
| - | - | - |
| Pricing | Monthly subscription or API credits | Pay-as-you-go, no minimums |
| Models | Claude only | Claude and every other NanoGPT text model |
| Billing | Separate Anthropic account | Single NanoGPT account |
| Rate limits | Anthropic limits | NanoGPT limits |

### Need Help?

* Check your balance at [nano-gpt.com/balance](https://nano-gpt.com/balance)
* View API usage at [nano-gpt.com/usage](https://nano-gpt.com/usage)
* Create or manage API keys at [nano-gpt.com/api](https://nano-gpt.com/api)
* Contact support via the chat widget on [nano-gpt.com](https://nano-gpt.com)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.