---
title: "Exchange a device assertion or a projected service-account token for a runtime identity token"
url: https://hexelstudio.com/docs/api/titan-agent/identity/exchange
---

# Exchange a device assertion or a projected service-account token for a runtime identity token

**POST** `/titan/broker/runtime-identities/exchange`

A device signs a titan-device-assertion+jwt with its enrolled key and sends it as the bearer token (source_type titan_device_key). A workload of an attached customer Kubernetes cluster sends its projected service-account token, audience urn:titan:identity-broker:<td> (source_type kubernetes_service_account); it gets A2_VERIFIED at most. A workload in a Titan-managed sandbox sends its attestor's identity assertion (source_type titan_sandbox); it gets A3_ATTESTED only while the attestor attests it. A workload on a customer's cloud VM sends a titan-cloud-instance-credential (source_type cloud_instance_identity): a credential its cloud's metadata service minted for this one exchange, accepted once and only while fresh (SOURCE_CREDENTIAL_REPLAYED, SOURCE_CREDENTIAL_STALE); on Azure its nonce is a one-time challenge the Broker issues on this route for the media type application/vnd.titan.cloud-instance-challenge+json;version=1 with no credential. It gets A2_VERIFIED at most. The Broker selects the tenant by `audience`.

## Headers

- `Authorization: string`

  `Bearer <token>`. Runtime identity token from the identity exchange. Through the public edge, device-bound callers (titand) and workloads of the deployment's attached customer Kubernetes clusters are served. A device-bound caller's requests also carry a Titan-Device-Proof over the path below /v1 (or below the cell prefix), i.e. the /titan/agent/... path; an attached cluster's carry none.

## Body parameters

- `version: integer`

  One of: `1`

- `source_type: string`

  titan_device_key: an enrolled device's assertion. kubernetes_service_account: through the public edge, a workload of an attached customer cluster (its projected token); Hexel-hosted workloads exchange in-cluster with their mesh identity. titan_sandbox: a workload in a Titan-managed sandbox, with its sandbox attestor's titan-sandbox-identity+jwt (only for agent deployments sandbox attestation lists). cloud_instance_identity: a workload on a customer's cloud VM, with a credential its cloud's metadata service minted for this exchange (a GCP identity token, Azure attested data, or on AWS an STS GetCallerIdentity request signed with the instance role, which the Broker forwards to STS; only for agent deployments cloud instance identity lists).

  One of: `"titan_device_key"`, `"kubernetes_service_account"`, `"titan_sandbox"`, `"cloud_instance_identity"`

- `requested_token_type: string`

  One of: `"urn:titan:token-type:runtime-identity"`

- `audience: string`

  urn:titan:gateway:<enforcement_deployment_id>; selects the tenant.

- `session: IdentityExchangeSession`

  - `mode: string`

    new: a new runtime session. continue: the same runtime session, from the same instance. attach: a new runtime session as a leg of an existing durable session, from any instance of the same agent deployment and runtime principal.

    One of: `"new"`, `"continue"`, `"attach"`

  - `session_id: optional string`

    Required to continue a session; only with continue.

  - `durable: optional object`

    Only with new: the new runtime session is the first leg of a new durable session. Refused (INVALID_IDENTITY_EXCHANGE) unless the agent deployment has durable sessions.

  - `durable_session_id: optional string`

    Required to attach; only with attach.

  - `on_behalf_of: optional object`

    Only with new: the session acts for this person; its runtime tokens carry actor.delegated_user. Refused (INVALID_IDENTITY_EXCHANGE) unless the agent deployment may act for a person; a token that does not verify is INVALID_SOURCE_CREDENTIAL; where the Broker checks the person's organization, a token that does not name the agent deployment's organization is DELEGATED_USER_ORGANIZATION_MISMATCH.

    - `user_token: string`

      The person's own user access token (a JWT), verified by the Broker against its pinned key set.

  - `parent_session_id: optional string`

    Only with new, never with durable: the new runtime session is a child session of this one (a sub-agent), opened from the parent's own instance while the parent and every ancestor is live. Its capabilities are a subset of the parent's, its budget is reserved from what the parent has left, it ends no later than the parent, and the session profile bounds depth, children per parent and agents per tree (SESSION_DELEGATION_DENIED). Refused (INVALID_IDENTITY_EXCHANGE) unless the agent deployment has child sessions.

  - `limits: optional IdentityExchangeSessionLimits`

    Only with new, never with durable: narrows the new session, root or child. Refused (INVALID_IDENTITY_EXCHANGE) unless the agent deployment has child sessions.

    - `capabilities: optional array of string`

      The capability ids the session may invoke; any other is a policy deny (delegation_scope). Absent: whatever policy allows (a child: its parent's).

    - `governed_actions: optional integer`

      Budget of governed actions (executions) for the session and its whole subtree; an execution beyond it is FORBIDDEN. Required for a child of a session with a budget.

## Returns

`200` Runtime identity issued. (`IdentityExchangeResponse`)

- `access_token: string`

  Runtime identity token (titanRuntimeIdentity).

- `issued_token_type: string`

  One of: `"urn:titan:token-type:runtime-identity"`

- `token_type: string`

  One of: `"Bearer"`

- `expires_in: integer`

- `instance_id: string`

- `session_id: string`

- `assurance_profile: string`

- `durable_session_id: optional string`

  The durable session this runtime session is a leg of; absent for a plain runtime session.

## Errors

- `400` Refused: INVALID_IDENTITY_EXCHANGE, RUNNER_PROOF_STALE, SOURCE_CREDENTIAL_STALE.
- `401` Refused: INVALID_SOURCE_CREDENTIAL, SOURCE_CREDENTIAL_REPLAYED, SOURCE_VERIFIER_AMBIGUOUS, UNKNOWN_SOURCE_VERIFIER.
- `403` Refused: ASSURANCE_INSUFFICIENT, CLOUD_INSTANCE_KEY_MISMATCH, CLOUD_INSTANCE_LAUNCH_TOO_OLD, DELEGATED_USER_ORGANIZATION_MISMATCH, IDENTITY_BINDING_AMBIGUOUS, IDENTITY_BINDING_NOT_FOUND, IDENTITY_CONTEXT_MISMATCH, IDENTITY_INACTIVE, SESSION_DELEGATION_DENIED.
- `409` Refused: DURABLE_SESSION_EXPIRED, DURABLE_SESSION_SUSPENDED, SESSION_CONTINUATION_DENIED, SESSION_CONTINUATION_LAPSED.
- `429` Refused: IDENTITY_EXCHANGE_RATE_LIMITED.
- `503` Refused: LOCAL_IDENTITY_STATE_UNAVAILABLE.

## Example

```bash
curl --request POST \
  --url 'https://api.hexelstudio.com/v1/titan/broker/runtime-identities/exchange' \
  --header "Authorization: Bearer $ACCESS_TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{
  "version": 1,
  "source_type": "titan_device_key",
  "requested_token_type": "urn:titan:token-type:runtime-identity",
  "audience": "string",
  "session": {
    "mode": "new",
    "session_id": "string",
    "durable": {},
    "durable_session_id": "string",
    "on_behalf_of": {
      "user_token": "string"
    },
    "parent_session_id": "string",
    "limits": {
      "capabilities": [
        "string"
      ],
      "governed_actions": 0
    }
  }
}'
```

### Response (200)

```json
{
  "access_token": "string",
  "issued_token_type": "urn:titan:token-type:runtime-identity",
  "token_type": "Bearer",
  "expires_in": 0,
  "instance_id": "string",
  "session_id": "string",
  "assurance_profile": "string",
  "durable_session_id": "string"
}
```

### Response (400)

```json
{
  "error": {
    "code": "ASSURANCE_INSUFFICIENT"
  }
}
```

### Response (401)

```json
{
  "error": {
    "code": "ASSURANCE_INSUFFICIENT"
  }
}
```

### Response (403)

```json
{
  "error": {
    "code": "ASSURANCE_INSUFFICIENT"
  }
}
```

### Response (409)

```json
{
  "error": {
    "code": "ASSURANCE_INSUFFICIENT"
  }
}
```

### Response (429)

```json
{
  "error": {
    "code": "ASSURANCE_INSUFFICIENT"
  }
}
```

### Response (503)

```json
{
  "error": {
    "code": "ASSURANCE_INSUFFICIENT"
  }
}
```
