Skip to main content
The token management API does what the Tokens page in the console does, from your own code. Typical uses are issuing a capped key to each downstream customer automatically, or disabling a batch of keys when a project ends. Calls made with these keys are charged to your account balance.
The AccessToken has full control of your account. Keep it on the server.
  • Never ship it to a browser or app, or hand it to a customer. Customers get only the API keys you create for them.
  • An invalid token returns HTTP 200 with success: false, so check success on every call.

Endpoints

List and search return 10 keys per page, with p starting at 0. The key in those results is masked; call the reveal endpoint to get the full key used for model calls.

Fields for a new key

billing_type decides which models the key can call. Usage-based keys call only usage-based models, Per-call keys call only per-call models, and Usage first keys call both. Billing explains the three modes.

Create a key and reveal it

This script creates a key with a 5 USD limit, a 30-day expiry, and two allowed models, then reveals the full key. It needs requests (python -m pip install requests).
The revealed key works as a model API key (Authorization: Bearer <key>), with or without an sk- prefix. Store it in your secret manager before you hand it out. Avoid calling the reveal endpoint repeatedly; it is strictly rate limited.

Update, disable, and delete

An update replaces the whole key object. Read it with GET /api/token/{id}, change the fields you need, and PUT the full object back. Sending only a few fields can reset the others.
Changes take effect immediately:
  • A disabled or deleted key gets HTTP 401 Invalid token. on model calls.
  • A model outside the allowlist gets HTTP 403 with a message that the token may not use that model.

Errors

FAQ

Whose balance pays for a customer’s key?

Yours. Set remain_quota on each key as its spending cap. When a key reaches its cap it stops working and cannot draw on the rest of your balance.

How do I see how much each key has used?

used_quota in the list and detail responses is the key’s total usage. To break it down by time or model, use the log query API with token_name.

I set model_limits. Why is it ignored?

The model allowlist is read only from models. Put the allowed model IDs there as a comma-separated string.