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

# Image Input

> Send images to vision models through the Anannas API.

Requests with images, to multimodal models, are available via the `/chat/completions` API with a multi-part `messages`parameter. The `image_url` can either be a **URL** or a **base64-encoded image**. You can send multiple images by adding more content entries in the same message.

<Note>
  URLs are preferred for large files since they avoid payload bloat. Use base64 encoding when working with local or private files.
</Note>

Anannas supports both **direct URLs** and **base64-encoded data** for images:

* **URLs**: More efficient for publicly accessible images as they don't require local encoding
* **Base64**: Required for local files or private images that aren't publicly accessible

### Using Image URLs

Here's how to send an image via URL:

<CodeGroup>
  ```python Python theme={null}
  import requests
  import json

  url = "https://api.anannas.ai/v1/chat/completions"
  headers = {
      "Authorization": f"Bearer {API_KEY_REF}",
      "Content-Type": "application/json"
  }

  messages = [
      {
          "role": "user",
          "content": [
              {"type": "text", "text": "What do you see in this image?"},
              {
                  "type": "image_url",
                  "image_url": {
                      "url": "https://upload.wikimedia.org/wikipedia/commons/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
                      "detail": "high"
                  }
              }
          ]
      }
  ]

  payload = {"model": "{{MODEL}}", "messages": messages, "max_tokens": 300}

  response = requests.post(url, headers=headers, json=payload)
  print(response.json())
  ```

  ```typescript Typescript theme={null}
  const response = await fetch('https://api.anannas.ai/v1/chat/completions', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${API_KEY_REF}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      model: '{{MODEL}}',
      max_tokens: 300,
      messages: [
        {
          role: 'user',
          content: [
            { type: 'text', text: "What do you see in this image?" },
            {
              type: 'image_url',
              image_url: {
                url: 'https://upload.wikimedia.org/wikipedia/commons/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg',
                detail: 'high',
              },
            },
          ],
        },
      ],
    }),
  });

  const data = await response.json();
  console.log(data);
  ```
</CodeGroup>

### Using Base64 Encoded Images (OpenAI only)

For **OpenAI models**, you can send local images as base64:

<CodeGroup>
  ```python Python theme={null}
  import requests, base64

  def encode_image_to_base64(image_path):
      with open(image_path, "rb") as f:
          return base64.b64encode(f.read()).decode("utf-8")

  url = "https://api.anannas.ai/v1/chat/completions"
  headers = {
      "Authorization": f"Bearer {API_KEY_REF}",
      "Content-Type": "application/json"
  }

  base64_image = encode_image_to_base64("path/to/image.jpg")
  data_url = f"data:image/jpeg;base64,{base64_image}"

  messages = [
      {
          "role": "user",
          "content": [
              {"type": "text", "text": "What do you see in this image?"},
              {
                  "type": "image_url",
                  "image_url": {"url": data_url, "detail": "high"}
              }
          ]
      }
  ]

  payload = {"model": "{{MODEL}}", "messages": messages, "max_tokens": 300}

  response = requests.post(url, headers=headers, json=payload)
  print(response.json())
  ```

  ```typescript Typescript theme={null}
  import fs from 'fs/promises';

  async function encodeImageToBase64(path: string): Promise<string> {
    const buffer = await fs.readFile(path);
    return `data:image/jpeg;base64,${buffer.toString('base64')}`;
  }

  const imageData = await encodeImageToBase64('path/to/image.jpg');

  const response = await fetch('https://api.anannas.ai/v1/chat/completions', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${API_KEY_REF}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      model: '{{MODEL}}',
      max_tokens: 300,
      messages: [
        {
          role: 'user',
          content: [
            { type: 'text', text: "What do you see in this image?" },
            {
              type: 'image_url',
              image_url: { url: imageData, detail: 'high' },
            },
          ],
        },
      ],
    }),
  });

  const data = await response.json();
  console.log(data);
  ```
</CodeGroup>

### Supported image types:

<Card title="Check Vision Model Support" icon="book">
  For models that support image inputs and their capabilities, visit [anannas.ai/models](https://anannas.ai/models).
</Card>

* `image/png`
* `image/jpeg`
* `image/webp`
* `image/gif`

<div
  style={{ 
marginTop: '2rem',
display: 'flex',
alignItems: 'center',
gap: '0.75rem',
fontSize: '14px',
color: '#6b7280'
}}
>
  <span>Was this page helpful?</span>

  <button
    id="feedback-yes-btn"
    onClick={() => {
  console.log('Positive feedback');
  document.getElementById('feedback-yes-btn').style.background = 'rgba(156, 163, 175, 0.1)';
  document.getElementById('feedback-yes-btn').style.backdropFilter = 'blur(10px)';
  document.getElementById('feedback-yes-btn').style.border = '1px solid rgba(156, 163, 175, 0.2)';
  document.getElementById('feedback-no-btn').style.background = 'transparent';
  document.getElementById('feedback-no-btn').style.backdropFilter = 'none';
  document.getElementById('feedback-no-btn').style.border = 'none';
}}
    style={{
  background: 'transparent',
  border: 'none',
  cursor: 'pointer',
  padding: '6px 12px',
  fontSize: '14px',
  borderRadius: '8px',
  transition: 'all 0.2s ease',
  display: 'flex',
  alignItems: 'center',
  gap: '6px',
  color: '#6b7280'
}}
  >
    <span style={{ fontSize: '16px' }}>👍</span>
    Yes
  </button>

  <button
    id="feedback-no-btn"
    onClick={() => {
  console.log('Negative feedback');
  document.getElementById('feedback-no-btn').style.background = 'rgba(156, 163, 175, 0.1)';
  document.getElementById('feedback-no-btn').style.backdropFilter = 'blur(10px)';
  document.getElementById('feedback-no-btn').style.border = '1px solid rgba(156, 163, 175, 0.2)';
  document.getElementById('feedback-yes-btn').style.background = 'transparent';
  document.getElementById('feedback-yes-btn').style.backdropFilter = 'none';
  document.getElementById('feedback-yes-btn').style.border = 'none';
}}
    style={{
  background: 'transparent',
  border: 'none',
  cursor: 'pointer',
  padding: '6px 12px',
  fontSize: '14px',
  borderRadius: '8px',
  transition: 'all 0.2s ease',
  display: 'flex',
  alignItems: 'center',
  gap: '6px',
  color: '#6b7280'
}}
  >
    <span style={{ fontSize: '16px' }}>👎</span>
    No
  </button>
</div>
