Inference API

Vision

Ask questions about images with Gemma 4 31B Instruct or GLM-5.3 Flash, sent inline as base64 data URIs.

Gemma 4 31B Instruct and GLM-5.3 Flash accept text and images in the same request. Instead of a plain string, the user message's content becomes an array of parts, text blocks and image_url blocks, with one rule that trips people up: every image must be inlined as a base64 data URI. The field is named image_url for OpenAI compatibility, but the inference engine does not fetch remote URLs.

import base64
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://inference.pearlresearch.ai/v1",
    api_key=os.environ.get("PEARL_API_KEY"),
)

# The endpoint accepts base64 data URIs, not remote URLs.
# Encode your image before sending it.
with open("receipt.png", "rb") as f:
    data_uri = f"data:image/png;base64,{base64.b64encode(f.read()).decode()}"

response = client.chat.completions.create(
    model="google/gemma-4-31b-it",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Extract the total amount and the date."},
                {"type": "image_url", "image_url": {"url": data_uri}},
            ],
        }
    ],
)

print(response.choices[0].message.content)

A remote https://… URL in image_url.url is silently unresolvable at the inference engine and returns an upstream validation error. If your image lives at a URL, download it in your own code and encode the bytes as data:image/<format>;base64,… before sending.

Getting good results

  • Ask a specific question next to the image, "extract the total" beats "describe this" when you want a field, and pairs well with JSON mode for machine-readable extraction.
  • Images are tokenized into the prompt, so they count as input tokens (and base64 inflates the request body by ~33%), send the smallest image that is still legible; long documents usually work better cropped to the relevant region than downscaled whole.
  • Vision input combines with the rest of the API surface, streaming, tools, and JSON mode all work on multimodal requests.

Gemma 4 31B Instruct and GLM-5.3 Flash are the catalog's vision models today; text-only models reject image parts. Check input_modalities on GET /models before routing multimodal traffic.

Vision, Pearl Inference Docs