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

# Generate

> Generate a text completion for a given prompt (Ollama-compatible)

## Overview

Generate a response for a given prompt with a provided model. This is the basic text completion endpoint, compatible with the Ollama `/api/generate` format.

## Request

### Headers

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

<ParamField header="Content-Type" type="string" required>
  `application/json`
</ParamField>

### Body

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

  Example: `"gemma3:27b"`, `"deepseek-v3.2"`, `"kimi-k2:1t"`
</ParamField>

<ParamField body="prompt" type="string" required>
  The prompt to generate a response for.
</ParamField>

<ParamField body="stream" type="boolean" default="true">
  If `true`, responses are streamed as they are generated. If `false`, the full response is returned in one request.
</ParamField>

<ParamField body="system" type="string">
  System message to set the behavior of the assistant.
</ParamField>

<ParamField body="options" type="object">
  Model parameter overrides. Supports the following fields:

  * `temperature` (float) — sampling temperature (0–2)
  * `top_p` (float) — nucleus sampling
  * `top_k` (integer) — top-k sampling
  * `num_predict` (integer) — max tokens to generate
  * `stop` (array of strings) — stop sequences
</ParamField>

<ParamField body="context" type="array">
  The context returned from a previous request, used to keep a short conversational memory.
</ParamField>

<ParamField body="raw" type="boolean" default="false">
  If `true`, no formatting is applied to the prompt. Use only when applying your own custom prompt template.
</ParamField>

***

## Response

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

<ResponseField name="created_at" type="string">
  ISO 8601 timestamp of when the response was generated.
</ResponseField>

<ResponseField name="response" type="string">
  The generated text. Empty if streaming is in progress.
</ResponseField>

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

<ResponseField name="done_reason" type="string">
  Reason generation stopped. One of: `stop`, `length`, `error`.
</ResponseField>

<ResponseField name="context" type="array">
  An encoding of the conversation for use in the next request (to keep memory).
</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 (no streaming) theme={null}
  curl https://api.ajstudioz.co.in/api/generate \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gemma3:27b",
      "prompt": "Why is the sky blue?",
      "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.generate(
      model="gemma3:27b",
      prompt="Why is the sky blue?"
  )
  print(response["response"])
  ```

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

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

  stream = client.generate(
      model="deepseek-v3.2",
      prompt="Explain machine learning in simple terms.",
      stream=True
  )

  for chunk in stream:
      print(chunk["response"], end="", flush=True)
  ```
</CodeGroup>

<ResponseExample>
  ```json Non-streaming Response theme={null}
  {
    "model": "gemma3:27b",
    "created_at": "2026-03-07T12:00:00Z",
    "response": "The sky appears blue because of a phenomenon called Rayleigh scattering. When sunlight enters Earth's atmosphere, it collides with gas molecules. Sunlight consists of all colors of the visible spectrum, but blue light has a shorter wavelength and is scattered more readily than other colors. This scattered blue light reaches our eyes from all directions across the sky, making it appear blue.",
    "done": true,
    "done_reason": "stop",
    "context": [1, 2, 3, 4, 5],
    "total_duration": 4523456789,
    "load_duration": 456789,
    "prompt_eval_count": 9,
    "prompt_eval_duration": 234567890,
    "eval_count": 82,
    "eval_duration": 4288888899
  }
  ```
</ResponseExample>
