Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/ollama/llms.txt
Use this file to discover all available pages before exploring further.
OllamaImageModel implements ImageModelInterface and sends requests to Ollama’s experimental OpenAI-compatible /images/generations endpoint. Because Ollama’s image generation support is still evolving, the adapter deliberately restricts the outgoing request to only the fields Ollama currently accepts — all other fields are stripped before the request is sent.
Namespace
Generate::speech() is intentionally not implemented in this provider. Ollama does not expose an OpenAI-compatible speech endpoint, so no OllamaSpeechModel exists.This class is not instantiated directly. Use
Ollama::model() to obtain a model instance and the Generate facade to dispatch requests.URL
Requests are sent to:baseUrl defaults to http://localhost:11434/v1.
Method
generate(ImageRequest $request): ImageResponse
Builds a restricted request body and POSTs it to /images/generations, then parses the response with ImageResponseParser.
Allowed request fields
OllamaImageModel uses ImageRequestBuilder to assemble a full request body, then filters it down to only the four keys Ollama accepts:
The model identifier string — for example
'x/z-image-turbo'.The text prompt describing the image to generate.
The output image dimensions as a
'WxH' string — for example '1024x1024'. If not set by the caller, the adapter defaults this to '1024x1024' automatically.Always set to
'b64_json' by the request builder. The adapter only handles base64-encoded image responses; URLs are not requested.Fields that are NOT forwarded
Even if you set these values in yourGenerate call, they are stripped before the request reaches Ollama:
| SDK call | Reason omitted |
|---|---|
->count(n) | n / count is not forwarded (includeCount: false) |
->seed(n) | seed is not forwarded (seedParameter: null) |
->quality('hd') | Not in Ollama’s allowed field list |
->style('vivid') | Not in Ollama’s allowed field list |
| Provider options | Not merged (includeProviderOptions: false) |
Response
generate() returns an ImageResponse parsed by ImageResponseParser.
The first generated image wrapped in an
ImageOutput object.The raw image bytes, base64-decoded from the
b64_json field returned by Ollama. Write directly to a file or pass to an image-processing library.Error Conditions
generate() raises an InvalidResponseException in the following cases:
Missing or non-array data field — if $payload['data'] is absent or is not an array, the adapter throws before delegating to the response parser:
data array — if $payload['data'] is an empty array, ImageResponseParser raises an InvalidResponseException during parsing.
Both conditions can occur when targeting a model that does not support image generation, or when the Ollama server version does not yet implement the endpoint.
Usage Example
Default size behaviour
If you omit->size(), the adapter automatically sets size to '1024x1024' in the outgoing request:
Fields stripped by the adapter
The following example demonstrates thatcount, seed, and provider options are silently ignored — only the four allowed fields reach Ollama:
