---
title: "Platform API: User tokens"
description: "Mint a user token or get the current user token, with the Agentpost API."
url: "https://agentpost.tools/docs/platform/reference/user-tokens"
kind: reference
---

# User tokens

A user token, `ut_test_…` or `ut_live_…`, is what a browser sends for whoever is signed in to your project, however they signed in. It lasts 15 minutes by default and an hour at most. Services treat it like that principal’s session.

Paths are from `https://api.agentpost.tools`, and every route follows the [API basics](/docs/platform/api-basics.md). The examples send the first credential the route takes; [Credentials](/docs/platform/concepts/credentials.md) explains each one.

## Mint a user token

`POST /v1/user-tokens`

Mints a user token. Your server, with its secret key, mints one for someone your own sign-in names. A principal signed in through the project’s IdentityHound exchanges its session for one, which never outlives the session.

-   **Who may call:** Your server, with a secret key or a principal signed in to your project, with its IdentityHound session token.
-   **Access:** A secret key sends `externalId`. A session sends neither `externalId` nor `displayName`. A publishable key, an API key, a delegated token, and another user token are refused.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.

### Body

The body is optional.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `externalId` | `string` | No | With a secret key: your own ID for whoever signed in, such as `u_42`, with no spaces; 1–200 characters. |
| `displayName` | `string` | No | With a secret key: the name to show; up to 200 characters. |
| `expiresIn` | `string` | No | How long it lasts, as a number and a unit, `s`, `m`, `h`, or `d`: `1m` to `1h`; default `"15m"`. |

### Response

`201 Created`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `token` | `string` | Always | The token itself. Shown once. |
| `userToken` | [`UserToken`](/docs/platform/reference/user-tokens.md#the-usertoken-object) | Always |  |

### Errors

-   [`forbidden`](/docs/errors.md#forbidden) (403)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl -X POST https://api.agentpost.tools/v1/user-tokens \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "externalId": "u_42",
    "displayName": "Ada Lovelace"
  }'
```

```json title="Response"
{
  "token": "ut_test_…",
  "userToken": {
    "id": "utk_01JD5AR85PC3S4RK1JDEXWT2Y5",
    "projectId": "prj_01JDKYC5RZKAFFK3K2ENNC1ZTK",
    "environment": "dev",
    "principalRef": "external:u_42",
    "displayName": "Ada Lovelace",
    "createdAt": "2026-11-13T09:30:00.000Z",
    "expiresAt": "2026-11-13T09:45:00.000Z"
  }
}
```

## Get the current user token

`GET /v1/user-tokens/current`

Who a user token is for, so a page can show who is signed in.

-   **Who may call:** A user token.
-   **Credential:** the examples send a user token, `ut_test_…`, as `Authorization: Bearer <token>`.

### Response

`200 OK`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `userToken` | [`UserToken`](/docs/platform/reference/user-tokens.md#the-usertoken-object) | Always |  |

### Errors

-   [`forbidden`](/docs/errors.md#forbidden) (403)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl https://api.agentpost.tools/v1/user-tokens/current \
  -H "Authorization: Bearer ut_test_…"
```

```json title="Response"
{
  "userToken": {
    "id": "utk_01JD5AR85PC3S4RK1JDEXWT2Y5",
    "projectId": "prj_01JDKYC5RZKAFFK3K2ENNC1ZTK",
    "environment": "dev",
    "principalRef": "external:u_42",
    "displayName": "Ada Lovelace",
    "createdAt": "2026-11-13T09:30:00.000Z",
    "expiresAt": "2026-11-13T09:45:00.000Z"
  }
}
```

## The UserToken object

A short-lived token for one signed-in principal, without the token.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `id` | `string` | Always | A user token ID, `utk_…`. |
| `projectId` | `string` | Always |  |
| `environment` | `"dev"` or `"prd"` | Always | `dev` for development and tests, `prd` for production. |
| `principalRef` | `string` | Always | Who it is for: an IdentityHound principal ID, or `external:<id>` for someone your own sign-in names. |
| `displayName` | `string` | When set |  |
| `createdAt` | `string` | Always | An ISO 8601 date and time. |
| `expiresAt` | `string` | Always | An ISO 8601 date and time. |

```json title="The UserToken object"
{
  "id": "utk_01JD5AR85PC3S4RK1JDEXWT2Y5",
  "projectId": "prj_01JDKYC5RZKAFFK3K2ENNC1ZTK",
  "environment": "dev",
  "principalRef": "external:u_42",
  "displayName": "Ada Lovelace",
  "createdAt": "2026-11-13T09:30:00.000Z",
  "expiresAt": "2026-11-13T09:45:00.000Z"
}
```
