Provider key management (BYOK)
Bring Your Own Key (BYOK) lets you store provider API keys encrypted inside the gateway rather than embedding them in configuration files. The gateway encrypts each key at rest and decrypts it on demand when forwarding upstream requests.
Key storage and encryption
Provider API keys are stored encrypted in the gateway database using AES-256-CBC plus HMAC-SHA256 for integrity. The encryption passphrase is held outside the database, configured by Myra for your deployment. A stored key value is never returned to the SPA; the list endpoint returns only the alias and metadata.
Key identity model
Each stored key is uniquely identified by the combination of:
gateway_id— the gateway the key is bound to (ortenant_idwhen stored at tenant level).provider— the provider identifier (for exampleopenai,anthropic,bedrock).alias— a label for the key. The default value isdefault.
Tenant-level keys serve administrative and usage-synchronisation tasks (for example the Anthropic Admin API usage feed); they are not consulted on the inference path. Inference always uses the key stored on the gateway itself for the requested provider — there is no fall-through from a gateway to a tenant-level key. See Tenants and gateways API.
There is one other key source: a Myra-provided model that you enable under Add Model → Use Platform Key. When the gateway has no own default key for that provider, such a model uses Myra's managed key, and the usage is charged to the workspace wallet. Your own key is always preferred: enabling a Myra-provided model never moves the spend of an existing own key to Myra's key. A Myra key is never used for a provider whose endpoint your gateway redirects to an endpoint you control.
The Use Platform Key page judges each Myra-provided model for this gateway before you click. A model it cannot enable shows the reason instead of an Enable button: Not available on this platform (the Myra model pool is not set up, or the model has no price yet), Not included in your plan, Not allowed by this gateway's provider, residency or endpoint settings, or Cannot be enabled when the gateway's configuration could not be read. An already enabled model keeps its Disable button. A model used with Myra's key is charged to the wallet at the provider's list price plus the platform margin (see Provider costs).
Which key a leg uses
One rule decides the key for every call the gateway makes on your behalf: the main request, fallback legs, agent tool calls, chat file uploads and chat feedback summaries. On a self-serve workspace Anthropic is served by the shared Myra key and a key stored on the gateway for Anthropic is never read; self-serve workspaces hold no own provider keys (see below). Otherwise your own key for that provider is used; only when you have none and a Myra-provided model is enabled does the gateway fall back to Myra's key. This holds for a fallback leg or an agent step on another provider too: it is allowed under the same rules as a normal request (model enabled or in your plan, wallet check, cost charged to the wallet). If the shared key is not configured on the platform, the request fails with a configuration error instead of using another key. A request that names an alias other than default never falls back to Myra's key.
Self-serve plans hold no own provider keys
A workspace on a self-serve plan (self_serve_*, trials included) cannot store its own provider keys. Models are served by the shared Myra key and billed to the wallet. On such a workspace:
- Add Model opens on Use Platform Key. Use My Own Key shows a notice and a Discuss requirements link to the enterprise contact page instead of the key form.
- The Provider Keys card stays visible but lists no own-key rows; keyless rows (
myra,mock) and Myra-provided models still show, and Add Model stays available. The pool gateway is not affected. - Storing a key through the API (gateway or tenant scope) is rejected with
400andcode: "own_key_not_available_on_plan"(fieldprovider). Theerrortext is not shown in the UI; the SPA renders its own localized message. - Changing a workspace onto a self-serve plan deletes the own keys it had stored (one audit row per key, reason
plan_change_self_serve). See Plan configuration.
To use your own keys, use Discuss requirements to talk to Myra about moving to a plan that includes them.
Multiple keys per provider
Multiple keys for the same provider on the same gateway coexist under different aliases. The mechanism supports zero-downtime rotation and per-flow key selection.
To select a non-default alias on a specific inference request, send the x-aig-byok-alias header:
curl "https://<your-gateway-host>/v1/<TENANT>/<GATEWAY>/openai/chat/completions" \
-H "Authorization: Bearer <TOKEN>" \
-H "x-aig-byok-alias: backup" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-4o", "messages": [{"role":"user","content":"Hi"}]}'
💡 Note: How the gateway reads the
x-aig-byok-aliasheader:
- Accepted shape: 1 to 64 letters, digits,
.,_or-, starting with a letter or digit (the same rule as the alias on a stored key).- Malformed: anything else is rejected with
400byok_alias_invalid. It is never treated like an absent header. The check runs before the response cache, so a cached answer is never returned for a malformed alias.- Whitespace: surrounding spaces and tabs are trimmed, so a header of only spaces and tabs counts as empty (the
defaultalias). A space or tab inside the value is rejected with400byok_alias_invalid.- Repeated header: a header sent more than once is joined (
a, b) and rejected with400.- Empty or absent: an empty header is the same as sending no header: the
defaultalias.- Letter case:
defaultin any letter case (Default,DEFAULT) is thedefaultalias.- Unknown alias: a well-formed alias that matches no stored key is rejected with
424provider_key_missing. The gateway does not silently fall back to thedefaultalias or to Myra's key, because that would spend a different key than the one you requested.- Rejected key: if the provider answers your own key with
401(or a403authentication refusal, not a model-entitlement refusal), the request fails with424provider_key_rejectedanderror.provider. The gateway makes one call, does not retry or fail over, and never switches to Myra's key; nothing is charged. Replace the key under the gateway's provider settings.- Self-serve workspaces: where Anthropic is served by the shared Myra key, the header is still validated but does not select a key.
- Cached answers: a request whose answer is served from the response cache (exact-match or semantic) reads no key at all, so a well-formed alias with no stored key can still receive a cached answer.
Per-provider key formats
Most providers accept the API key as a single string. Two providers expect a structured value in the API Key field:
-
AWS Bedrock — colon-delimited credentials. See AWS Bedrock.
-
Vertex AI — a Google Cloud service-account JSON key. The gateway signs a JWT with the service account's private key and exchanges it for a short-lived OAuth2 access token (RFC 7523 JWT-bearer). See Google Vertex AI.
For every other provider, paste the provider's API key string as-is.
Adding a BYOK key

Proceed as follows to add a BYOK key:
- Open Organisation → AI setup → Gateways (via the user-block menu at the bottom of the left sidebar). (A separate Platform › Models & providers › Providers page, platform-admin-only, also holds provider key + status config.)
- Click on the Open → button of the gateway.
- The gateway page opens on the Endpoint & keys tab.
- Locate the Provider Keys card.
- Click on the Add Model button.
- The Add Model page opens. Choose Use My Own Key (
…/models/new); Use Platform Key (…/models) enables Myra-provided models without a key of your own.
- The Add Model page opens. Choose Use My Own Key (
- Select the provider in the Provider drop-down list. The list is populated from
GET /admin/v1/providers. - Enter the alias in the Alias text field. Leave the value as
defaultfor the primary key. - Paste the API key in the API Key field. For providers that do not require a key, the field is hidden and a hint reads This provider does not require an API key.
- Click on the Store Key button.
-> The key is stored encrypted, the page displays Key stored and encrypted successfully., and the new alias appears in the Provider Keys card.
💡 Note: Posting again with the same
(provider, alias)rotates the stored value. The previous value is replaced.
The Provider Keys card lists each stored key with the columns Provider, Alias and Added. Below it, the Platform models table lists the Myra-provided models enabled on this gateway and the Myra-hosted fleet, with the Source column: Myra-hosted, Myra key (charged to wallet) or Included in your plan. For a granted model the label follows the key that actually serves it: Your key (billed by <provider>) when the gateway's own default key for that provider is used (the provider bills you directly; a key stored only under another alias does not count), Myra key (charged to wallet) when the Myra key is used, and Key source unavailable when the server could not decide. A plan-included model always runs on the Myra key (Included in your plan), or reads Key source unavailable when the server could not decide. A stored default key also serves every model of its provider: those models appear in the model picker without any entry under Platform models, the provider bills them, and nothing is charged to the wallet for them (no platform markup); they do not count against budget limits either. The Provider Keys card says so under the key table. This is also the route for an Enterprise tenant, which has no plan-included models: store the customer's own key with Add Model, then Use My Own Key. Data-residency settings can still exclude a provider. Do not add a platform-model grant for a provider the customer's own key already covers: if that key is later removed, the granted model keeps working on Myra's key and is charged to the wallet.
Deleting a BYOK key
Proceed as follows to delete a BYOK key:
- Open Organisation › AI setup › Gateways and the gateway page (tab Endpoint & keys).
- Locate the Provider Keys card.
- Click on the Delete action in the row of the key.
-> The key is removed immediately. Subsequent requests that resolve to the deleted (provider, alias) fail until a replacement key is stored — however they spell the alias: aliases are matched case-, accent- and trailing-space-insensitively, and the gateway's short-lived key cache follows the stored key, not the spelling, so deleting default also stops Default (and a replaced key is used for every spelling). The gateway instance that handles the delete drops the key from its cache at once. Each gateway instance keeps its own key cache, though, so another instance that already holds the key can keep using it until its cache entry expires, at most the key cache lifetime (byok_cache_ttl, default 60 s) after the delete. That other instance is the previous release while a deploy switches over (it finishes its in-flight requests for up to 15 minutes), or another site of a deployment that runs several sites side by side. The same holds for a replaced key: another instance can use the previous value for up to that long. A request that is already running when you delete or replace the key can finish with the key it started with, on any instance. To be sure a leaked key is useless, also revoke it at the provider. The gateway does not auto-substitute another alias, and there is no tenant-level fallback on the inference path — to use a different key, request its alias explicitly with the x-aig-byok-alias header.
⚠️ Caution: Deleting the
defaultkey for a provider causes every request that does not specify an explicit alias to fail until a replacement key is stored.
Storing keys via the API
Both gateway-scoped and tenant-scoped key storage is available via the admin API. See Tenants and gateways API for the endpoints and request bodies.
See also
- BYOK — what BYOK is and why
- Provider authentication
- Gateways
- Fallback and retry
- Providers overview