Use an API key from an environment variable #
On this page
Send API calls through the gateway, even if your code already reads a provider key from a variable such as WEATHER_API_KEY. The gateway adds the stored key to the call. Bind the provider key to the variable only if you require the client to keep its fixed host, or the library fixes that host and gives you no way to set the gateway address.
Move the call to the gateway #
Find the stored key's name with
list_secrets, or store the key. In the manifest, look for the stored name in asecretvalue undersettings. For a key scoped to this application,list_secretsalso lists manifest bindings insettingsand the running copy’s bindings inapplied_settings.If you find a binding, supply the key again from your original source under a new stored name such as
WEATHER_UPSTREAM_KEY. The platform keeps the stored value private. If an upstream declaration returnsupstream_key_is_bound, itsdetailidentifies the binding, including one in a deploy, promote or redeploy in progress. Use a new stored name in that case too.Choose how your code will call the gateway.
Change the request. Build the URL from
TURNZERO_CLOUD_GATEWAY_URL(fall back toTURNZERO_CLOUD_API), then append/egress/v0/<upstream>and the provider's path. SendTURNZERO_CLOUD_APP_TOKENasAuthorization: Bearerand remove the read ofWEATHER_API_KEY. Keep the old binding while code that reads it is still running. See the request before and after.Keep the variable names. If the code or SDK reads its base URL and key from variables and sends the key as
Authorization: Bearer, put those variable names insdk_settings.base_urlandsdk_settings.keyon the upstream. The next deploy, promote, or restart gives the new copy the gateway URL and any egress key under those names. Replacing the provider key under its existing stored name takes effect on gateway calls. Remove any manifestsettingsentries for those variables as part of the change. See the SDK declaration.
Declare the upstream with the stored name as
credential_nameand anysdk_settingsyou chose. If the manifest owns the declaration, add it toupstreamsand submit the manifest with anysettingschanges. Otherwise, submit anysettingschanges first, then calldeclare_outbound_api. Deploy only after the declaration is in place.Deploy and call the route that uses the API. If you deploy to development first, check production after promotion. Keep the old host in
egressand keep the old stored key while a running copy or a deployment in progress still needs them. Keepsdk_settings.keywhile a running copy uses the upstream's egress key. Removing that setting ends the upstream's outstanding egress keys. Follow the rollout and cleanup steps.
Bind the key for a direct call #
Use these steps when your client meets either fixed-host condition above.
- Store the key for this application and the environment that will use it. If it is stored only at account scope, supply it again under a new name at application scope.
- In the manifest's
settings, set the existing variable name to an object such as{"secret": "WEATHER_PROVIDER_KEY"}, whereWEATHER_PROVIDER_KEYis the stored name. Add the provider host toegress. See how to bind a stored value. - Submit the manifest, deploy, and call the route that uses the key. Keep the key out of chat, source code, and logs.
Refusals #
| Refusal | Status | Cause | Remedy |
|---|---|---|---|
upstream_key_is_bound |
409 | A setting already uses the stored name in the manifest, a running copy, or a deploy, promote, or redeploy in progress. | Store the key under a new name and use that name as credential_name. |