Overview
NanoGPT supports authorization-code OAuth with PKCE for public clients. The returned credential is a dedicated NanoGPT API key insk-nano-... format, scoped to the approved app/user grant.
Use the returned key as a bearer token against the OpenAI-compatible API:
Choose a Flow
All three flows return the same kind of credential: a dedicated NanoGPT API key.
Discovery
Authorization server metadata:Scopes
For this MVP, OAuth requests must include
api.use because the returned access token is a spend-capable API key.
Recommended scope:
PKCE Requirements
NanoGPT requires S256 PKCE.code_challenge_methodmust beS256.plainis rejected.code_verifiermust use RFC 7636 characters:A-Z,a-z,0-9,-,.,_,~.code_verifierlength must be 43 to 128 characters.code_challengemust be base64url-encoded SHA-256 of the verifier.- Authorization codes expire quickly and are one-time use.
Redirect URI Rules
Allowed redirect URIs:- HTTPS redirect URIs.
- Loopback HTTP redirect URIs with an explicit port, such as
http://127.0.0.1:8787/callback,http://localhost:8787/callback, orhttp://[::1]:8787/callback.
- Wildcards.
- URL fragments.
- Credentials in URLs.
- Non-HTTPS web redirects.
- Loopback HTTP without an explicit port.
- Redirect URIs that do not exactly match the registered or callback URI.
127.0.0.1 internally.
Shortcut Key Handoff
Use this flow for local apps and clients that want the shortest browser sign-in integration.1. Generate PKCE
Generate:code_verifiercode_challenge = base64url(sha256(code_verifier))state
2. Redirect to NanoGPT
Send the user to:
Example:
3. Handle the Callback
On approval:4. Exchange the Code
grant_type is optional. If present, it must be authorization_code. Form-encoded bodies are also accepted.
Success response:
key or access_token; they contain the same value.
Standard OAuth PKCE
Use this flow for generic OAuth clients that want explicit dynamic registration and standard OAuth endpoint names.1. Register the Client
client_nameredirect_uris
grant_types, defaults to["authorization_code"]response_types, defaults to["code"]token_endpoint_auth_method, defaults tononeclient_uri, must be HTTPS and have no fragmentlogo_uri, must be HTTPS and have no fragment
2. Redirect to the Authorization Endpoint
Example:
3. Handle the Callback
On approval:4. Exchange the Code
grant_type=authorization_codeclient_idredirect_uricodecode_verifier
Authenticated Downstream Key Code
An already authenticated app can create a one-time authorization code for a downstream local app.redirect_uriorcallback_urlcode_challenge- Authenticated source API key in the
Authorizationheader
code_challenge_method, defaults toS256scope, defaults toapi.use models.readkey_labelorkey_namelimitusage_limit_type:daily,weekly, ormonthly; defaults tomonthlywhenlimitis presentexpires_atclient_name,app_name, ornamex-titleorx-app-nameheaders as fallback app names
- The source API key must be active.
- The source API key must be linked to a signed-in NanoGPT account.
- OAuth-issued API keys cannot create further OAuth key codes.
- Source keys with existing spend, request, model, provider, origin, or redaction restrictions are rejected for this flow.
- If the source key has an expiration, the downstream key cannot outlive it.
Use the Returned Credential
List models:GET /api/v1/modelsGET /api/v1/image-modelsGET /api/v1/video-modelsGET /api/v1/audio-modelsPOST /api/v1/chat/completionsPOST /api/v1/responsesPOST /api/v1/messages
Token and Key Behavior
The OAuthaccess_token is a dedicated NanoGPT API key in this MVP.
Implications:
- It is long-lived unless an expiration is set.
- It can spend from the user’s NanoGPT balance.
- It should be stored like a password.
- It should not be logged or exposed in browser-visible HTML.
- It can be revoked by deleting or disabling the API key in NanoGPT settings.
- The same active grant can reuse the same key when settings are unchanged.
- New app-specific limits or expiration can force a new dedicated key.
$0 cap blocks paid spend for that app. Leaving the cap empty means no app-specific cap.
Browser/web OAuth keys are tied to origins derived from the redirect URI when applicable. Loopback keys allow common loopback origins for the chosen callback port.
Revocation
NanoGPT does not expose an OAuth revocation endpoint in this MVP. Users revoke access by deleting, disabling, expiring, or limiting the generated API key in NanoGPT settings. Client behavior:- If a stored key starts returning
401, discard it. - Ask the user to sign in again.
- Do not keep retrying a revoked key.
Errors
OAuth JSON errors use this shape:Rate Limits and Abuse Controls
OAuth endpoints are rate-limited. Developers should:- Avoid repeated failed token exchanges.
- Restart the flow after an
invalid_grant. - Never reuse authorization codes.
- Never log raw authorization codes, code verifiers, or API keys.
Local App Example
Example source:/auth, exchanges the code at /api/v1/auth/keys, calls /api/v1/models, and masks the key in terminal output.