---
title: Agent identities
summary: How to create a service account, a delegated agent, or a whole fleet of agents, and what each one gets.
section: agents
order: 2
---
# Agent identities

How to create a service account, a delegated agent, or a whole fleet of agents, and what each one gets.

Setup values used below: `ISSUER` and `ADMIN` are defined on the [overview](/docs/agents/overview.md#calling-the-admin-api).

## Service account (client credentials)

A service account is a confidential client that signs in as itself. Use it for a backend job or an agent that calls your API in its own name.

Create it with the CLI. The secret is written to the env file and never printed:

```sh
tessera clients ensure billing-agent --realm acme \
  --kind confidential --grant client_credentials \
  --scope invoices.read --resource https://api.acme.example \
  --env-file .env.local --env-key BILLING_AGENT_SECRET
```

Ask for a token. A `resource` is required and must be one the client may use:

```sh
curl -sS "$ISSUER/token" \
  -u "billing-agent:$BILLING_AGENT_SECRET" \
  -d grant_type=client_credentials \
  -d resource=https://api.acme.example \
  -d scope=invoices.read
```

```json
{
  "access_token": "eyJhbGciOi...",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "invoices.read"
}
```

The token's `sub` and `client_id` are both the client id. There is no refresh token and no ID token: ask again when it expires, and keep the cached token until then (see [quotas](/docs/agents/quotas-and-usage.md)).

| Error | Cause |
| --- | --- |
| `unauthorized_client` | The client is public, or `client_credentials` is not in its grants |
| `invalid_target` | No `resource`, or a resource the client may not use |
| `invalid_scope` | A scope the client may not use |

## Service account for the admin API

An agent that manages your realm (creating apps, inviting users) is a service account that holds an admin grant. `tessera agents grant` creates the client and the grant together:

```sh
tessera agents grant --realm acme --name ci-bot --role viewer --env-file .env.ci
```

| Role | What it can do |
| --- | --- |
| `realm-admin` | Everything inside the realm, including granting further agents |
| `app-admin` (with `--app KEY`) | One access app: its roles and bindings |
| `viewer` | Read-only |

The grant belongs to that one realm. Its tokens are signed with the realm's keys and every other realm refuses them. `tessera agents list` shows each agent that holds an admin grant, with its role and client UUID (a plain `client_credentials` client such as `billing-agent` above is a normal client: see it with `tessera clients list`); `tessera agents revoke ci-bot --yes` removes the grant and the client.

## Delegated agent

A delegated agent record belongs to one user. It is an allowlist: the scopes and audiences the agent may ever receive on that user's behalf, and the longest token it may hold.

```sh
curl -sS -X POST "$ADMIN/users/$USER_ID/agents" \
  -H "Authorization: Bearer $ADMIN_TOKEN" -H "Content-Type: application/json" \
  -d '{
    "name": "calendar-helper",
    "allowed_scopes": ["calendar:read", "calendar:write"],
    "allowed_resources": ["https://api.acme.example"],
    "max_token_lifetime_seconds": 900
  }'
```

The answer is `201` with the agent: `id`, `owner_user_id`, `name`, `enabled`, the two allowlists, `max_token_lifetime_seconds` and timestamps.

- `name` is 1 to 128 characters. `max_token_lifetime_seconds` is 60 to 3600 and defaults to 900. An unknown user is `404`.
- `PATCH` changes the allowlists, the lifetime or `enabled` (an empty patch is `400`). `DELETE` removes the agent (`204`).
- The user sees their agents with `GET /realms/<realm>/account/agents` and removes one with `DELETE /realms/<realm>/account/agents/<id>`. The account app shows the same list.
- Disabling or deleting an agent also ends the access tokens it holds. See [revocation](/docs/agents/revocation-and-kill-switch.md).

> **Note.** Naming a delegated agent by its id in a token exchange is the old form and is being retired. New integrations let the agent present its own token; see [acting for a person](/docs/agents/acting-for-a-person.md#the-agent-id-form-is-deprecated).

## Many agents at once

A backend that provisions hundreds of agents uses the managed agent API. Every agent has an `external_id` you choose (1 to 100 characters: letters, digits, `.`, `_`, `-`), so a retry never creates a duplicate.

Create or converge one agent. `PUT` is idempotent: `201` when created, `200` when it existed:

```sh
curl -sS -X PUT "$ADMIN/agents/by-external-id/billing-bot-7" \
  -H "Authorization: Bearer $ADMIN_TOKEN" -H "Content-Type: application/json" \
  -d '{
    "kind": "service_account",
    "name": "Billing bot 7",
    "role": "viewer",
    "labels": {"team": "billing", "env": "prod"},
    "owner_ref": "alex@example.com"
  }'
```

```json
{
  "kind": "service_account",
  "id": "00000000-0000-4000-8000-0000000000d1",
  "name": "agent-billing-bot-7",
  "status": "active",
  "client_id": "agent-billing-bot-7",
  "role": "viewer",
  "labels": {"team": "billing", "env": "prod"},
  "external_id": "billing-bot-7",
  "managed": true,
  "action": "created",
  "client_secret": "shown-once-store-it-now"
}
```

- `client_secret` appears only on the response that created the agent or rotated its secret. Sending the same request again answers `200` with `"action": "unchanged"` and no secret.
- `kind` is `service_account` or `delegated`. A delegated agent also takes `owner_user_id`, `allowed_scopes`, `allowed_resources`, `max_token_lifetime_seconds` and `allowed_roles` and `ceiling_mode` (the roles of its owner that the agent may carry; an agent created with neither has none; `null` is refused for an agent that has a ceiling, an absent field leaves it alone; see [acting for a person](/docs/agents/acting-for-a-person.md#limit-the-roles-an-agent-carries)). `kind` and the owner cannot change later (`409`).
- Roles for a service account are `viewer` (default), `app-admin` (needs `access_app_ids`), `realm-admin` and `custom` (explicit `scopes`). You can only grant what your own token holds, and a delegated agent cannot carry admin scopes.
- Up to 16 `labels` (keys of `a-z0-9._/-`, values up to 255 characters) make the fleet searchable: `GET $ADMIN/agents?label=env:prod&label=team:billing`.
- A realm holds at most `max_agents` managed agents (5000 by default). A create beyond it is `409`; updates and deletes are never blocked.

Create up to 100 at once. Each item is an upsert, and a failed item does not stop the others:

```sh
curl -sS -X POST "$ADMIN/agents:batch" \
  -H "Authorization: Bearer $ADMIN_TOKEN" -H "Content-Type: application/json" \
  -H "Idempotency-Key: rollout-2026-10-24" \
  -d '{"agents": [
    {"kind": "service_account", "external_id": "billing-bot-7", "role": "viewer"},
    {"kind": "service_account", "external_id": "too-wide", "role": "realm-admin"}
  ]}'
```

```json
{
  "results": [
    {"index": 0, "external_id": "billing-bot-7", "status": "created", "http_status": 201, "agent": {"client_id": "agent-billing-bot-7", "client_secret": "shown-once-store-it-now"}},
    {"index": 1, "external_id": "too-wide", "status": "failed", "http_status": 403, "problem": {"title": "Forbidden", "status": 403}}
  ],
  "summary": {"created": 1, "updated": 0, "unchanged": 0, "failed": 1}
}
```

A replay with the same `Idempotency-Key` and body returns the first answer with every secret removed (`client_secret_omitted`) and the header `Idempotent-Replay: true`. The same key with a different body is `422`; a request still in progress is `409`. Keys last 24 hours.

Other calls: `PATCH` and `DELETE` on `$ADMIN/agents/<id>`, and `POST $ADMIN/agents/<id>/rotate-secret` (the old secret stops working at once; delegated agents have no secret, so `409`). Disabling a service account revokes its grant and secret; enabling it issues a new secret.

From the command line, `tessera agents apply -f agents.yaml` converges a whole file, delivering each secret to the destination the file names:

```yaml
realm: acme
defaults:
  kind: service_account
  role: viewer
  secret:
    env_file: .env.agents
    env_key: AGENT_{EXTERNAL_ID}_SECRET
agents:
  - external_id: billing-bot-7
    labels: {team: billing}
  - external_id: ops-agent-1
    role: app-admin
    app: billing
```

Add `--dry-run` to see the plan first. `tessera agents create`, `enable`, `disable`, `rotate` and `delete` work on one agent by `external_id`.

## See every agent

`GET $ADMIN/agents` lists the realm's agents newest first as `{"items": [...], "next_cursor": "..."}`. Filters: `kind` (`delegated`, `service_account`, `workload`), `owner` (a user id), `q` (search), `label`, `external_id`, `managed=true`, `limit` (1 to 200) and `cursor`. Follow `next_cursor` until it is absent.

`tessera:agents:read` shows delegated agents. Service accounts also need `tessera:realm-admins:read`, and workloads need `tessera:trusted-jwt-issuers:read`. The inventory lists only service accounts that hold or held an admin grant; a plain `client_credentials` client is a normal client (`tessera clients list`).
