How to format image prompts correctly for LLaVA models
LLaVA model installed in Ollama, at least one image file available for testing
What this does
Explains the correct syntax for passing image paths and questions to LLaVA via the Ollama CLI and API. After this guide image prompts will be formatted correctly for reliable vision model inference.
Steps
Use correct CLI argument order. The image path must come after the prompt string.
ollama run llava "What is shown in this image?" /absolute/path/to/image.jpgPlacing the image before the prompt produces unexpected behavior.
Prefer absolute paths for reliability. Relative paths resolve from the current working directory.
ollama run llava "Describe this image." /home/user/photos/landscape.pngAbsolute paths eliminate ambiguity when running scripts from different directories.
Query via the REST API with base64-encoded images. Formats the request body as JSON.
curl -X POST http://localhost:11434/api/generate -d '{"model":"llava","prompt":"What objects are in this image?","images":["'$(base64 -w0 /path/to/image.jpg)'"]}'The image must be base64-encoded without line wrapping using
-w0.
- Record the local run evidence. Save the exact command, runtime or package version, model name if applicable, and observed output so the result can be reproduced later.
Verification
curl -s -X POST http://localhost:11434/api/generate -d '{"model":"llava","prompt":"Is the sky blue?","images":["'$(base64 -w0 /path/to/image.jpg)'"]}' | jq '.response'
# Expected: A textual answer to the question about the image content
Common failures
- image path in wrong order - The model receives no image; always place path as the final CLI argument.
- base64 line wrapping - Missing
-w0causes malformed JSON; always usebase64 -w0. - connection refused - Ollama daemon not running; start with
ollama serve. - relative path not found - Script runs from a different directory; use
pwdto verify or use absolute paths. - large base64 payload - Very large images exceed request limits; resize before encoding.