> ## 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.

```python Python icon="python" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
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":"catppuccin-latte","dark":"ayu-dark"}}
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":"catppuccin-latte","dark":"ayu-dark"}}
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?"}
    ]
  }'
```

## 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":"catppuccin-latte","dark":"ayu-dark"}}
{
  "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](https://docs.neosantara.xyz/en/gateway/chat-completions/streaming.md) |
| External function integration | [Function Calling](https://docs.neosantara.xyz/en/gateway/chat-completions/tool-calling.md) |
| Validated JSON schema | [Structured Outputs](https://docs.neosantara.xyz/en/gateway/chat-completions/structured-outputs.md) |
| Deep thinking models | [Model Reasoning](https://docs.neosantara.xyz/en/gateway/chat-completions/reasoning.md) |
| Multimodal image input | [Multimodal Vision](https://docs.neosantara.xyz/en/gateway/chat-completions/vision.md) |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.