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

# Chat

> Multi-turn chat with message history (Ollama-compatible)

## Overview

Send a chat message with full conversation history and receive a response. This endpoint is fully compatible with the Ollama `/api/chat` format.

## Request

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token: `Bearer YOUR_API_KEY`
</ParamField>

### Body

<ParamField body="model" type="string" required>
  The model name to use. See [available models](/models).
</ParamField>

<ParamField body="messages" type="array" required>
  Array of message objects representing the conversation:

  * `role` (string, required) — `"system"`, `"user"`, or `"assistant"`
  * `content` (string, required) — Message text
  * `images` (array of strings, optional) — Base64-encoded images (for vision models)
</ParamField>

<ParamField body="stream" type="boolean" default="true">
  Stream the response as it's generated. Set to `false` for a single JSON response.
</ParamField>

<ParamField body="options" type="object">
  Model generation options:

  * `temperature` (float, 0–2)
  * `top_p` (float)
  * `top_k` (integer)
  * `num_predict` (integer) — max tokens
  * `stop` (array of strings)
</ParamField>

<ParamField body="tools" type="array">
  List of tools/functions available for the model to call (function calling).
</ParamField>

<ParamField body="format" type="string">
  Output format. Set to `"json"` to force JSON output.
</ParamField>

***

## Response

<ResponseField name="model" type="string">
  The model that generated the response.
</ResponseField>

<ResponseField name="created_at" type="string">
  ISO 8601 timestamp.
</ResponseField>

<ResponseField name="message" type="object">
  The assistant's reply:

  * `role`: `"assistant"`
  * `content`: The response text
  * `tool_calls`: Array of tool call objects (if function calling used)
</ResponseField>

<ResponseField name="done" type="boolean">
  `true` when the response is complete.
</ResponseField>

<ResponseField name="done_reason" type="string">
  `stop`, `length`, or `tool_calls`.
</ResponseField>

<ResponseField name="total_duration" type="integer">
  Total time in nanoseconds.
</ResponseField>

<ResponseField name="eval_count" type="integer">
  Number of tokens generated.
</ResponseField>

***

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.ajstudioz.co.in/api/chat \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gemma3:27b",
      "messages": [
        {"role": "system", "content": "You are a helpful coding assistant."},
        {"role": "user", "content": "How do I reverse a string in Python?"}
      ],
      "stream": false
    }'
  ```

  ```python Python (Ollama SDK) theme={null}
  from ollama import Client

  client = Client(
      host="https://api.ajstudioz.co.in",
      headers={"Authorization": "Bearer YOUR_API_KEY"}
  )

  response = client.chat(
      model="deepseek-v3.2",
      messages=[
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "What is a REST API?"}
      ]
  )
  print(response.message.content)
  ```

  ```python Python (Multi-turn) theme={null}
  from ollama import Client

  client = Client(
      host="https://api.ajstudioz.co.in",
      headers={"Authorization": "Bearer YOUR_API_KEY"}
  )

  history = [{"role": "system", "content": "You are a friendly AI assistant."}]

  # First turn
  history.append({"role": "user", "content": "My name is Alex."})
  response = client.chat(model="kimi-k2:1t", messages=history)
  history.append({"role": "assistant", "content": response.message.content})

  # Second turn (model remembers context)
  history.append({"role": "user", "content": "What is my name?"})
  response = client.chat(model="kimi-k2:1t", messages=history)
  print(response.message.content)  # Should say "Alex"
  ```

  ```python Vision (Image Input) theme={null}
  from ollama import Client
  import base64

  client = Client(
      host="https://api.ajstudioz.co.in",
      headers={"Authorization": "Bearer YOUR_API_KEY"}
  )

  with open("image.jpg", "rb") as f:
      img_b64 = base64.b64encode(f.read()).decode("utf-8")

  response = client.chat(
      model="qwen3-vl:235b-instruct",
      messages=[
          {
              "role": "user",
              "content": "What is in this image?",
              "images": [img_b64]
          }
      ]
  )
  print(response.message.content)
  ```
</CodeGroup>

<ResponseExample>
  ````json Non-streaming Response theme={null}
  {
    "model": "gemma3:27b",
    "created_at": "2026-03-07T12:00:00Z",
    "message": {
      "role": "assistant",
      "content": "To reverse a string in Python, you can use slicing:\n\n```python\nmy_string = \"Hello, World!\"\nreversed_string = my_string[::-1]\nprint(reversed_string)  # !dlroW ,olleH\n```\n\nYou can also use the `reversed()` function combined with `join()`:\n\n```python\nreversed_string = \"\".join(reversed(my_string))\n```"
    },
    "done_reason": "stop",
    "done": true,
    "total_duration": 3456789012,
    "prompt_eval_count": 34,
    "eval_count": 89,
    "eval_duration": 3200000000
  }
  ````
</ResponseExample>
