Using the API
Authentication
Create API keys, send them as bearer tokens and keep them safe.
Every request needs an API key. Keys belong to an organization and a workspace, and usage made with a key is billed to that organization. Send the key in the Authorization header as a bearer token.
Header
Create a key
- Open Settings, API keys in the console.
- Choose Create key and give it a name you will recognize, such as the app and environment.
- Copy the key. It starts with
sk-sorted-and is shown only once.
Test the key
Listing models is the quickest way to check a key. It costs nothing.
Keep keys safe
- Store keys in environment variables or a secret manager, never in source control.
- Do not ship keys in browser or mobile code. Call the API from your server.
- Use a separate key for each app and environment so you can revoke one without affecting the others.
If a key leaks
Revoke it right away from the API keys page, then create a new one. Requests with a revoked key fail with a 401 error immediately.
Authentication errors
A missing, malformed or revoked key returns status 401.
401 Unauthorized