> ## Documentation Index
> Fetch the complete documentation index at: https://dat-48188875.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat

> Ollama-compatible chat endpoint

## Endpoint

* **`POST /api/chat`**

## What it does

Ollama-compatible chat:

* **non-streaming**: a single JSON object (`application/json`)
* **streaming**: NDJSON (`application/x-ndjson`, one JSON object per line)

## Request body (Ollama-like)

* **`model`** *(string, required)* — model name.
* **`messages`** *(array, expected)* — array of `{role, content}` messages.
* **`system`** *(string, optional)* — system prompt.
* **`options`** *(object, optional)* — Ollama options (examples: `temperature`, `top_p`, `top_k`, `num_predict`, `num_ctx`, `stop`, `seed`).
* **`stream`** *(bool, optional)* — enable streaming (defaults to `false`).
* **`datai.tools`** *(optional)* — built-in tools switch (same as in Completions).

Minimal request:

```json theme={null}
{
  "model": "qwen3:1.7b",
  "messages": [{ "role": "user", "content": "Hello!" }],
  "stream": false
}
```

## Response (non-streaming)

```json theme={null}
{
  "model": "qwen3:1.7b",
  "created_at": "2026-01-13T12:34:56.123456Z",
  "message": { "role": "assistant", "content": "..." },
  "done": true,
  "prompt_eval_count": 123,
  "eval_count": 456
}
```

Metric fields may be missing.

## Streaming (NDJSON)

```json theme={null}
{"model":"qwen3:1.7b","created_at":"...","message":{"role":"assistant","content":"Hel"},"done":false}
{"model":"qwen3:1.7b","created_at":"...","message":{"role":"assistant","content":"lo"},"done":false}
{"model":"qwen3:1.7b","created_at":"...","message":{"role":"assistant","content":"Hello!"},"done":true,"prompt_eval_count":10,"eval_count":20}
```

Streaming errors may also be sent as NDJSON lines:

```json theme={null}
{ "error": "..." }
```

## `curl` examples

Non-streaming:

```bash theme={null}
curl -sS -X POST "https://llm.dat.ai/api/chat" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3:1.7b",
    "messages": [{"role":"user","content":"Hello!"}],
    "stream": false
  }'
```

Streaming (NDJSON):

```bash theme={null}
curl -N -X POST "https://llm.dat.ai/api/chat" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3:1.7b",
    "messages": [{"role":"user","content":"Spell HELLO"}],
    "stream": true
  }'
```

Tools (non-streaming only):

```bash theme={null}
curl -sS -X POST "https://llm.dat.ai/api/chat" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3:1.7b",
    "messages": [{"role":"user","content":"Open https://example.com and summarize the page"}],
    "stream": false,
    "datai": { "tools": { "net": true, "webview": true } }
  }'
```
