Store provider keys in a profile
A profile is a named set of provider keys. An account holds up to 10 profiles and one is the default; a sandbox gets the default profile of its account. A profile holds up to 8 keys per provider; one is active, the others are ready to switch to.
Inside the sandbox the base URL points at the proxy,
https://api.styne.ai/ai-proxy/<provider>, plus /v1 for the providers that
put their API under it: ANTHROPIC_BASE_URL=https://api.styne.ai/ai-proxy/anthropic, OPENAI_BASE_URL=https://api.styne.ai/ai-proxy/openai/v1.
The key variable holds the placeholder, which starts with styne-ai-.
Keys are encrypted (AES-256-GCM, bound to your account) before they are stored. No call ever returns a key: a profile lists, per
provider, each key’s id, its hint (the last four characters) and whether it is active. A key you pass in the request body is not
logged anywhere.
Needs a role of owner or admin to change anything; every role except billing can read. The calls below use the account API at https://app.styne.ai, so $API is https://app.styne.ai. Send a signed-in session
token as $TOKEN, or an API key with /v1/key-api in front of the path ($API/v1/key-api/ai-credentials/profiles/default/keys/anthropic);
an API key acts as the member who created it and needs the ai.manage scope to change anything. The dashboard does the same. A stored
key reaches the sandbox regions within about 20 seconds.
Create a profile (it becomes the default when it is the first), add two keys, switch:
The proxy switch
The switch is per account and on by default. With it on, every sandbox created afterwards gets, for each provider the default profile holds a key for, a placeholder key and the proxy’s base URL in its environment, so the agents inside work without changes. An account whose default profile holds no key gets nothing added. A variable you pass yourself at create (or set in a stored environment) wins over the placeholder.ai_proxy_off), also the
sandboxes that were already running. Switch it on again with {"enabled":true}: sandboxes that already hold a placeholder work again, and a sandbox created
while it was off holds none.
How the proxy protects keys
-
The placeholder is random per sandbox; only its hash is stored. It is bound to that sandbox and works only while the sandbox
runs. At every call the proxy asks the sandbox’s node (a result is reused for 2 seconds at most):
- running: the call goes through;
- paused or stopped: refused with
403 sandbox_not_running; the placeholder is kept, so the same token works again once the sandbox runs again; - ended by timeout, crash, node loss or delete, or unknown to every node: refused with
401 invalid_placeholderand the placeholder is ended for good, so a token copied out of a sandbox is useless the moment the sandbox is gone; - the nodes cannot tell: refused with
503 proxy_unavailable, nothing is ended.
-
A key goes only to its own provider: the host behind
/ai-proxy/anthropic/...is fixed toapi.anthropic.com, whatever the request says. The key is put only in the provider’s own header (x-api-key,Authorizationorx-goog-api-key). Every other credential header the sandbox sends is dropped. -
When a provider answers
401or402to the active key, the proxy tries the profile’s next key of that provider with the same request, and returns the first answer that is not a refusal. This keeps a sandbox working when one account runs out of credit. The active flag you set is the first one tried; it is not changed by the retry. -
Replies stream through unchanged. The proxy reads the provider’s own
usagefields as they pass and keeps no content. - Request bodies up to 32 MiB are forwarded.
Read token usage
Per sandbox and provider the proxy counts requests, input and output tokens (from the provider’s usage fields; cached input counts as input) and refused or failed calls. Counters are kept for 40 days after their last change.Block a sandbox
403 ai_access_blocked from the proxy on its next call; unblock with {"blocked":false}.
Errors from the proxy
Provider answers, including their own errors, pass through unchanged.