Using

Provider credentials#

Save each provider's API key on the gateway once, and every workspace can call that provider's models with the API keys you issue.

  1. Open Providers and choose + Add key, or Add key on the provider's row.
  2. Under Provider, select the provider. Choose a Configuration method when the provider offers a choice.
  3. Enter the credential and any required settings, then choose Save key.

The provider's row reads Stored in the gateway and, for the selected workspace, Connected.

The Providers page with OpenAI, Anthropic and Google connected

You need: an organisation Owner or Admin account, and an API key from the provider.

The path names the credential. jq reads the provider key from the environment, and curl reads the admin header from a pipe. This keeps both keys out of process arguments.

Shell
jq -n '{ value: env.OPENAI_API_KEY }' \
  | curl -sS -X PUT "$TOKEDEX_URL/control/keys/OPENAI_API_KEY" \
      -H @<(printf 'Authorization: Bearer %s\n' "$TOKEDEX_ADMIN_KEY") \
      -H "Content-Type: application/json" \
      --data-binary @-
JSON
{"name":"OPENAI_API_KEY","set":true}

You need: Bash, curl, jq, an exported OPENAI_API_KEY, an admin key with the credential-admin or admin preset in TOKEDEX_ADMIN_KEY, and export TOKEDEX_URL='http://127.0.0.1:4000'.

The replica that saves a key uses it at once. Other replicas pick it up by polling the shared configuration. Saving a key needs no restart.

Credential names#

The Env-var name column on Providers names each provider's credentials and settings, such as GEMINI_API_KEY for Google. Providers that share a key share a row. Public settings such as a region show their values in the table.

GET /control/keys lists provider bindings and their sources. A public setting includes its setting.label and setting.value. The response hides credential values. This example shows two entries with providerInfo omitted.

Shell
curl -sS "$TOKEDEX_URL/control/keys" \
  -H @<(printf 'Authorization: Bearer %s\n' "$TOKEDEX_ADMIN_KEY")
JSON
[
  { "name": "ANTHROPIC_API_KEY", "source": "unset", "providers": ["anthropic"] },
  { "name": "OPENAI_API_KEY", "source": "store", "providers": ["openai"] }
]

Check which providers are connected#

Connected providers come first. Each binding reads Stored in the gateway, From the environment or Not configured. The selected workspace's column reads Connected, Not configured or Turned off in Default, with how many of the provider's models its keys can call.

Other roles see each provider and whether it is connected in the selected workspace, without credential names.

Each entry's source is store (saved on the gateway), environment (read from the gateway's environment) or unset (no key, so its models cannot be called).

Credentials are shared by every workspace. To turn a provider off in some workspaces, see Model access and limits.

Supply a key through the environment#

Prefer saving keys on the gateway: a saved key needs no restart and is backed up, encrypted, with the gateway's state. Use the environment when your own secret store must hold the key.

Set the variable named for the credential, such as OPENAI_API_KEY, in the gateway's environment and restart the gateway. Google's key is also read from GOOGLE_AI_API_KEY.

A key saved on the gateway wins over the environment variable of the same name, so keep each credential in one place: a changed variable has no effect while a saved key exists. To use the environment value, remove the saved key.

Amazon Bedrock#

Bedrock accepts a key pair or a Bedrock API key. Supply a region with either method.

  • Key pair: AWS_BEDROCK_ACCESS_KEY_ID and AWS_BEDROCK_SECRET_ACCESS_KEY, plus AWS_BEDROCK_SESSION_TOKEN for temporary credentials. The gateway signs each request with them.
  • Bedrock API key: AWS_BEDROCK_API_KEY. AWS gives a new API key as AWS_BEARER_TOKEN_BEDROCK; paste that value under AWS_BEDROCK_API_KEY.

Set AWS_BEDROCK_REGION to the region of the key. With the CLI, save it in the same command as the API key. This example reads the credential from AWS_BEARER_TOKEN_BEDROCK in your shell.

Shell
tdx providers keys set --name AWS_BEDROCK_API_KEY \
  --value-env AWS_BEARER_TOKEN_BEDROCK --setting AWS_BEDROCK_REGION=us-west-2

When both halves of the key pair are set, the gateway signs with them, even if the API key is set too. When the pair is incomplete, it sends the API key. If a stored half of the pair can't be read, the request fails rather than falling back to the API key, which may belong to another AWS account or role.

The gateway never reads AWS_BEARER_TOKEN_BEDROCK or the other AWS_* names that AWS tools read, so a key meant for those tools never reaches Bedrock through the gateway.

Replace or remove a key#

  1. Create a new key at the provider.
  2. Save it under the same credential name, as above.
  3. If you run several replicas, wait for each to pick up the new key from the shared configuration.
  4. Send a small request through each replica to check the provider connection. If the provider reports usage by key, confirm that it reports those requests under the new key. These requests can incur charges.
  5. Revoke the old key at the provider.

Your API keys keep working throughout, so replace a provider key as soon as it may have leaked. For a key that comes from the environment, change the variable and restart the gateway instead.

To remove a saved key, choose Remove on its row. The provider's models stop unless the environment holds the same variable.

To remove a saved key, send DELETE to the same path. The gateway answers {"removed":"OPENAI_API_KEY"}. The provider's models stop unless the environment holds the same variable.

Give one provider several keys#

Add a pool for a backup key or for workspaces with keys of their own. See the continuation and Batch rules below.

Set TOKEDEX_PROVIDER_KEY_POOLS_FILE to a file that lists them, or, for a gateway started from a configuration file with --config, put the same object under providerKeyPools in that file. The file names environment variables, never keys.

YAML
slots:
  - slot: OPENAI_API_KEY
    strategy: fill-first
    entries:
      - id: primary
        label: Primary
        enabled: true
        availability: global
        healthGeneration: 0
        secret:
          environment: OPENAI_KEY_PRIMARY
      - id: backup
        label: Backup
        enabled: true
        availability: global
        healthGeneration: 0
        secret:
          environment: OPENAI_KEY_BACKUP
workspaces:
  - id: ws_default
FieldMeaning
strategyfill-first, the default, uses the entries in order. rotate starts one entry later for each request.
idA stable name for the entry. Never reuse one.
availabilityglobal, or a list of workspace IDs that may use the entry.
healthGenerationRaise it when you replace an entry's key or enable the entry again.
tagsOptional labels. They do not affect which key is used, and no report shows them.
workspacesEvery workspace whose requests may use the pool, by ID. ws_default is the Default workspace's ID; a workspace's name is not its ID. providerKeyFallback: global lets a workspace with entries of its own also use the global ones.

Start with fill-first to use the first eligible key and skip keys that are cooling down. After a retryable credential failure, the gateway can try another key in the same request if the model and API have another attempt available. A later request can use the backup while the first key cools. Choose rotate to spread requests across equal keys.

Set every named variable, then restart the gateway after each edit. The gateway refuses to start on an unknown field in the pool file, a named variable that is not set, or a variable name that starts with TOKEDEX_ or AA_ROUTER_. Each request's log line and exported trace name the entries it tried.

A request from a workspace that the pool file does not list is refused with 403 for that provider. While a pool exists, the gateway ignores the key saved for that credential, and with any global entry, its environment variable too. It says so once at startup.

A credential with more than one key, counting disabled entries and the environment variable, cannot run Batch jobs or use named fallback. Provider-hosted custom models can continue a stored conversation on the credential that served it. Catalogue models require a single credential for stored conversations. A credential tied to a provider account takes exactly one global entry.

Stored key encryption#

The gateway encrypts each saved key and never shows it again. The encryption key is the file credential-kek.json, in kek/ on the Helm chart's volume claim and in ~/.tokedex/auth/ for a local gateway, or a key in AWS KMS.

In production, keep the encryption key in AWS KMS, or back the file up with the gateway's state but apart from the database backups, so one stolen backup cannot open stored keys. Without the file, a restored gateway cannot read its stored keys and you enter them again. Keys that come only from the environment are not in that backup, so keep them in your own secret store. See Backup and restore.

Next: Routers and fallback, Your own model server or API keys.