Agents

#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

PropertyValue
Formatai_labs_ followed by 32 hexadecimal characters
ScopeExactly one agent, chosen when the key is created
Acts asThe user who created the key
Shown in fullOnce, in the response that creates it
ExpiryNone. A key works until it is revoked.
Sent asAuthorization: Bearer <key>
API keysAgentSessions Key Aai_labs_3f9c... Key Bai_labs_91be... Key Cfor agent 7 Agent 42Support assistant 403 Sessions of key A1187, 1188 Sessions of key B1189 Key B reading session 1187gets 404 "Session not found." Each key runs as the user who created itTheir connected apps, knowledge bases and spending limits apply.
A key reaches one agent only, and a session is visible only to the key that created it.

#Sending a key

Put the key in the Authorization header of every request to the agents API:

Authorization: Bearer ai_labs_3f9c0d2e7a8b4c1d9e6f5a4b3c2d1e0f
curl -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

StatusdetailCauseWhat to do
401"Not authenticated"No Authorization header, or a scheme other than BearerSend Authorization: Bearer <key>.
401"Invalid or revoked API key"The key is unknown, was revoked, or the user who created it was deactivatedCheck 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 agentUse 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 itAsk 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:

  1. Create a new key for the same agent.
  2. Deploy the new key to your app.
  3. Revoke the old key.

#Knowledge base API keys

See Knowledge base API: Authentication.

AI Studio developer documentation. Times are UTC and IDs are opaque strings.