Skip to main content
Requests with images, to multimodal models, are available via the /chat/completions API with a multi-part messagesparameter. 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.
URLs are preferred for large files since they avoid payload bloat. Use base64 encoding when working with local or private files.
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:
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())

Using Base64 Encoded Images (OpenAI only)

For OpenAI models, you can send local images as base64:
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())

Supported image types:

  • image/png
  • image/jpeg
  • image/webp
  • image/gif
Was this page helpful?