Skip to main content

Overview

BYOK (Bring Your Own Key) lets you store API credentials for supported upstream providers and route API text requests through your own keys: per request, by default for your account or for one API key (see Use saved keys by default), or exclusively for a model (see Exclusive keys). Page reading keys work differently: once saved, they are used automatically (see Page reading keys). Typical reasons to use BYOK:
  • Your provider bills you directly (enterprise agreements, committed-use discounts, free tiers).
  • You want NanoGPT routing + enhancements, without using NanoGPT platform keys.

Availability

BYOK is supported on:
  • POST /api/v1/chat/completions
  • POST /api/v1/responses and POST /api/v1/messages. They run through Chat Completions and accept the same headers, byok body field and defaults.
Responses requests that need OpenAI’s native Responses API (for example hosted tools such as web search or code interpreter, computer use, or stored native history) can only run on a saved OpenAI key (openai or openai-responses). They use it when the request sends x-use-byok: true or byok.enabled: true, when the API key’s default is only, or under Prefer BYOK (the account’s, or a per-key prefer default; see Use saved keys by default). When the request asks for BYOK or the key’s default is only, there is no credit fallback: if the key fails, the request fails. Prefer BYOK tries your saved OpenAI key first, and runs the request on credits when there is none or the key fails with a retryable error before anything is returned. With x-byok-fallback-to-credits: false it uses only your saved key, as on Chat Completions: no saved key, or a request that can’t run on one, fails with code byok_credentials_missing instead of running on credits. Without that header, Prefer BYOK doesn’t apply to flex-tier streams or explicit prompt caching, which run on credits; explicit prompt caching with x-byok-fallback-to-credits: true (or byok.fallbackToCredits: true) fails with code prompt_cache_funding_fallback_unsupported. Zero Data Retention requests use a saved key only when the request asks for BYOK. A response that fell back to credits carries the x-nanogpt-byok-fallback header; for a background request, GET /api/v1/responses/{id} returns it once the request has finished. Team-billed requests follow the team’s BYOK settings. Native requests on other models, such as Qwen with built-in tools, never run on a saved key: asking for one (including an only default) fails with code byok_provider_not_supported. Under Prefer BYOK they run on credits, unless the request sends x-byok-fallback-to-credits: false: then they fail with code byok_credentials_missing. These never run on a saved key: POST /api/v1/completions (a redacted request runs through Chat Completions and follows its rules), batches, Private Mode and Decision models. Page reading keys are also used by chat in the web app, scraping on POST /api/v1/chat/completions, POST /api/scrape-urls and POST /api/v1/data/url/scrape.

Pricing

When you use BYOK:
  • Your provider bills you directly for usage on their side.
  • NanoGPT charges a 5% platform fee on top for routing and platform features.
Page reads served by your own key are free on NanoGPT; your crawler provider bills you directly. No platform fee applies to them.

Configure Keys

Web UI

Manage BYOK keys in the NanoGPT web app: Keys are never shown again after saving (only a short suffix is displayed), so treat them like passwords.

API (NanoGPT key required)

API keys can list and remove saved provider keys, and change two routing settings: an API key’s BYOK default and a saved key’s exclusive setting (not OpenAI-compatible):
Adding or replacing a key and changing a ZDR declaration require the web app. If your account has a sign-in factor, sign in with an identity linked to the account and confirm it’s you. Guest accounts with no sign-in factor can continue using their session. API-key POST requests, and PATCH requests with neither an apiKeyByokMode nor an exclusive field, return HTTP 403 with code owner_login_required, including restricted API keys. DELETE remains available so scripts can quickly remove a leaked provider key. Example: remove a provider key
Key additions, replacements, removals and ZDR declaration changes send a security notice to the account’s stored email addresses, when available.

Use BYOK On A Request

Enable BYOK

Option A: request header
Option B: request body

Select a provider (optional)

If the model can route through multiple providers, you can force a specific provider. Header:
Body:

Fallbacks (optional)

BYOK defaults to fail-fast behavior. If your provider key fails, NanoGPT will not silently route the request through a different provider key. You can control this via the request body:
To let a BYOK request continue on credits when your key fails with a retryable error, send x-byok-fallback-to-credits: true (or byok.fallbackToCredits: true). Send false to keep a request on your key even when a default below would fall back. Responses requests that need OpenAI’s native Responses API fall back to credits only under Prefer BYOK (see Availability).

Use Saved Keys By Default

You don’t have to send x-use-byok on every request.

Account default: Prefer BYOK

Turn on Prefer BYOK for API requests at https://nano-gpt.com/byok. API text requests then try your first compatible saved key before NanoGPT’s capacity. If no key matches, or the attempt fails with a retryable error, the request continues on credits at normal prices, after the normal balance checks. Send x-byok-fallback-to-credits: false to keep one request on your key, or x-use-byok: false (byok.enabled: false) to skip BYOK for one request.

Per-API-key default

Each NanoGPT API key can have its own default, which replaces the account default for requests made with that key: A request’s own x-use-byok header or byok.enabled field always wins. Under only, x-byok-fallback-to-credits: true restores the credit fallback for that request, except on requests that need the native Responses API. A key without a default follows the account default, so nothing changes until you set one. only applies where BYOK does (see Availability). Decision model and Advisor requests fail under it, as they do with x-use-byok: true, and so do Fusion requests: code fusion_byok_unsupported with fusion on Chat Completions, and code fusion_failed with the same message on /api/v1/fusion/completions. Send x-use-byok: false to run one on credits. Endpoints that never run on a saved key ignore it; to keep a model off credits everywhere, mark the key exclusive (below). Set or clear a key’s default with your own API key (connected apps can’t change it), or from a signed-in session on /api/user/provider-keys/session:
  • apiKeyId is the key’s numeric id, the id the Management API lists for it.
  • mode is off, prefer or only; null removes the key’s default.
  • GET /api/user/provider-keys returns the defaults as apiKeyByokModes, keyed by API key id.
  • Revoking an API key removes its default.

Exclusive Keys

Mark a saved key exclusive (“use only this key”) to run its models only on that key. An API request for a covered model then uses the key even without x-use-byok (with two Responses exceptions, below). If the key is missing, fails or can’t serve the request, the request fails: it never falls back to credits or to another provider, whatever fallback the request asks for. Requests the key serves are normal BYOK requests (see Pricing). Chat in the web app isn’t affected. A key covers every model it can serve, or only the models you list (up to 50). A listed model also covers its variants, such as :thinking; a listed variant covers only itself. Turn it on or off with your own API key (connected apps can’t change it):
  • Leave out exclusiveModels (or send null) to cover every model the key can serve. Each update replaces the key’s previous setting.
  • Send "exclusive": false to turn it off. Removing the key also clears it.
  • The body takes only provider, exclusive and exclusiveModels; any other field returns HTTP 400.
  • Save the key first: turning it on for a provider without a saved key returns HTTP 400 with code byok_exclusive_key_missing.
  • The response, and each key in GET /api/user/provider-keys, show exclusive and exclusive_models (null when the key covers every model).
  • On https://nano-gpt.com/byok, the Use only this key for API requests checkbox on a saved key turns it on for every model the key serves, or off.
A covered request that can’t run on the key is refused before anything is charged: Two kinds of Responses requests use an exclusive key only when they send x-use-byok: true or come from an API key whose default is only, and are refused with byok_exclusive_unsupported otherwise:
  • background requests (background: true)
  • requests that need OpenAI’s native Responses API (for example hosted tools, computer use, or stored native history), which also need the exclusive key to be a saved OpenAI key
Answers an exclusive key served, and most refusals, carry an x-nanogpt-byok-exclusive header naming the key’s provider. If your client has its own fallback chain, stop it on that header or on any byok_exclusive_* error code. Team-billed requests under an active team BYOK policy follow the team’s policy instead.

Provider Slugs

The exact set of supported providers can evolve; the BYOK UI lists what your account can configure.

Chat / completion providers

These providers can be used for BYOK on POST /api/v1/chat/completions: Notes:
  • AWS JSON can also include sessionToken.
  • Azure-style providers require provider-specific endpoints and identifiers (for example, a deployment name).
  • If you want to force Google AI Studio routing for Gemini models, set x-byok-provider: google (or byok.provider: "google").
  • Additional provider options may appear over time in the BYOK UI and provider-discovery endpoints.

Web-search-only providers

These providers are BYOK for web search enhancements, not chat model execution:

Page reading providers

These providers read web pages for URL scraping, not chat model execution:

Page Reading Keys

Save a Firecrawl, Berrycrawl or Linkup key at https://nano-gpt.com/byok, and NanoGPT reads pages with it. You don’t need x-use-byok or byok.enabled. Which key a page read uses:
  • Standard reads use your Berrycrawl or Firecrawl key. If you saved both, NanoGPT tries one and falls back to the other, both on your keys.
  • PDFs and documents are parsed with your Firecrawl key. In web app chat and on /api/scrape-urls, a document URL fails if you saved only a Berrycrawl key, with a message asking you to add a Firecrawl key.
  • Stealth mode (stealthMode: true) uses your Firecrawl key. Without one, stealth reads use NanoGPT’s Firecrawl key and are billed as usual.
  • Linkup keys are used only when Linkup is the selected page reader: provider: "linkup" on /api/scrape-urls, or scraping: { "enabled": true, "provider": "linkup" } in chat.
If you have no key for a read, NanoGPT reads the page with its own key and bills it as usual.

No fallback to NanoGPT keys

Your key replaces NanoGPT’s. If a page can’t be read with your key, for example because your provider account is out of credits, that URL fails; NanoGPT does not retry it with a paid key. If a saved key can no longer be read, the request fails with HTTP 409 and code byok_credential_unreadable. Save the key again on the BYOK page or remove it.

Balance and spending limits

Balance checks and API key spending limits don’t count page reads your own key will serve. Request limits still apply, and model usage in chat is billed as usual.

When your keys are not used

  • Zero Data Retention: requests that require ZDR always read pages with NanoGPT’s Linkup key under NanoGPT’s ZDR agreement, never with your keys.
  • x402 payments: requests paid with x402 never use saved keys.
  • Per chat request: send scraping: { "enabled": true, "byok": false } to read pages with NanoGPT’s keys for that request. On /api/scrape-urls, remove the key to stop using it.

Teams

Team-billed requests use the team’s saved page reading keys when the team has BYOK enabled (prefer_team or require_team). A member’s personal key never serves a team-billed request. Without a matching team key, team-billed page reads use NanoGPT’s keys and are billed to the team as usual, in every team BYOK mode.
Saving a Berrycrawl key runs one test page read with it, which uses one Berrycrawl credit. Firecrawl and Linkup keys are checked without using credits.

Teams (BYOK)

Teams can also store provider keys and configure whether team-billed traffic should use team keys. Team settings endpoints (session-authenticated, not OpenAI-compatible):
Team key additions, replacements and ZDR changes require the acting member’s account confirmation under the same rule. Key changes notify the team owner’s stored email addresses. Existing team permissions still apply. BYOK modes:
  • disabled: BYOK off for the team.
  • prefer_team: use a team key when available; otherwise fall back to normal routing.
  • require_team: fail requests when no team key exists for the required provider.
Important behavior:
  • In prefer_team mode, team-billed traffic will not use a member’s personal BYOK keys unless the client explicitly opts in to BYOK on the request.

Security Notes

  • Never put provider keys in client-side code or public repos.
  • Store keys once in the web app, then enable BYOK per request or with a default.