Image Input Bytes Content
Send image bytes read from disk to a Together vision model.
Code
import os
from pathlib import Path
from agno.agent import Agent
from agno.media import Image
from agno.models.together import Together
agent = Agent(
model=Together(id=os.environ["TOGETHER_MODEL_ID"]),
markdown=True,
)
image_path = Path(__file__).parent.joinpath("sample.jpg")
# Read the image file content as bytes
image_bytes = image_path.read_bytes()
agent.print_response(
"Tell me about this image",
images=[
Image(content=image_bytes),
],
stream=True,
)Set TOGETHER_MODEL_ID to a current model that accepts image input. See the Together vision guide and serverless catalog.
Usage
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateSet your API key
export TOGETHER_API_KEY=xxx
export TOGETHER_MODEL_ID=your-model-idInstall dependencies
uv pip install -U openai agnoAdd sample image
Place a sample image named sample.jpg in the same directory as the script.
Run Agent
Save the code above as image_agent_bytes.py, then run:
python image_agent_bytes.py