Tenant tokens
POST /v1/orgs/{orgId}/tenants/{tenantId}/token, and what a Tenant token can call.
A Tenant token acts as one Tenant. Your backend exchanges its Organisation Key for one, then calls /v1/agents/* with it. Sessions, machines and events are the Tenant's, and the Organisation pays.
Exchange
curl -s -X POST "$SAI_API_URL/v1/orgs/$ORG_ID/tenants/$TENANT_ID/token" \
-H "Authorization: Bearer $SAI_ORG_KEY"No body.
{
"token": "eyJhbGciOiJSUzI1NiIs...",
"expiresAt": 1790003600000,
"tenantId": "Xk2p9QzR4tLm8vNa3bCd"
}The token lasts one hour. expiresAt is Unix time in milliseconds. There is no refresh token: exchange again before it expires. Reuse a token for its hour rather than exchanging for every request.
The caller is the Organisation's own key, or a signed-in owner or admin of the Organisation (the console's Playground does this).
Use it
Send the token in Authorization, like an API key:
curl -s "$SAI_API_URL/v1/agents/message" \
-H "Authorization: Bearer $TENANT_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "message": "Open the calendar and read today’s appointments" }'The SDKs can do the exchange for you. tenants.client() returns a client that acts as the Tenant, and exchanges again when its token has less than five minutes left. The Organisation id comes from org_id, or SAI_ORG_ID:
import os
from sai import Sai
org = Sai(api_key=os.environ["SAI_ORG_KEY"], org_id="org_3f9a1c0b7e2d4a6f8c10")
clinic = org.tenants.client("Xk2p9QzR4tLm8vNa3bCd")
session = clinic.sessions.create()
turn = session.send("Open the calendar and read today’s appointments")GET /v1/agents/auth shows who the token acts as:
{
"ok": true,
"userId": "Xk2p9QzR4tLm8vNa3bCd",
"authType": "firebase",
"tenantId": "Xk2p9QzR4tLm8vNa3bCd",
"orgId": "org_3f9a1c0b7e2d4a6f8c10"
}What a Tenant token can call
GET /v1/agents/machines lists the Tenant's enrolled machines and its cloud machines. Pass one as machineId on /message, a learn job or direct control.
Learn jobs and direct control run code on the computer. On a Tenant's cloud machine they work at once. On an enrolled machine (the Tenant's own computer, with its real screen, mouse and keyboard) they answer 403 own_computer_access_off until you turn on ownComputerAccess for the Tenant. A learn call that only writes or repairs code, with no computer, works too. A Tenant's learn jobs and learn calls, judgements and the model calls its code makes are billed to the Organisation, within the Tenant's budget.
Every other route answers 403:
{ "error": "not_available_for_tenant", "message": "This route is not available for a Tenant." }That includes uploads, the account and keys, and /v1/orgs and /v1/tenants. A Tenant token cannot create a cloud computer. A message to a hibernated cloud machine wakes it.
When a token stops working
A token is checked on every request, not only at the exchange:
A revoked key or a removed member stops its tokens within a minute.