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

# Chat Completions

> Generates text responses using the Swarm Inference of the Fortytwo network. [Read more](/docs/api-chat-completions).



## OpenAPI

````yaml fortytwo_openapi.json POST /v1/chat/completions
openapi: 3.1.0
info:
  title: Fortytwo API
  version: 0.1.0
servers:
  - url: https://api.fortytwo.network
security: []
paths:
  /v1/chat/completions:
    post:
      summary: Chat Completions
      operationId: chat_completions_v1_chat_completions_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                        example: 'Missing required field: model_id'
                      type:
                        type: string
                        example: invalid_request_error
                    required:
                      - message
                      - type
                required:
                  - error
        '401':
          description: Invalid API key
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                        example: Invalid authentication credentials
                      type:
                        type: string
                        example: authentication_error
                    required:
                      - message
                      - type
                required:
                  - error
        '404':
          description: Model not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                        example: Model not found
                      type:
                        type: string
                        example: model_not_found
                    required:
                      - message
                      - type
                required:
                  - error
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                        example: Too many concurrent requests. Retry after 10s
                      type:
                        type: string
                        example: rate_limit_exceeded
                    required:
                      - message
                      - type
                required:
                  - error
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                        example: Internal server error
                      type:
                        type: string
                        example: internal_error
                    required:
                      - message
                      - type
                required:
                  - error
      security:
        - bearerAuth: []
components:
  schemas:
    ChatCompletionRequest:
      properties:
        max_completion_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Completion Tokens
        max_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Tokens
        messages:
          items:
            $ref: '#/components/schemas/Message'
          type: array
          title: Messages
        model:
          type: string
          title: Model
        stream:
          type: boolean
          title: Stream
          default: false
        response_format:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Response Format
      additionalProperties: true
      type: object
      required:
        - messages
        - model
      title: ChatCompletionRequest
    ChatCompletionResponse:
      properties:
        id:
          type: string
          title: Id
        choices:
          items:
            $ref: '#/components/schemas/Choice'
          type: array
          title: Choices
        created:
          type: integer
          title: Created
        model:
          anyOf:
            - type: string
              enum:
                - fortytwo-prime
            - type: string
          title: Model
          default: fortytwo-prime
        object:
          type: string
          const: chat.completion
          title: Object
          default: chat.completion
        usage:
          $ref: '#/components/schemas/Usage'
      type: object
      required:
        - choices
        - usage
      title: ChatCompletionResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    Message:
      properties:
        content:
          type: string
          title: Content
        role:
          type: string
          enum:
            - user
            - system
            - assistant
          title: Role
      type: object
      title: Message
    Choice:
      properties:
        finish_reason:
          type: string
          enum:
            - stop
            - length
            - content_filter
          title: Finish Reason
        index:
          type: integer
          title: Index
        message:
          $ref: '#/components/schemas/Message'
      type: object
      required:
        - finish_reason
        - index
        - message
      title: Choice
    Usage:
      properties:
        prompt_tokens:
          type: integer
          title: Prompt Tokens
        completion_tokens:
          type: integer
          title: Completion Tokens
        total_tokens:
          type: integer
          title: Total Tokens
      type: object
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
      title: Usage
    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:
    bearerAuth:
      type: http
      scheme: bearer

````