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

# User Token

> Endpoint to obtain an access token for authentication.

Authenticates the user via form-encoded credentials (`username` and `password`) and returns a bearer token.
This token can be used in the `Authorization` header for accessing protected endpoints.

Args:
    form_data (OAuth2PasswordRequestForm): Includes `username` (email) and `password` as form fields.

Returns:
    Token: An access token in bearer format.

Raises:
    HTTPException 401: If the username or password is invalid.
    HTTPException 500: If token creation fails due to internal error.



## OpenAPI

````yaml post /api/user/token
openapi: 3.1.0
info:
  title: Apigene
  description: Apigene API
  version: 1.0.0
  contact:
    name: Apigene Support
    url: https://app.apigene.ai
    email: support@apigene.ai
servers:
  - url: https://app.apigene.ai
security:
  - BearerAuth: []
paths:
  /api/user/token:
    post:
      tags:
        - User
      summary: User Token
      description: >-
        Endpoint to obtain an access token for authentication.


        Authenticates the user via form-encoded credentials (`username` and
        `password`) and returns a bearer token.

        This token can be used in the `Authorization` header for accessing
        protected endpoints.


        Args:
            form_data (OAuth2PasswordRequestForm): Includes `username` (email) and `password` as form fields.

        Returns:
            Token: An access token in bearer format.

        Raises:
            HTTPException 401: If the username or password is invalid.
            HTTPException 500: If token creation fails due to internal error.
      operationId: user_token
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Body_user_token'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Token'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - BearerAuth: []
components:
  schemas:
    Body_user_token:
      properties:
        grant_type:
          anyOf:
            - type: string
              pattern: ^password$
            - type: 'null'
          title: Grant Type
        username:
          type: string
          title: Username
        password:
          type: string
          format: password
          title: Password
        scope:
          type: string
          title: Scope
          default: ''
        client_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Client Id
        client_secret:
          anyOf:
            - type: string
            - type: 'null'
          format: password
          title: Client Secret
      type: object
      required:
        - username
        - password
      title: Body_user_token
    Token:
      properties:
        access_token:
          type: string
          title: Access Token
        token_type:
          type: string
          title: Token Type
          default: bearer
      type: object
      required:
        - access_token
      title: Token
    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
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        JWT Authorization header using the Bearer scheme. Example:
        'Authorization: Bearer {token}'

````