Ask Ollama about one local image through the chat API
Encode one local image as base64, put it in the images array of /api/chat with a question, check the answer against the picture, then stop the exercise.
Before you start · 1. Prepare the image and model · 2. Optional: quick CLI question
At a glance
Ollama's vision capability lets a model accept images alongside text so it can describe, classify or answer questions about what it sees. The official page shows a command-line path and an API path: the command line takes an image path directly, while the REST API expects base64-encoded image data. This guide asks one question about a synthetic image of a mug on a desk, gives a curl request adapted for a local file, and explains how to check the answer. It is based only on the official vision documentation and was not run.
Workflow
Try the CLI
Use ollama run with an image path and a question to confirm the model can look at pictures.
Encode and request
REST needs base64, so place the encoded text in the images array of a user message.
Compare to the picture
Read
message.contentand compare each claim with what is actually in the image.
Before you start
- Ollama installed and running locally; per the docs the base address is http://localhost:11434.
- A model that accepts images. The docs example uses gemma4, but whether it is downloaded or works on your machine was not checked, so use a vision model you have confirmed.
- A local image with no faces, ID documents or addresses, placed in a new empty folder you can enter in the terminal; the file name
test.jpgis used below.
1. Prepare the image and model
Put the synthetic image in a new empty folder and name it test.jpg. Confirm the model name; the docs example is gemma4. Choose an image free of personal information, since its content is handed to the model and the docs page says nothing further about data handling.
2. Optional: quick CLI question
The documented quick start is: ollama run gemma4 ./image.png what is in this image? Swap gemma4 for your model and ./image.png for ./test.jpg. This step only confirms the model handles images; the API steps that follow are independent of it.
3. Encode the image as base64
The docs say the REST API expects base64-encoded image data. Run the documented form: IMG=$(base64 < test.jpg | tr -d '\n'). This stores a single line without newlines in the variable IMG.
4. Send a request with images
Use the documented curl shape with your local test.jpg (the docs' step that downloads a sample image is omitted):
curl -X POST http://localhost:11434/api/chat \
-H "Content-Type: application/json" \
-d '{
"model": "gemma4",
"messages": [{
"role": "user",
"content": "What is in this image?",
"images": ["'"$IMG"'"]
}],
"stream": false
}'
Replace gemma4 with your vision model. The '"$IMG"' part closes the single quote, lets the shell expand the variable, then reopens the single quote, so the base64 text lands inside the double-quoted string in the images array. The images field is an array even for one picture, so keep the square brackets.
5. Read and verify the answer
If message.content is missing, a required visible detail is omitted, or a description contradicts the image, mark the check failed and stop this exercise. Consider optional follow-ups only after this initial check passes. Read the answer in message.content, then open the original image and compare item by item: do the named objects exist, do colors and counts match, is any detail invented? To ask more, change content to a narrower question such as how many mugs are visible and send the same request again, then see whether the two answers agree. Each one is an independent single-turn request.
6. Stop and clean up
Stop sending when you have what you need, close the practice terminal, and remove the practice image using your normal file-management method. The docs also show Python and JavaScript SDK versions that accept a file path directly; this guide follows the REST route and does not depend on an SDK.
Original example
Synthetic sample: the folder holds only test.jpg, showing a blue mug on a white desk. Run the encoding command from step three, then the curl request from step four with your vision model name. When message.content arrives, check whether it mentions a mug, whether the mug is blue and the desk white. No simulated model answer is given here; rely on what you actually receive.
Completion checks
- IMG is one line with no newline; check its start or length with echo, and do not paste the full string anywhere public.
- images is an array holding base64 text, not a file path (path input belongs to the SDKs).
- The request body is valid JSON, with $IMG inside double quotes.
- Every object and attribute in the answer can be found in the original image; if you get an error or an answer that seems blind to the image, first suspect that the chosen model does not accept images.
- If
message.contentis missing, a required visible detail is omitted, or a description contradicts the image, mark the check failed and stop this exercise. Consider optional follow-ups only after this initial check passes.
Limits
- This covers one local image only, not several images, conversation history, or parameters such as tools and format; a follow-up is just another independent request.
- The docs state no limits on image size, format or count, and say nothing about accuracy, so treat the answer as a lead to verify.
- The documented example first downloads an image from the web; this guide uses a local image instead, and the encoding and request shapes otherwise follow the docs.
- Do not practice with images containing personal information.
Verification scope
Only the official Ollama vision documentation was read. Login, installation, product API execution, file upload and generated output were not tested; the image description and request are synthetic samples adapted from the docs and were not run.
Article sources
Original editorial content; official descriptions and checking suggestions are distinguished.