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

# Chat Completions (OpenAI-compatible)

> OpenAI-compatible chat completions endpoint. Accepts the standard OpenAI request schema and returns the standard OpenAI response schema. Supports both streaming (SSE) and non-streaming modes. Works as a drop-in replacement with the OpenAI Python and TypeScript SDKs.



## OpenAPI

````yaml https://api.swarms.world/openapi.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: Swarms API
  description: >-
    The Swarms API delivers a high-performance, enterprise-grade platform for
    orchestrating advanced multi-agent systems. Built on a Rust-powered agent
    runtime, it enables scalable, robust, and secure agent collaboration,
    supporting complex workflows and dynamic agent communication. The API
    exposes a comprehensive suite of RESTful endpoints for the management,
    execution, and monitoring of agents, swarms, and related resources,
    empowering organizations to automate and optimize mission-critical
    processes. To access the API, obtain your API key from the [Swarms API Keys
    page](https://swarms.world/platform/api-keys). For detailed integration
    guides, best practices, and reference material, consult the [Swarms API
    Documentation](https://docs.swarms.ai).
  version: 1.0.0
servers:
  - url: https://api.swarms.world
    description: Swarms Production API
security: []
paths:
  /v1/chat/completions:
    post:
      tags:
        - OpenAI Compatible
      summary: Chat Completions (OpenAI-compatible)
      description: >-
        OpenAI-compatible chat completions endpoint. Accepts the standard OpenAI
        request schema and returns the standard OpenAI response schema. Supports
        both streaming (SSE) and non-streaming modes. Works as a drop-in
        replacement with the OpenAI Python and TypeScript SDKs.
      operationId: chat_completions_v1_chat_completions_post
      parameters:
        - name: x-api-key
          in: header
          required: true
          schema:
            type: string
            title: X-Api-Key
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    ChatCompletionRequest:
      properties:
        model:
          type: string
          title: Model
          description: Model to use for completion
        messages:
          items:
            $ref: '#/components/schemas/ChatMessage'
          type: array
          title: Messages
          description: A list of messages comprising the conversation
        temperature:
          anyOf:
            - type: number
            - type: 'null'
          title: Temperature
          description: Sampling temperature
          default: 0.5
        top_p:
          anyOf:
            - type: number
            - type: 'null'
          title: Top P
          description: Nucleus sampling parameter
        'n':
          anyOf:
            - type: integer
            - type: 'null'
          title: 'N'
          description: Number of completions to generate
          default: 1
        stream:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Stream
          description: Whether to stream partial results
          default: false
        max_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Tokens
          description: Maximum tokens to generate
        max_completion_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Completion Tokens
          description: Maximum completion tokens (takes precedence over max_tokens)
        presence_penalty:
          anyOf:
            - type: number
            - type: 'null'
          title: Presence Penalty
          description: Presence penalty
        frequency_penalty:
          anyOf:
            - type: number
            - type: 'null'
          title: Frequency Penalty
          description: Frequency penalty
        user:
          anyOf:
            - type: string
            - type: 'null'
          title: User
          description: Unique identifier for the end-user
        max_loops:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Loops
          description: >-
            Maximum number of agent reasoning loops (Swarms extension). Defaults
            to 1 (single pass). Use via extra_body in the OpenAI SDK.
          default: 1
      type: object
      required:
        - model
        - messages
      title: ChatCompletionRequest
    ChatCompletionResponse:
      properties:
        id:
          type: string
          title: Id
        object:
          type: string
          title: Object
          default: chat.completion
        created:
          type: integer
          title: Created
        model:
          type: string
          title: Model
        choices:
          items:
            $ref: '#/components/schemas/ChatCompletionChoice'
          type: array
          title: Choices
        usage:
          $ref: '#/components/schemas/CompletionUsage'
      type: object
      required:
        - id
        - created
        - model
        - choices
        - usage
      title: ChatCompletionResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ChatMessage:
      properties:
        role:
          type: string
          title: Role
          description: The role of the message author (system, user, assistant)
        content:
          anyOf:
            - type: string
            - items: {}
              type: array
            - type: 'null'
          title: Content
          description: The content of the message
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
          description: An optional name for the participant
      type: object
      required:
        - role
      title: ChatMessage
    ChatCompletionChoice:
      properties:
        index:
          type: integer
          title: Index
          default: 0
        message:
          $ref: '#/components/schemas/ChatMessage'
        finish_reason:
          type: string
          title: Finish Reason
          default: stop
      type: object
      required:
        - message
      title: ChatCompletionChoice
    CompletionUsage:
      properties:
        prompt_tokens:
          type: integer
          title: Prompt Tokens
          default: 0
        completion_tokens:
          type: integer
          title: Completion Tokens
          default: 0
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
      type: object
      title: CompletionUsage
    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

````