These examples use the website API host, which currently lists their recommended models. The direct API host can have a different catalog during rollouts. For larger requests or longer runtimes, use
https://api.nano-gpt.com/api/v1 with a model from that host’s catalog. See API Hosts for limits and availability checks.NanoGPT CLI Device Login Integration Guide
This guide explains how to integrate device login into your CLI application so users can authenticate without embedding a browser.Overview
The NanoGPT CLI device login flow works like the GitHub CLI or Claude Code login:- Your CLI requests a login code from NanoGPT.
- User opens a URL in their browser and signs in.
- User approves the CLI access.
- Your CLI receives an API key (
sk-nano-...).
Step 1: Start the login flow
Make a POST request to initiate login:Request body
Response
Step 2: Direct the user to approve
Display theverification_uri_complete URL to the user. They should open it in their browser.
Example output in your CLI:
- They sign in with their NanoGPT account (Google, Discord, etc.).
- They see the verification code and click “Approve”.
- They can close the browser and return to the CLI.
Step 3: Poll for approval
Poll the status endpoint until you receive the API key:Response codes
Polling example (bash)
Step 4: Use the API key
Once you have the API key, use it for all NanoGPT API requests. List available models:Complete integration example
API key management
- API keys created through this flow are named
CLI (<client_name>)in the user’s account. - Users can view and revoke keys at https://nano-gpt.com/api.
- If the same
client_nameis used multiple times, the existing key is reused. - Keys do not expire unless manually revoked.
Error handling
Security best practices
- Store the API key securely (OS keychain, encrypted config, or secure credential storage).
- Never log or display the
device_code. - Handle key revocation by prompting the user to re-authenticate on 401s.
- Use HTTPS only (
https://nano-gpt.com).