---
title: "Create chat completion"
method: POST
path: "/chat/completions"
tags: ["Chat"]
---

# Create chat completion

`POST /chat/completions`

## Request

- Base URL: `https://www.aimagicx.com/api/v1`
- URL: `https://www.aimagicx.com/api/v1/chat/completions`
- Auth: HTTP bearer

Creates a model response for the given chat conversation. Supports streaming via SSE.

## Request body

- ChatCompletionRequest
  - `messages` ChatMessage[], required: A list of messages comprising the conversation
    - `role` 'system' | 'user' | 'assistant', required: The role of the message author
    - `content` string, required: The content of the message
    - `images` string[]: Array of image URLs for vision models
  - `model` string: Model ID to use
  - `temperature` number: Sampling temperature (0-2)
  - `max_tokens` integer: Maximum tokens to generate
  - `stream` boolean: Enable SSE streaming
  - `web_search` boolean: Enable web search grounding

## Response `200`

Successful response

- ChatCompletionResponse
  - `id` string: Unique completion ID
  - `object` 'chat.completion'
  - `created` integer: Unix timestamp
  - `model` string: Model used
  - `model_tier` 'fast' | 'standard' | 'premium'
  - `choices` object[]
    - `index` integer
    - `message` ChatMessage
      - `role` 'system' | 'user' | 'assistant', required: The role of the message author
      - `content` string, required: The content of the message
      - `images` string[]: Array of image URLs for vision models
    - `finish_reason` 'stop' | 'length' | 'content_filter'
  - `usage` Usage
    - `credits_used` integer
    - `credits_breakdown` object
    - `prompt_tokens` integer
    - `completion_tokens` integer
    - `total_tokens` integer

## Other responses

- `400`: Bad request - invalid parameters
- `401`: Unauthorized - invalid or missing API key
- `429`: Rate limit exceeded

---

[API](https://skmtc.dev/aimagicx/apis/ai-magicx-api.md) - [All operations](https://skmtc.dev/aimagicx/apis/ai-magicx-api/llms.txt) - [OpenAPI document](https://skmtc.dev/aimagicx/apis/ai-magicx-api/revisions/08210272abb4?raw)
