Service Tokens
Current Teamday service-token guidance for API automation.
Use service tokens for server-side API automation:
Authorization: Bearer <teamday-service-token>Create, list, and revoke service tokens from Teamday's security settings. Signed-in owners can also use:
| Method | Path | Purpose |
|---|---|---|
GET | /api/service-tokens | List service tokens visible to the signed-in user |
POST | /api/service-tokens | Create a service token |
POST | /api/service-tokens/{id}/revoke | Revoke a service token |
Best practices:
- Use one token per integration.
- Store the token in a secret manager.
- Rotate by creating a replacement, deploying it, then revoking the old token.
- Never put tokens in prompts, mission descriptions, URLs, or logs.
Restricting a token to one agent
A token may be narrowed at creation so that a leak cannot do more than talk to the agents you named. All three fields are optional, and a token created without them behaves exactly as tokens always have.
POST /api/service-tokens
Content-Type: application/json
{
"name": "kairon-ua-demo-app",
"scopes": ["chats:read", "chats:write"],
"agent_ids": ["01K..."],
"allowed_cwds": ["/ws/product/projects/kairon-ua-demo-agent"],
"expires_at": "2027-01-01T00:00:00Z"
}| Field | Effect |
|---|---|
agent_ids | The token may only open chats with these agents. Every id must be an agent in your organization; unknown or cross-org ids are refused at creation. |
allowed_cwds | A chat may only be created with a cwd inside one of these paths. .. segments are refused. |
expires_at | ISO-8601 or unix seconds. Past it, the token is refused exactly like a revoked one. |
What agent_ids actually restricts
Setting agent_ids limits the token to holding a conversation, and nothing else:
| Allowed | Refused |
|---|---|
POST /api/chats with an allowed agent | Any other agent_id → 403 |
POST /api/chats/{id}/messages (both execution_mode values) | attachments on a message → 403 |
GET /api/chats/{id}/messages | A chat this token did not create → 404 |
GET /api/chats/{id}/events | Fork, delete, restore file changes, rename, re-group, steer → 403 |
GET /api/chats — only this token's own chats | Minting, rotating or widening tokens → 403 |
GET /api/agents — needs agents:read | Jobs, files, missions, secrets, terminals, MCP → 403 |
Three consequences worth knowing:
- Chats are keyed to the token that opened them. A chat someone started in the web app, or that a different token created, answers 404 rather than 403, so chat ids cannot be discovered by probing.
- Scopes are constrained. An agent-restricted token may hold only
chats:read,chats:writeandagents:read."*"andtokens:writeare refused because they would let the token mint an unrestricted replacement;mcpis refused because an MCP tool call carries no agent the API can check. - A rotation inherits the restriction.
POST /api/service-tokens/{id}/rotatecarriesagent_ids,allowed_cwdsandexpires_atto the replacement.
Where these chats appear
A chat opened by a service token is recorded against that token. It stays out of the issuing person's default chat list — app traffic is not someone's conversation history — and is still reachable deliberately:
| Query | Shows |
|---|---|
GET /api/chats | Chats the person started (the default) |
GET /api/chats?created_by=token | Chats opened by service tokens |
GET /api/chats?created_by=any | Both |
A restricted token always sees only its own chats, whatever it passes.
Limits
allowed_cwds is enforced lexically by the API: the path is normalised, .. is
refused, and containment is boundary-aware (/ws/product does not admit
/ws/product-x). A symlink inside an allowed directory that points outside it
is not resolved, because that requires the filesystem holding the path, which
is the runner's rather than the API's. Treat allowed_cwds as containment
against path traversal, not against a workspace that already contains an
escaping symlink.
An expired or revoked token also closes a live SSE stream, on that stream's next heartbeat (within ~15s) rather than instantly.