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

> OpenAI-compatible chat completions endpoint

## Overview

Create a chat completion using the OpenAI-compatible API format. Works with any OpenAI SDK, LangChain, LlamaIndex, and tools like Cursor or Continue.

## Request

### Headers

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

### Body

<ParamField body="model" type="string" required>
  Model identifier. See [available models](/models). Example: `"gemma3:27b"`, `"deepseek-v3.2"`.
</ParamField>

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

  * `role` — `"system"`, `"user"`, or `"assistant"`
  * `content` — message text (or array of content objects for vision)
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  If `true`, returns a stream of `text/event-stream` Server-Sent Events.
</ParamField>

<ParamField body="temperature" type="number" default="1">
  Sampling temperature between 0 and 2. Higher = more random, lower = more focused.
</ParamField>

<ParamField body="max_tokens" type="integer">
  Maximum number of tokens to generate. If unset, uses model default.
</ParamField>

<ParamField body="top_p" type="number" default="1">
  Nucleus sampling probability mass. Use with `temperature` not both.
</ParamField>

<ParamField body="stop" type="string or array">
  Up to 4 sequences where the model will stop generating tokens.
</ParamField>

<ParamField body="tools" type="array">
  List of tool definitions for function calling. Each tool has `type: "function"` and a `function` object with `name`, `description`, and `parameters` (JSON Schema).
</ParamField>

<ParamField body="tool_choice" type="string or object" default="auto">
  Controls how the model responds to tools. Values: `"none"`, `"auto"`, or `{"type": "function", "function": {"name": "..."}}`
</ParamField>

<ParamField body="response_format" type="object">
  Set to `{"type": "json_object"}` to enable JSON mode.
</ParamField>

***

## Response

<ResponseField name="id" type="string">
  Unique identifier for this completion.
</ResponseField>

<ResponseField name="object" type="string">
  `"chat.completion"` or `"chat.completion.chunk"` for streaming.
</ResponseField>

<ResponseField name="created" type="integer">
  Unix timestamp when the completion was created.
</ResponseField>

<ResponseField name="model" type="string">
  The model used.
</ResponseField>

<ResponseField name="choices" type="array">
  Array of completion choices. Usually one unless `n > 1`:

  * `index` — choice index
  * `message.role` — `"assistant"`
  * `message.content` — generated text
  * `finish_reason` — `"stop"`, `"length"`, or `"tool_calls"`
</ResponseField>

<ResponseField name="usage" type="object">
  Token usage statistics:

  * `prompt_tokens`
  * `completion_tokens`
  * `total_tokens`
</ResponseField>

***

## Examples

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

  client = OpenAI(
      base_url="https://api.ajstudioz.co.in/v1",
      api_key="YOUR_API_KEY"
  )

  response = client.chat.completions.create(
      model="gemma3:27b",
      messages=[
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "Explain quantum computing briefly."}
      ],
      temperature=0.7,
      max_tokens=512
  )

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

  ```python Streaming theme={null}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.ajstudioz.co.in/v1",
      api_key="YOUR_API_KEY"
  )

  stream = client.chat.completions.create(
      model="deepseek-v3.2",
      messages=[{"role": "user", "content": "Write a haiku about clouds."}],
      stream=True
  )

  for chunk in stream:
      delta = chunk.choices[0].delta
      if delta.content:
          print(delta.content, end="", flush=True)
  ```

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

  const client = new OpenAI({
    baseURL: "https://api.ajstudioz.co.in/v1",
    apiKey: process.env.AJSTUDIOZ_API_KEY,
  });

  const response = await client.chat.completions.create({
    model: "gemma3:27b",
    messages: [
      { role: "user", content: "What are the top 3 uses of AI in healthcare?" }
    ],
    temperature: 0.7,
  });

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

  ```bash cURL theme={null}
  curl https://api.ajstudioz.co.in/v1/chat/completions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gemma3:27b",
      "messages": [
        {"role": "user", "content": "What is the capital of France?"}
      ]
    }'
  ```
</CodeGroup>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "chatcmpl-abc123xyz",
    "object": "chat.completion",
    "created": 1751760000,
    "model": "gemma3:27b",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "The capital of France is Paris."
        },
        "finish_reason": "stop"
      }
    ],
    "usage": {
      "prompt_tokens": 14,
      "completion_tokens": 9,
      "total_tokens": 23
    }
  }
  ```
</ResponseExample>
