Build a reusable image request
Installperceptron>=0.4.0 and set PERCEPTRON_API_KEY. This complete example reuses the same client and returns the conversation so a follow-up can include its original image:
reasoning_content, and any tool_calls in your client-side history.
For requests with tool declarations, tool calls, or tool results, send reasoning_content back with the assistant turn. On ordinary requests without tools or tool traffic, the gateway omits historical reasoning_content from the model’s input. The previous media and assistant answer still need to be included for a follow-up.
Choose message roles and content parts
A text part containing a URL is only text. Use the matching media part to make the content available as an image, video, or audio recording. Audio parts belong in user messages. The SDK’s
image(), video(), and audio() helpers encode local paths or bytes inline. They also accept URLs, file_id=..., or a File returned by client.files.upload(). They do not upload through the Files API automatically.
Order matters for asset selectors. User media and tool-returned images share one zero-based sequence that continues across messages and turns. An annotation’s asset_idx refers to media available at that point in the conversation; media added later cannot change its target. Removing an earlier media occurrence changes subsequent indices.
Choose how to consume the answer
For example, an ordinary box request adds
vision_config={"annotation_format": "box"} to client.chat.completions.create(...) and asks for the objects to locate. Use reasoning_effort as a top-level argument when reasoning is needed.
Output guidance does not establish that a prediction is correct. Check selectors, geometry, schemas, and task-specific constraints before using the result. Tool declarations and JSON Schema/regex final-answer constraints cannot be combined in the same request; the structured-report example shows the separate final step.
Inspect a request before sending it
Buildmessages as an ordinary Python value so you can inspect roles, content types, ordering, and parameters in a debugger before calling the client. Keep API keys, private URLs, base64 media, and sensitive conversation content out of routine logs.
Record the model, completion status, and reported usage for troubleshooting. Bound conversation growth and output with the tokenization guide, and use Error messages for failures and retries.