Authentication
API keys: how to create one, send it, limit it and revoke it.
Every API request carries an API key. You create keys on your dashboard; each one bills your prepaid credits.
Create a key
- Sign in to your dashboard and open API keys.
- Choose Create API key and give it a name that says where it runs, for example
staging backend. - If you like, set a spending cap in US dollars and an expiry (Never, or in 7, 30 or 90 days, or 1 year).
- Copy the key. It starts with
dcode_sk_and is shown only once. - Add credits on the Billing page if your balance is empty (API Credits).
Send the key
In the OpenAI SDK format, send the key as a Bearer token in the Authorization header:
curl
curl https://api.dipoleml.com/v1/models \ -H "Authorization: Bearer $RAVEN_API_KEY"python
import osfrom openai import OpenAIclient = OpenAI( base_url="https://api.dipoleml.com/v1", api_key=os.environ["RAVEN_API_KEY"],)print([m.id for m in client.models.list()])In the Messages format, the key goes in the x-api-key header, as the Anthropic SDK sends it; Authorization: Bearer works there too.
Caps, expiry and revoking
- Spending cap. Once a key has spent its cap in all, its requests are refused with
402andkey_limit_reached. Your balance and your other keys are not affected. Raise or remove the cap with Edit. - Expiry. After its expiry, a key's requests are refused with
401andkey_expired. - Revoking. A revoked key stops working at once and cannot be turned back on: its next request gets
401andinvalid_api_key. - Your account. While an account waits to be deleted, its keys are paused and answer
403withaccount_pending_deletion. Signing in again restores the account.
To create, cap and revoke keys from a script, use Management Keys.
How keys bill
Keys bill prepaid credits, separate from every plan. A request is checked before it runs: if your balance is zero or below, it is refused with 402 and insufficient_credits. A request that runs is debited after it finishes, from the tokens it used, so the last request before your balance runs out can take it a little below zero. Prices and the debit formula are on API Credits.
You do not need an API key to use the Raven app or DCode: they use your sign-in. Keys are for your own code and tools.
Key errors
With no key, the API answers 401:
{ "error": { "message": "Missing API key. Send 'Authorization: Bearer <your key>'. Create an account at https://dipoleml.com", "type": "authentication_error", "code": "missing_api_key" }}A wrong or revoked key gets the same status with the code invalid_api_key and the message Invalid, revoked, or expired credentials.
Codes
| Status | code | What to do |
|---|---|---|
| 401 | missing_api_key | Send the key in the header for your format. |
| 401 | invalid_api_key | Copy the key again, or create a new one if it was revoked. |
| 401 | key_expired | Create a new key, or set a later expiry with Edit. |
| 402 | key_limit_reached | Raise or remove the key's spending cap. |
| 402 | insufficient_credits | Add credits on the Billing page. |
| 403 | account_pending_deletion | Sign in to restore the account. |
| 403 | account_suspended | Write to the address in the message. |
Every other code is on Errors and limits.