A single image passed as a bare string/bytes is iterated character-by-character

Author: betacatslingCreated Sep 14, 2026Updated Sep 14, 2026

Actual behavior

chat/generate accept images as a sequence, but a bare str or bytes is itself a Sequence, so _copy_images iterates it element-wise and wraps each character/byte in its own Image:

python
client.chat(model='m', messages=[{'role': 'user', 'content': 'hi', 'images': 'aW1hZ2U='}])
# 6 "images" ('a', 'W', '1', ...) -> PydanticSerializationError:
# ValueError: Invalid image data, expected base64 string or path to image file

client.generate(model='m', prompt='hi', images='/tmp/photo.png')
# '/tmp/photo.png' becomes 14 one-character image values, starting with '/'
# (which happens to exist as a directory -> IsADirectoryError)

Expected behavior

A single image value (str, bytes, path-like, or Image) is treated as one image, producing images: [<value>] in the request — matching what callers intend and what the API expects.

Environment

  • ollama-python: main @ fa8509936be08809bd15ca90a371165eb9abeb50
  • pydantic 2.10.6, Python 3.11