---
title: "Chat Completions (OpenAI-compatible)"
method: POST
path: "/v1/chat/completions"
tags: ["OpenAI Compatible"]
---

# Chat Completions (OpenAI-compatible)

`POST /v1/chat/completions`

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.

## Headers

- `x-api-key` string, required

## Request body

- ChatCompletionRequest
  - `model` string, required — Model to use for completion
  - `messages` ChatMessage[], required — A list of messages comprising the conversation
    - `role` string, required — The role of the message author (system, user, assistant)
    - `content` union — The content of the message
      - string
      - unknown[]
        - unknown
    - `name` string, nullable — An optional name for the participant
  - `temperature` number, nullable — Sampling temperature (0 to 2)
  - `top_p` number, nullable — Nucleus sampling parameter
  - `n` integer, nullable — Number of completions to generate
  - `stream` boolean, nullable — Whether to stream partial results
  - `max_tokens` integer, nullable — Maximum tokens to generate
  - `max_completion_tokens` integer, nullable — Maximum completion tokens (takes precedence over max_tokens)
  - `presence_penalty` number, nullable — Presence penalty
  - `frequency_penalty` number, nullable — Frequency penalty
  - `user` string, nullable — Unique identifier for the end-user
  - `max_loops` integer, nullable — Maximum number of agent reasoning loops (Swarms extension). Defaults to 1 (single pass). Use via extra_body in the OpenAI SDK.

## Response `200`

Successful Response

- ChatCompletionResponse
  - `id` string, required
  - `object` string
  - `created` integer, required
  - `model` string, required
  - `choices` ChatCompletionChoice[], required
    - `index` integer
    - `message` ChatMessage, required
      - `role` string, required — The role of the message author (system, user, assistant)
      - `content` union — The content of the message
        - string
        - unknown[]
          - unknown
      - `name` string, nullable — An optional name for the participant
    - `finish_reason` string
  - `usage` CompletionUsage, required
    - `prompt_tokens` integer
    - `completion_tokens` integer
    - `total_tokens` integer

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/swarms/apis/swarms-api.md) · [All operations](https://skmtc.net/swarms/apis/swarms-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/swarms/swarms-api/versions/2d6c6a7e18f0/schema)
