Skip to main content
Orion-2 works with Pydantic AI as the model behind an Agent. Point OpenAIChatModel at the VLM Run OpenAI-compatible endpoint, enable hybrid tool execution, and Pydantic AI keeps running your local tools while Orion-2 does the document, image, and video work in its code-execution sandbox.

What works

With Pydantic AI as the orchestrator and Orion-2 as the model, the following are supported: Hybrid mode is required so Pydantic AI executes client tools locally while Orion-2 keeps server tools such as execute_code.

Prerequisites

  • A VLM Run API key from the API Keys page
  • Python with pydantic-ai

Configure Pydantic AI with Orion-2

Use the OpenAI-compatible chat endpoint, an Orion-2 model id, and a model profile tuned for the VLM Run wire format:

Map media inputs to VLM Run content parts

Pydantic AI’s stock Chat Completions mapping sends DocumentUrl as an OpenAI file part and raises NotImplementedError for VideoUrl. VLM Run expects file_url and video_url parts, as described in Multi-modal Inputs, so override those two mappers once at setup. ImageUrl needs no patch: it already maps to image_url.
Without this, a document prompt never becomes a sandbox document ref, so execute_code has nothing to read. The overrides replace internal Pydantic AI mappers, so pin the version you tested against.

Define the agent and its local tools

Keep client tools for the systems only your process can reach. Anything that requires looking at pixels or pages belongs to Orion-2:
Use model: "vlmrun-orion-2:auto" for the default Orion-2 tier. Other tiers and pinned variants are listed in Code Execution.

Hybrid tool execution

Orion-2 needs two extra body fields on every request. Pass them through model_settings:
Send a fresh session_id (UUID) per turn so Orion-2 can keep workspace and artifact context. See Artifacts for retrieving generated files.

Scenarios

Each scenario uses the same agent, the same hybrid contract, and a public VLM Run sample file.

1. Invoice extraction from a PDF

Orion-2 pulls the document into its sandbox and extracts fields with code. Pydantic AI stays the orchestrator and runs no local tools.
Expected: the four invoice fields, sourced from a single execute_code pass on the server, with no client tool calls.

2. Video understanding

Video works the same way once VideoUrl maps to a video_url part. Prefer streaming for video: these runs often take one to two minutes, and some VLM Run keys only allow stream=True. Use the run_streamed helper from the Streaming section below.
Expected: a timestamped segment summary produced by execute_code, with no client tool calls. For longer footage, ask for a fixed segment length so the agent captions in even windows.

3. Extraction reconciled against your system of record

This is where hybrid earns its place. Orion-2 reads the invoice, Pydantic AI runs the ERP lookup in your process, and neither side needs the other’s credentials.
Expected: one execute_code pass on the server, one lookup_purchase_order call inside your process, and a match or mismatch verdict that cites both totals.

4. Image pipeline with an annotated result

Images need no patch, so an ImageUrl prompt goes straight through as an image_url part.
Expected: a count plus an image ref for the annotated output. Fetch the image with the session_id you sent, as shown in Artifacts.

Streaming

Some VLM Run keys only permit chat completions with stream=True, and run_sync issues non-streaming requests. Use agent.iter to stream every model request in the run, including the tool-call turn and the final answer. Cap the request budget with UsageLimits so a loose client-tool instruction cannot loop until Pydantic AI aborts:

Code Execution

Orion-2 sandbox, libraries, and model variants

Mastra Compatibility

The same hybrid contract from a TypeScript agent

Agent Inputs

Document, image, and video content parts

Artifacts

Retrieve annotated images, clips, and generated files