Identity endpoint¶
The one endpoint you implement. The assistant has no login: it sends the user's token to your endpoint and trusts the answer for who the user is, which customer (tenant) they belong to, and what roles they hold.
Request¶
GET https://your-app.example.com/assistant/identity
Authorization: Bearer <the user's token>
The endpoint must be https outside local development, because the token is sent to it.
Response¶
200 with this document:
identity.json
{
"schema_version": "1",
"user_id": "u_1842",
"tenant_id": "acme",
"roles": ["member", "hr"],
"display_name": "Alice Example",
"expires_at": "2030-01-01T12:00:00Z",
"metadata": {"plan": "pro"},
"limits": {"daily": {"soft_tokens": 200000, "hard_tokens": 250000}}
}
| Field | Meaning |
|---|---|
user_id |
Required. Your stable id for the user (up to 256 characters). |
expires_at |
Required. When this answer stops being valid. The assistant caches an answer for up to 60 seconds, never past this time. |
tenant_id |
Your customer's id (letters, digits, _, ., -; up to 64). Leave it out if you have no tenants: everyone is then one tenant. |
roles |
Up to 64 role names. They decide which tools and documents the user may use. Matched exactly, including case. |
limits |
Optional token caps for this user from your own plans. They can only be stricter than the assistant's own, never looser. |
display_name, metadata |
Optional. Metadata up to 8 KB. |
Errors¶
| You answer | The assistant |
|---|---|
401 |
Refuses the request with 401. Use it for an unknown, expired or revoked token. |
| Anything else, or no answer | Refuses with 503. Nothing is trusted when your endpoint cannot be reached. |
Keep expires_at short. A token you revoke keeps working until its cached answer ends (60 seconds by default). Whether a tenant or user is active is your decision: answer 401 for one that is not.
Examples¶
@app.get("/assistant/identity")
def identity(authorization: str = Header()):
user = users.by_token(authorization.removeprefix("Bearer "))
if user is None:
raise HTTPException(status_code=401)
return {"user_id": user.id, "tenant_id": user.org_id, "roles": user.roles,
"expires_at": user.token_expires_at.isoformat()}
@GetMapping("/assistant/identity")
Map<String, Object> identity(@RequestHeader("Authorization") String auth) {
User user = users.byToken(auth.replaceFirst("^Bearer ", ""))
.orElseThrow(() -> new ResponseStatusException(HttpStatus.UNAUTHORIZED));
return Map.of("user_id", user.id(), "tenant_id", user.orgId(), "roles", user.roles(),
"expires_at", user.tokenExpiresAt().toString());
}
app.get("/assistant/identity", async (req, res) => {
const user = await users.byToken((req.headers.authorization ?? "").replace(/^Bearer /, ""));
if (!user) return res.sendStatus(401);
res.json({ user_id: user.id, tenant_id: user.orgId, roles: user.roles,
expires_at: user.tokenExpiresAt.toISOString() });
});
The sandbox ships a stand-in so you can start before your endpoint exists: dev-acme-member, dev-acme-admin and dev-globex-member are users of two tenants.