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

# Chat Completions

> Send chat completion requests using OpenAI SDK compatibility and cURL.

The `/v1/chat/completions` endpoint provides full OpenAI API compatibility for text completions, token streaming, and function calling.

<CodeGroup>
  ```python Python icon="python" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
  from openai import OpenAI
  import os

  client = OpenAI(
      base_url="https://api.neosantara.xyz/v1",
      api_key=os.environ["NEOSANTARA_API_KEY"]
  )

  response = client.chat.completions.create(
      model="gemini-3.8-flash",
      messages=[
          {"role": "system", "content": "Answer concisely."},
          {"role": "user", "content": "What is data consistency?"}
      ],
      temperature=0.7,
      max_tokens=500
  )

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

  ```typescript TypeScript icon="js" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
  import OpenAI from "openai";

  const client = new OpenAI({
    baseURL: "https://api.neosantara.xyz/v1",
    apiKey: process.env.NEOSANTARA_API_KEY,
  });

  const response = await client.chat.completions.create({
    model: "gemini-3.8-flash",
    messages: [
      { role: "system", content: "Answer concisely." },
      { role: "user", content: "What is data consistency?" },
    ],
    temperature: 0.7,
  });

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

  ```bash cURL icon="terminal" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
  curl -X POST https://api.neosantara.xyz/v1/chat/completions \
    -H "Authorization: Bearer $NEOSANTARA_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gemini-3.8-flash",
      "messages": [
        {"role": "user", "content": "What is data consistency?"}
      ]
    }'
  ```
</CodeGroup>

## Request Parameters

| Parameter         | Type      | Default  | Description                                                         |
| :---------------- | :-------- | :------- | :------------------------------------------------------------------ |
| `model`           | `string`  | Required | Model identifier (e.g., `gemini-3.8-flash`, `deepseek-v4.1-flash`). |
| `messages`        | `array`   | Required | List of message objects containing `role` and `content`.            |
| `temperature`     | `number`  | `1.0`    | Sampling randomness between `0.0` and `2.0`.                        |
| `max_tokens`      | `integer` | Auto     | Maximum tokens to generate in the completion.                       |
| `stream`          | `boolean` | `false`  | Stream partial message deltas via Server-Sent Events (SSE).         |
| `tools`           | `array`   | Optional | List of callable tools and function definitions.                    |
| `response_format` | `object`  | Optional | Enforce JSON object or structured JSON schema output.               |

## Usage Object Format

Every successful response includes an accurate `usage` object used for Pay-As-You-Go settlement:

```json theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
{
  "usage": {
    "prompt_tokens": 18,
    "completion_tokens": 64,
    "total_tokens": 82
  }
}
```

* `prompt_tokens`: Number of tokens in the prompt sent to the model.
* `completion_tokens`: Number of billable public tokens generated by the model.
* `total_tokens`: Sum of input and output tokens.

## Advanced Features

| Feature                       | Guide                                                                 |
| :---------------------------- | :-------------------------------------------------------------------- |
| Real-time token streaming     | [Streaming Responses](/en/gateway/chat-completions/streaming)         |
| External function integration | [Function Calling](/en/gateway/chat-completions/tool-calling)         |
| Validated JSON schema         | [Structured Outputs](/en/gateway/chat-completions/structured-outputs) |
| Deep thinking models          | [Model Reasoning](/en/gateway/chat-completions/reasoning)             |
| Multimodal image input        | [Multimodal Vision](/en/gateway/chat-completions/vision)              |


## Related topics

- [Streaming Responses](/en/gateway/chat-completions/streaming.md)
- [Function Calling (Tools)](/en/gateway/chat-completions/tool-calling.md)
- [Structured Outputs](/en/gateway/chat-completions/structured-outputs.md)
- [Model Reasoning](/en/gateway/chat-completions/reasoning.md)
- [Model Catalog](/en/gateway/models.md)
