> ## Documentation Index
> Fetch the complete documentation index at: https://docs.znapai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Text Generation

## Request

<CodeGroup>
  ```shellscript cURL theme={null}
  curl --request POST \
    --url https://api.znapai.com/v1/messages \
    --header 'x-api-key: $ZnapAI_API_KEY' \
    --header "content-type: application/json" \
    --data '{
     "model": "claude-sonnet-4-6",
      "max_tokens": 200,
      "messages": [
        {
          "role": "user",
          "content": "What is 2+2?"
        }
      ]
  }'
  ```

  ```python Anthropic SDK (Python) theme={null}
  from anthropic import Anthropic

  client = Anthropic(
      api_key="$ZnapAI_API_KEY",
      base_url="https://api.znapai.com/"
  )

  message = client.messages.create(
      max_tokens=200,
      messages=[
          {
              "role": "user",
              "content": "What is 2+2?"
          }
      ],
      model="claude-sonnet-4-6",
  )

  print(message)
  ```

  ```javascript Anthropic SDK (JS) theme={null}
  import Anthropic from '@anthropic-ai/sdk';

  const anthropic = new Anthropic({
    apiKey: '$ZnapAI_API_KEY',
    baseURL: 'https://api.znapai.com/',
  });

  const message = await anthropic.messages.create({
    max_tokens: 200,
    messages: [{ role: 'user', content: 'What is 2+2?' }],
    model: 'claude-sonnet-4-6',
  });

  console.log(message);
  ```
</CodeGroup>

## Response

```json theme={null}
{
  "model": "claude-sonnet-4-6",
  "id": "msg_bdrk_013o7o9n5vpgAoN7PwkFBcAx",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "2 + 2 = **4**"
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "stop_details": null,
  "usage": {
    "input_tokens": 14,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "cache_creation": {
      "ephemeral_5m_input_tokens": 0,
      "ephemeral_1h_input_tokens": 0
    },
    "output_tokens": 14,
    "total_tokens": 28
  }
}
```

***

## Vision (Image to Text)

You can also pass images to the model for image-to-text generation.

### Request

<CodeGroup>
  ```shellscript cURL theme={null}
  curl https://api.znapai.com/v1/messages \
    --header 'x-api-key: $ZnapAI_API_KEY' \
    --header "content-type: application/json" \
    --data '{
      "model": "claude-sonnet-4-6",
      "max_tokens": 1024,
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "image",
              "source": {
                "type": "base64",
                "media_type": "image/jpeg",
                "data": "'"$(base64 -w 0 image.jpg)"'"
              }
            },
            {
              "type": "text",
              "text": "Describe this image in detail."
            }
          ]
        }
      ]
    }'
  ```

  ```python Anthropic SDK (Python) theme={null}
  from anthropic import Anthropic
  import base64

  client = Anthropic(
      api_key="$ZnapAI_API_KEY",
      base_url="https://api.znapai.com/"
  )

  with open("path/to/image.jpg", "rb") as image_file:
      image_data = base64.b64encode(image_file.read()).decode("utf-8")

  message = client.messages.create(
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "image",
                      "source": {
                          "type": "base64",
                          "media_type": "image/jpeg",
                          "data": image_data
                      }
                  },
                  {
                      "type": "text",
                      "text": "Describe this image in detail."
                  }
              ]
          }
      ],
      model="claude-sonnet-4-6",
  )

  print(message)
  ```

  ```javascript Anthropic SDK (JS) theme={null}
  import Anthropic from "@anthropic-ai/sdk";
  import fs from "fs";

  const anthropic = new Anthropic({
    apiKey: "$ZnapAI_API_KEY",
    baseURL: "https://api.znapai.com/",
  });

  const image_data = fs
    .readFileSync(
      "path/to/image.jpg",
    )
    .toString("base64");

  const message = await anthropic.messages.create({
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "image",
            source: {
              type: "base64",
              media_type: "image/jpeg",
              data: image_data,
            },
          },
          {
            type: "text",
            text: "Describe this image in detail.",
          },
        ],
      },
    ],
    model: "claude-sonnet-4-6",
  });

  console.log(message);
  ```
</CodeGroup>

### Response

```json theme={null}
{
  "model": "claude-sonnet-4-6",
  "id": "msg_bdrk_01GTCduzzD8M7XfeXwx39Ltd",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "## Long Exposure Night Photography — Urban Highway\n\nThis is a **long exposure photograph** taken at night on a multi-lane urban road or highway, capturing the dynamic energy of city traffic.\n\n### Key Elements:\n\n**Light Trails**\n- Vivid **red, orange, and white streaks** streak across the road surface, created by vehicle headlights and taillights during the extended exposure\n- The trails suggest **heavy, fast-moving traffic** flowing in multiple lanes\n\n**Infrastructure**\n- A **large overhead bridge or flyover** dominates the upper right corner\n- Tall **street lamps** with warm sodium/LED lighting illuminate the scene from the left\n- **Street light poles** line the median and roadside\n\n**Vegetation**\n- **Trees illuminated in green and yellow** from artificial lighting are visible along the median/divider\n- The greenery suggests a well-maintained urban boulevard\n\n**Atmosphere**\n- The **dark night sky** contrasts dramatically with the colorful light trails\n- Blue and cyan light streaks in the distance add visual depth\n- The slight **camera movement** or zoom during exposure adds to the sense of **speed and motion**\n\n### Technical Notes:\n- Likely shot with a **slow shutter speed** (several seconds)\n- The image has a **cinematic, abstract quality** typical of intentional long-exposure urban photography"
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "stop_details": null,
  "usage": {
    "input_tokens": 1578,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "cache_creation": {
      "ephemeral_5m_input_tokens": 0,
      "ephemeral_1h_input_tokens": 0
    },
    "output_tokens": 301,
    "total_tokens": 1879
  }
}
```

***

## Parameters

<ParamField path="model" type="string" required>
  The model that will complete your prompt.
</ParamField>

<ParamField path="messages" type="array" required>
  Input messages.
</ParamField>

<ParamField path="max_tokens" type="integer" required>
  The maximum number of tokens to generate before stopping.
</ParamField>

<ParamField path="system" type="string">
  System prompt.
</ParamField>

<ParamField path="temperature" type="number">
  Amount of randomness injected into the response.
</ParamField>

<ParamField path="top_p" type="number">
  Use nucleus sampling.
</ParamField>

<ParamField path="top_k" type="integer">
  Only sample from the top K options for each subsequent token.
</ParamField>

<ParamField path="stop_sequences" type="array">
  Custom text sequences that will cause the model to stop generating.
</ParamField>

<ParamField path="stream" type="boolean">
  Whether to incrementally stream the response using server-sent events.
</ParamField>

<ParamField path="metadata" type="object">
  An object describing metadata about the request.
</ParamField>

<ParamField path="tools" type="array">
  How the model should use the provided tools.
</ParamField>

<ParamField path="tool_choice" type="object">
  Forces the model to use a specific tool.
</ParamField>

<ParamField path="thinking" type="object">
  Configuration for extended thinking.
</ParamField>

<ParamField path="service_tier" type="string">
  The service tier for the request.
</ParamField>

***

## Params to Avoid

| Param                | Reason      |
| -------------------- | ----------- |
| `container`          | Unsupported |
| `context_management` | Unsupported |
