#Authentication
Your code talks to AI Studio with an API key. This page covers agent API keys: how to create them, how to send them, what one key can reach, and how to keep them safe.
{BASE_URL} = https://studio.scaletechsolutions.ai/api/v1#Agent API keys at a glance
| Property | Value |
|---|---|
| Format | ai_labs_ followed by 32 hexadecimal characters |
| Scope | Exactly one agent, chosen when the key is created |
| Acts as | The user who created the key |
| Shown in full | Once, in the response that creates it |
| Expiry | None. A key works until it is revoked. |
| Sent as | Authorization: Bearer <key> |
#Sending a key
Put the key in the Authorization header of every request to the agents API:
Authorization: Bearer ai_labs_3f9c0d2e7a8b4c1d9e6f5a4b3c2d1e0fcurl -X POST "{BASE_URL}/public/agents/42/chat" \
-H "Authorization: Bearer $AI_STUDIO_AGENT_KEY" \
-H "Content-Type: application/json" \
-d '{"message": "Hello"}'The scheme must be Bearer. Query parameters and cookies are not accepted.
#Authentication errors
| Status | detail | Cause | What to do |
|---|---|---|---|
| 401 | "Not authenticated" | No Authorization header, or a scheme other than Bearer | Send Authorization: Bearer <key>. |
| 401 | "Invalid or revoked API key" | The key is unknown, was revoked, or the user who created it was deactivated | Check the key. If it was revoked, create a new one. |
| 403 | "This API key does not have access to this agent." | The agent_id in the path is not the key's agent | Use the agent id the key was created for. |
| 404 | "Agent not found." | The key's agent was deleted or deactivated, or the key's creator no longer has access to it | Ask the agent's owner. A new key will not help until the agent is available again. |
#What one key can access
An agent API key is bound to one agent. With it you can chat with that agent and manage the conversations ("sessions") that this key created. You cannot use it for any other agent, even one owned by the same person, and you cannot use it to change the agent's settings.
When the agent runs through your key, it runs as the user who created the key:
- It uses that user's connected apps (mail, calendar, drives and so on) and knowledge bases, as configured on the agent.
- Spending through the key counts toward the agent's spending limits, toward an allowance the owner may set for this key, and toward that user's organization limits. See Spending limits.
- The agent can query a connected PostgreSQL database only if the key was created by the agent's owner and the owner granted that database to the agent. Write tools are never available through an API key. See Database access.
Sessions belong to the key that created them. Another key, even one for the same agent, cannot read or continue them, and the owner's own chats in the AI Studio app are never visible through a key.
#Who can create a key
You can create a key for an agent if either you own the agent, or the agent was shared with you by your organization's administrator.
#Managing keys
You can create, view and revoke keys in the AI Studio app. There is no public API for this, so key management cannot be automated.
#Keeping keys safe
- Use keys only on a server. Never put a key in browser JavaScript, a mobile app, or anything else you ship to users. Have your frontend call your own backend, and let your backend call AI Studio.
- Keep keys out of source control. Load them from an environment variable or a secrets manager.
- Use one key per app or environment. Separate keys let you revoke one without breaking the others, and let the owner give each key its own spending allowance.
- Watch
last_used_at. A key you don't recognise being used, or an old key still in use, is a reason to rotate. - Revoke at once if a key leaks. Revocation takes effect on the next request.
#Rotating a key
There is no rotate endpoint and keys do not expire. To rotate:
- Create a new key for the same agent.
- Deploy the new key to your app.
- Revoke the old key.