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

# Authentication

> How to authenticate with the NanoGPT API and web app.

## Usage monitoring and API-key management

For subscription quota monitoring, create a **Usage only** [management token](https://docs.nano-gpt.com/api-reference/management-api.md) in Settings → Security. It can read usage without permission to run models or spend your balance.

Management tokens begin with `sk-nano-mgmt-` and authenticate only `/api/management/v1` endpoints. Their permissions are separate from inference API keys. Use only `usage:read` for a monitoring tool; `api_keys:write` can create spending-capable inference keys.

## API Authentication (Recommended for inference)

Most integrations should use an **API key**.

Send API-key requests to `https://api.nano-gpt.com`. Create and manage keys on the [NanoGPT website](https://nano-gpt.com/api); see [API Hosts](https://docs.nano-gpt.com/api-reference/miscellaneous/api-hosts.md) for the correct client base URL.

### API key format

New keys use the format:

```text theme={null}
sk-nano-<uuid>
```

Some older accounts may still have **legacy** keys (a plain UUID). Both formats are accepted.

### Send your key (headers)

Use one of these headers on inference API requests:

1. `Authorization: Bearer <API_KEY>` (recommended)
2. `X-API-Key: <API_KEY>`

Example:

```bash theme={null}
curl "https://api.nano-gpt.com/api/v1/models" \
  -H "Authorization: Bearer sk-nano-YOUR_API_KEY"
```

### Common errors

* `401 Unauthorized`: Missing/invalid/revoked API key (or your key is inactive/expired, if your account has expiration enabled)
* `403 Forbidden`: API key browser-origin restriction failed (`api_key_origin_not_allowed`)
* `403 Forbidden`: the request came from an IP address that is not on the key's Allowed IPs list (`api_key_ip_not_allowed`). See [Allowed IPs](#allowed-ips)
* `429 Too Many Requests`: Rate limit exceeded (per-second throughput, or a per-key daily cap if configured), or `authentication_rate_limited` when this key was rejected repeatedly. The authentication throttle is per key, not per IP; fix the key and honor `Retry-After` (see [Error Handling](https://docs.nano-gpt.com/api-reference/miscellaneous/error-handling.md#authentication-rate-limiting))

For rate-limit details, see [Rate Limits](https://docs.nano-gpt.com/api-reference/miscellaneous/rate-limits.md).

### Allowed IPs

You can limit an API key to the IP addresses you call from. Open the key's settings on [https://nano-gpt.com/api](https://nano-gpt.com/api) and fill in **Allowed IPs**: one IPv4 or IPv6 address or CIDR range per line (for example `203.0.113.7` or `2001:db8::/48`), up to 20 entries. Leave the field empty to allow any IP; that is the default.

A request with that key from any other address is refused with `403` and `error.code` `api_key_ip_not_allowed`, before anything is charged. The address that counts is the public IP NanoGPT sees: behind a proxy, VPN, NAT or a hosted platform, that is the egress address of that network, not your machine's local address.

To fix the error, the key owner adds the address (or its range) to the key's Allowed IPs, or clears the field to remove the restriction. Retrying from the same address without changing the list fails the same way.

### Getting an API key

Create and manage API keys in the NanoGPT dashboard: [https://nano-gpt.com/api](https://nano-gpt.com/api)

## CLI Authentication (Device Login)

If you're building a CLI, use **device login** so users can approve access in a browser and your CLI receives an API key (`sk-nano-...`).

See: [CLI Device Login](https://docs.nano-gpt.com/integrations/cli-login.md)

## OAuth PKCE (Sign in with NanoGPT)

If you're building a third-party app, local tool, coding agent, or generic OAuth client, use **OAuth PKCE** so users can approve access in NanoGPT instead of manually creating and pasting an API key.

OAuth returns an app-specific NanoGPT API key (`sk-nano-...`) that your app sends as:

```http theme={null}
Authorization: Bearer sk-nano-...
```

You can also attach your referral link, so users who create a NanoGPT account through your sign-in are referred by you. See [Referral Attribution](https://docs.nano-gpt.com/api-reference/miscellaneous/oauth-pkce.md#referral-attribution).

See: [OAuth PKCE](https://docs.nano-gpt.com/api-reference/miscellaneous/oauth-pkce.md)

## Web App Sign-In (Browser)

If you are using the NanoGPT web app, sign-in is handled via browser sessions. Supported sign-in methods include:

* OAuth (GitHub, Google)
* Email one-time code (magic link / verification code)
* Email/password (or username/password, where supported)
* Passkey (WebAuthn)

If you are calling the API from a backend service, prefer API keys instead of relying on browser cookies.

## API Key Security Best Practices

* Store keys in environment variables (for example: `NANOGPT_API_KEY`).
* Never commit keys to git or ship them in client-side code.
* Prefer `Authorization: Bearer ...` over putting keys in URLs.
* For browser-based apps, set **Allowed browser origins** when creating the API key so the key is only accepted from your app's origin. Prefer backend calls or OAuth PKCE when possible; do not embed unrestricted API keys in client-side code.
* Use separate keys per app/environment so you can revoke access without breaking everything.
* Set spending and request limits (if available for your account) to cap blast radius.


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