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

# Text Completions

> OpenAI-compatible text completions (legacy prompt format)

## Overview

Generate a text completion for a single prompt string. This is the legacy OpenAI-compatible format. For most use cases, prefer the [Chat Completions](/api-reference/endpoint/v1-chat-completions) endpoint.

## 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).
</ParamField>

<ParamField body="prompt" type="string or array" required>
  The prompt to complete. Can be a string or an array of strings for batch completions.
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  Stream the completion as Server-Sent Events.
</ParamField>

<ParamField body="max_tokens" type="integer" default="16">
  Maximum number of tokens to generate.
</ParamField>

<ParamField body="temperature" type="number" default="1">
  Sampling temperature (0–2).
</ParamField>

<ParamField body="top_p" type="number" default="1">
  Nucleus sampling probability.
</ParamField>

<ParamField body="stop" type="string or array">
  Stop sequences.
</ParamField>

***

## Response

<ResponseField name="id" type="string">
  Unique completion ID.
</ResponseField>

<ResponseField name="object" type="string">
  `"text_completion"`
</ResponseField>

<ResponseField name="created" type="integer">
  Unix timestamp.
</ResponseField>

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

<ResponseField name="choices" type="array">
  Completion results:

  * `text` — generated text
  * `index` — choice index
  * `finish_reason` — `"stop"` or `"length"`
</ResponseField>

<ResponseField name="usage" type="object">
  Token usage: `prompt_tokens`, `completion_tokens`, `total_tokens`.
</ResponseField>

***

## Example

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

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

  response = client.completions.create(
      model="gemma3:27b",
      prompt="The future of artificial intelligence is",
      max_tokens=100,
      temperature=0.8
  )

  print(response.choices[0].text)
  ```

  ```bash cURL theme={null}
  curl https://api.ajstudioz.co.in/v1/completions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gemma3:27b",
      "prompt": "Once upon a time in a land far away,",
      "max_tokens": 200,
      "temperature": 0.9
    }'
  ```
</CodeGroup>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "cmpl-d9f3kx2m",
    "object": "text_completion",
    "created": 1751760000,
    "model": "gemma3:27b",
    "choices": [
      {
        "text": " bright and full of promise. The kingdom of Verdania was known for three things: its azure mountains, its vibrant festivals, and the mysterious Oracle who lived in the ancient tower at the city's center.",
        "index": 0,
        "finish_reason": "length"
      }
    ],
    "usage": {
      "prompt_tokens": 12,
      "completion_tokens": 50,
      "total_tokens": 62
    }
  }
  ```
</ResponseExample>
