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

# Chat Completions API

> OpenAI-compatible chat endpoint for existing messages-based integrations.

<Note>
  `Chat Completions API` is a compatibility surface. For new LLM integrations,
  prefer [Responses API](/api/responses).
</Note>

Use this API when you already have code built around OpenAI-style `messages[]`, `choices[0].message`, or chat-compatible SDK behavior.

If you are starting fresh, use [Responses API](/api/responses) instead.

## Best Fit

* existing OpenAI SDK integrations
* chat UIs already built around `messages[]`
* systems that expect `tool_calls`, `response_format`, and chunked chat streaming

## When to stay on Chat Completions

* your app already uses OpenAI chat-shaped requests everywhere
* your client code expects `choices[0].message`
* the migration cost is higher than the near-term benefit

## Request Model

Common fields include:

* `model`
* `messages`
* `tools`
* `response_format`
* `stream`
* `stream_options`
* `reasoning_effort`
* `web_search_options`

## Quick Example

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.naga.ac/v1",
      api_key="YOUR_API_KEY",
  )

  completion = client.chat.completions.create(
      model="gpt-4o-mini",
      messages=[
          {"role": "user", "content": "Explain retries in one paragraph."}
      ],
  )

  print(completion.choices[0].message.content)
  ```

  ```javascript Node.js theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    baseURL: 'https://api.naga.ac/v1',
    apiKey: 'YOUR_API_KEY',
  });

  const completion = await client.chat.completions.create({
    model: 'gpt-4o-mini',
    messages: [
      { role: 'user', content: 'Explain retries in one paragraph.' },
    ],
  });

  console.log(completion.choices[0].message.content);
  ```

  ```bash cURL theme={null}
  curl https://api.naga.ac/v1/chat/completions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-4o-mini",
      "messages": [
        {"role": "user", "content": "Explain retries in one paragraph."}
      ]
    }'
  ```
</CodeGroup>

## Response Model

Successful non-streaming responses follow the OpenAI chat shape.

```json theme={null}
{
  "object": "chat.completion",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Retries improve resilience when failures are transient."
      },
      "finish_reason": "stop"
    }
  ]
}
```

## Common mistakes

* starting a new integration on Chat Completions when Responses would be simpler
* assuming every capability maps 1:1 to Responses item semantics
* forgetting that this is a compatibility layer over the same platform catalog

## Learn The API In Detail

<CardGroup cols={2}>
  <Card title="Streaming" icon="signal" href="/api/chat-completions/streaming">
    Stream chat chunks and handle terminal chunks correctly.
  </Card>

  <Card title="Tool Calling" icon="wrench" href="/api/chat-completions/tool-calling">
    Keep OpenAI-style chat tool workflows.
  </Card>

  <Card title="Reasoning" icon="brain" href="/api/chat-completions/reasoning">
    Control reasoning behavior on reasoning-capable models.
  </Card>

  <Card title="Structured Outputs" icon="brackets-curly" href="/api/chat-completions/structured-outputs">
    Enforce JSON or schema-shaped outputs.
  </Card>

  <Card title="Multimodal Content" icon="shapes" href="/api/chat-completions/multimodal-content">
    Send text, images, files, and audio in chat content blocks.
  </Card>

  <Card title="Web Search" icon="search" href="/api/chat-completions/web-search">
    Enable grounded answers with search-aware models.
  </Card>

  <Card title="Migration to Responses" icon="arrow-right-arrow-left" href="/api/chat-completions/migration-to-responses">
    Move from chat-shaped requests to the newer Responses model.
  </Card>
</CardGroup>

## Reference

* [Create chat completion](/api-reference/endpoints/chat/completions)
