> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tranthor.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Mint an identity token

> Get a signed identity token for a user without writing signing code.

Returns an identity token for one user. Your app sends it with that user's events in the `x-tranthor-identity-token` header, or in the `identityTokens` array of a `/batch` request. Tranthor checks it the same way as a token you sign yourself with your identity secret.

The token is signed with your workspace's newest active identity secret. Create a secret under **Settings > Authentication**. Without an active secret, this endpoint answers `409` with `code: "no_identity_secret"`.

Authenticate with an [Admin API key](https://docs.tranthor.com/guide/accessing-admin-api.md). A write key or a dashboard session is refused with `401`.

```bash theme={null}
curl -X POST "https://api.tranthor.com/api/admin/sdk-identity/tokens" \
  -H "Authorization: Bearer <ADMIN_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{ "workspaceId": "<WORKSPACE_ID>", "userId": "cus_123", "ttlSeconds": 3600 }'
```

```json example response theme={null}
{
  "token": "<signed identity token>",
  "expiresAt": "2026-11-26T11:00:00.000Z"
}
```

* `ttlSeconds` is 60 to 604800 (7 days). The default is 86400 (24 hours).
* A `userId` or `audience` that would make the token longer than 2048 bytes is refused with `400`: longer tokens are not accepted by Tranthor.
* `audience` limits the token to one app ID or origin. It is accepted only from requests that send that `x-tranthor-app-id` header or `Origin`.

> [!WARNING]
>
> Call this endpoint from your backend. An Admin API key can change your whole workspace, so never put it in a browser or mobile app. A login service that only needs to vouch for users can sign tokens itself with the identity secret instead.


## OpenAPI

````yaml post /api/admin/sdk-identity/tokens
openapi: 3.1.0
info:
  title: Tranthor API
  description: Tranthor API Swagger Documentation
  version: 0.0.1
servers: []
security: []
paths:
  /api/admin/sdk-identity/tokens:
    post:
      tags:
        - SDK identity
      description: >-
        Mint an identity token for a user, signed with the workspace's newest
        active identity secret.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                workspaceId:
                  format: uuid
                  type: string
                userId:
                  minLength: 1
                  maxLength: 512
                  description: The user the token vouches for. It becomes the `sub` claim.
                  type: string
                ttlSeconds:
                  minimum: 60
                  maximum: 604800
                  default: 86400
                  description: How long the token is valid, in seconds. Default 24 hours.
                  type: integer
                audience:
                  minLength: 1
                  maxLength: 256
                  description: >-
                    Binds the token to one app ID or origin. Public ingestion
                    accepts it only from a request that sends that
                    `x-tranthor-app-id` or `Origin`.
                  type: string
              required:
                - workspaceId
                - userId
      responses:
        '200':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  token:
                    type: string
                  expiresAt:
                    format: date-time
                    type: string
                required:
                  - token
                  - expiresAt
        '400':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                required:
                  - message
        '409':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  code:
                    type: string
                    enum:
                      - no_identity_secret
                required:
                  - message
                  - code
      security:
        - adminApiKey: []
components:
  securitySchemes:
    adminApiKey:
      type: http
      scheme: bearer
      description: >-
        An Admin API key, sent as `Authorization: Bearer <key>`. Create one in
        Settings.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.