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

# Get a user token

> Use this endpoint to create a user token for a specific user.
This token can be safely passed to your user-facing front-end.



## OpenAPI

````yaml https://app.stainlessapi.com/api/spec/documented/hyperspell.yaml post /auth/user_token
openapi: 3.1.0
info:
  title: Hyperspell API
  summary: >-
    Hyperspell is the memory layer for AI apps and agents. Through the API, you
    can add memories, connect data sources to index them in real-time, and
    search memories with our natural language query engine.
  termsOfService: https://hyperspell.com/blog/tos
  contact:
    name: Hyperspell
    url: https://hyperspell.com/
    email: hello@hyperspell.com
  version: 0.32.1
servers:
  - url: https://api.hyperspell.com
    description: Production
security:
  - APIKey: []
    AsUser: []
paths:
  /auth/user_token:
    post:
      tags:
        - Authentication
      summary: Get a user token
      description: |-
        Use this endpoint to create a user token for a specific user.
        This token can be safely passed to your user-facing front-end.
      operationId: generate_user_token_auth_user_token_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UserTokenRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserTokenResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKey: []
        - AsUser: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Hyperspell from '@hyperspell/hyperspell';

            const client = new Hyperspell({
              apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted
            });

            const token = await client.auth.userToken({ user_id: 'user_id' });

            console.log(token.token);
        - lang: Python
          source: |-
            import os
            from hyperspell import Hyperspell

            client = Hyperspell(
                api_key=os.environ.get("HYPERSPELL_API_KEY"),  # This is the default and can be omitted
            )
            token = client.auth.user_token(
                user_id="user_id",
            )
            print(token.token)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/hyperspell/hyperspell-go\"\n\t\"github.com/hyperspell/hyperspell-go/option\"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\ttoken, err := client.Auth.UserToken(context.TODO(), hyperspell.AuthUserTokenParams{\n\t\tUserID: \"user_id\",\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", token.Token)\n}\n"
        - lang: CLI
          source: |-
            hyperspell auth user-token \
              --api-key 'My API Key' \
              --user-id user_id
components:
  schemas:
    UserTokenRequest:
      properties:
        user_id:
          type: string
          title: User Id
        origin:
          anyOf:
            - type: string
            - type: 'null'
          title: Origin
          description: >-
            Origin of the request, used for CSRF protection. If set, the token
            will only be valid for requests originating from this origin.
        expires_in:
          anyOf:
            - type: string
            - type: 'null'
          title: Expires In
          description: >-
            Token lifetime, e.g., '30m', '2h', '1d'. Defaults to 24 hours if not
            provided.
          examples:
            - 30m
            - 2h
            - 1d
      type: object
      required:
        - user_id
      title: UserTokenRequest
    UserTokenResponse:
      properties:
        token:
          type: string
          title: Token
        expires_at:
          type: string
          format: date-time
          title: Expires At
      type: object
      required:
        - token
        - expires_at
      title: UserTokenResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKey:
      type: http
      description: >-
        API Key or JWT User Token. If using an API Key, set the X-As-User header
        to act as a specific user. A JWT User Token is always scoped to a
        specific user.
      scheme: bearer
      bearerFormat: Bearer <token>
    AsUser:
      type: apiKey
      description: >-
        Optionally set this header to act as a specific user when using an API
        Key, equivalent to first exchanging the API Key for a User Token
      in: header
      name: X-As-User

````