How it works
When a request arrives authenticated with your AI Gateway API Key, the gateway selects a provider key for the target provider as follows:- Attached provider keys: if any are attached for the provider, they are used exclusively (this feature)
- Traffic Policy BYOK: provider keys in
providers[].api_keys—used only when no attached key exists for that provider - ngrok-managed keys: ngrok’s shared keys for OpenAI and Anthropic (requires credits)—used only when no attached or BYOK key exists for that provider
How keys are stored and shown
Provider keys are envelope-encrypted with AES-256 before being persisted. Plaintext exists only in memory for the duration of a single upstream request and is never written to disk or logged. Keys are shown exactly once at creation. The full key value is returned in the API response and dashboard exactly once, when you create it. Save it somewhere safe—if you lose it, delete the key and create a new one. Display form is redacted everywhere else. After creation, the key appears in the API and dashboard asfirst10***last4 for standard-length keys (or ***lastN for short keys, matching the Stripe “last 4” convention). The redacted form identifies the key without exposing it.
No update-in-place. There is no PATCH operation for a key value. To rotate, attach a replacement and delete the old key—see Rotating attached keys below.
When to use attached provider keys
Attach provider keys to your AI Gateway API Key when you:- Have your own provider accounts but want simpler setup than BYOK: no Traffic Policy changes, no secrets to configure
- Need providers beyond OpenAI and Anthropic: attached keys work with any supported provider
- Want to separate key management from gateway config: ops teams can manage keys independently from Traffic Policy deployments
- Need per-key provider routing: different API keys can have different provider keys attached, so teams can use isolated provider accounts
If you just need OpenAI and Anthropic and don’t have your own provider accounts, use AI Gateway API Keys with ngrok-managed keys—no setup required.
Attaching a provider key
Dashboard
- Navigate to AI Gateways in the dashboard.
- Select your gateway.
- Go to the API Keys tab and select the key you want to configure.
- Click Add Provider Key.
- Select the provider and paste your provider API key.
- Click Save.
CLI
API
Python
Attaching keys for multiple providers
Attach keys for as many providers as you need. Each provider is configured independently:You can attach up to 15 keys per provider to a single AI Gateway API Key. Requests beyond that return
ERR_NGROK_27506 (provider key limit exceeded). Most teams need 2–3 for failover and staged rotation.Rotating attached keys
To rotate a provider key without downtime:Attach the new key
Attach the replacement key alongside the existing one. The gateway tries the most recently attached key first, so the new key takes over immediately while the old key remains available as fallback.
Relationship with Traffic Policy BYOK
Attached provider keys and BYOK (Traffic Policyproviders[].api_keys) can coexist, but attached keys always win for a given provider:
| Provider config | What gets used |
|---|---|
| Attached key only | Your attached key |
| BYOK only | Your BYOK key |
| Both attached and BYOK | Attached key (BYOK is ignored for that provider) |
| Neither | ngrok-managed key (if available) |
| None of the above | Error |
Listing and removing attached keys
List
Remove
Next steps
- Migrate from Traffic Policy Keys: Step-by-step guide for moving existing BYOK config to attached keys
- AI Gateway API Keys: Overview of AI Gateway API Keys and how they work
- Bring Your Own Keys: Configure provider keys directly in Traffic Policy
- Managing Provider Keys (BYOK): Key rotation and management for Traffic Policy keys