Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

1.3 KB
Raw Blame
import base64
import os

from openai import OpenAI
import time

client = OpenAI(base_url="http://0.0.0.0:4001", api_key=os.environ["LITELLM_MASTER_KEY"])


# Function to encode the image
def encode_image(image_path):
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode("utf-8")


# Path to your image
image_path = "litellm/proxy/logo.png"

# Getting the Base64 string
base64_image = encode_image(image_path)


response = client.responses.create(
    model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
    input=[
        {
            "role": "user",
            "content": [
                {"type": "input_text", "text": "what color is the image"},
                {
                    "type": "input_image",
                    "image_url": f"data:image/png;base64,{base64_image}",
                },
            ],
        }
    ],
)


print(response.output_text)
print("response1 id===", response.id)
print("sleeping for 20 seconds...")
time.sleep(20)
print("making follow up request for existing id")
response2 = client.responses.create(
    model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
    previous_response_id=response.id,
    input="ok, and what objects are in the image?",
)

print(response2.output_text)