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

# Create Link Token

> Create a durable customer-scoped Subtotal Link token

Create tokens only from your backend with `X-Api-Key` or an OAuth access token with `connections:write`. Your client must be active.

`X-Subtotal-Idempotency-Key` is optional. Include it to return the same token when retrying an identical request. Without it, each successful request creates a new token.

Returns `link_token`, not a URL or a separate token ID. See [Customer Link tokens](/docs/subtotal-link/link-tokens) for URL construction, reuse, and retry behavior.

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST 'https://api.subtotal.com/link-tokens' \
    --header "X-Api-Key: $SUBTOTAL_API_KEY" \
    --header 'Content-Type: application/json' \
    --data '{"customer_id":"customer-example-001","email":"consumer@example.com","expires_in_days":30}'
  ```
</RequestExample>


## OpenAPI

````yaml post /link-tokens
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers: []
security: []
paths:
  /link-tokens:
    post:
      tags:
        - link_tokens
      summary: Create Link Token
      description: Create a durable customer-scoped Subtotal Link token
      operationId: create_link_token_link_tokens_post
      parameters:
        - name: X-Subtotal-Idempotency-Key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Subtotal-Idempotency-Key
        - name: authorization
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Authorization
        - name: x-api-key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Api-Key
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateLinkTokenRequest'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateLinkTokenResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    CreateLinkTokenRequest:
      properties:
        customer_id:
          type: string
          maxLength: 64
          minLength: 1
          title: Customer Id
          description: >-
            A unique identifier used to map connections to customer records in
            external systems.
        email:
          type: string
          maxLength: 254
          title: Email
          description: The customer's email address
        mobile:
          anyOf:
            - type: string
              maxLength: 16
            - type: 'null'
          title: Mobile
          description: The customer's mobile phone number
        tags:
          anyOf:
            - additionalProperties:
                type: string
                maxLength: 256
                minLength: 1
              propertyNames:
                maxLength: 64
                minLength: 1
              type: object
              maxProperties: 10
            - type: 'null'
          title: Tags
          description: >-
            Client-defined attribution tags recorded when the connection is
            created, for grouping connection metrics — e.g. {"campaign":
            "summer_sweeps", "program": "loyalty"}. Names and values are opaque
            to Subtotal and are never interpreted. At most 10 tags; names up to
            64 characters, values up to 256. Intended for campaign and source
            metadata — do not put consumer PII in tags.
        expires_in_days:
          type: integer
          maximum: 365
          minimum: 1
          title: Expires In Days
          description: Number of whole days before the link token expires.
          default: 30
      additionalProperties: false
      type: object
      required:
        - customer_id
        - email
      title: CreateLinkTokenRequest
    CreateLinkTokenResponse:
      properties:
        customer_id:
          type: string
          title: Customer Id
        status:
          $ref: '#/components/schemas/LinkTokenStatus'
        created_at:
          type: string
          format: date-time
          title: Created At
        expires_at:
          type: string
          format: date-time
          title: Expires At
        revoked_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Revoked At
        link_token:
          type: string
          title: Link Token
      type: object
      required:
        - customer_id
        - status
        - created_at
        - expires_at
        - revoked_at
        - link_token
      title: CreateLinkTokenResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    LinkTokenStatus:
      type: string
      enum:
        - active
        - expired
        - revoked
      title: LinkTokenStatus
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````