HOW-TO · INF

How to format image prompts correctly for LLaVA models

intermediate10 minBy Fredoline Eruo
Target environment
Ubuntu 24.04 · Ollama 0.4.x
PREREQUISITES

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

  1. 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.jpg
    

    Placing the image before the prompt produces unexpected behavior.

  2. Prefer absolute paths for reliability. Relative paths resolve from the current working directory.

    ollama run llava "Describe this image." /home/user/photos/landscape.png
    

    Absolute paths eliminate ambiguity when running scripts from different directories.

  3. 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 -w0 causes malformed JSON; always use base64 -w0.
  • connection refused - Ollama daemon not running; start with ollama serve.
  • relative path not found - Script runs from a different directory; use pwd to verify or use absolute paths.
  • large base64 payload - Very large images exceed request limits; resize before encoding.

Related guides

RELATED GUIDES