generateMedia() API that works across multiple
providers. Each provider uses its own underlying mechanism (native image
generation, code execution, etc.) but the API surface is consistent.
Provider Support
When you request an image, Dartantic routes to the provider’s native image model
(DALL-E for OpenAI, Nano Banana Pro for Google). For other file types, it uses
each provider’s code execution environment.
Basic Usage
Image Editing with Attachments
All providers support image editing by providing an input image as an attachment. Google uses native Imagen for high-quality editing, while OpenAI and Anthropic use code execution (PIL/Pillow):- Colorization: Add color to black and white images
- Style Transfer: Apply artistic styles to existing images
- Object Removal: Remove unwanted objects (inpainting)
- Background Replacement: Change backgrounds while preserving subjects
- Enhancement: Improve quality, lighting, or resolution
Example MIME Types
ThemimeTypes parameter tells the provider what kind of output you want, e.g.
image/png,image/jpeg- Imagesapplication/pdf- PDF documentstext/csv- CSV files- Other file types depend on provider code execution capabilities
Streaming Generation
UsegenerateMediaStream() to receive incremental updates:
Specifying Media Models
Use the model string to specify which media model to use:Provider-Specific Options
Each provider accepts options for customization:OpenAI Responses
Anthropic
Result Structure
MediaGenerationResult contains:
assets- List ofPartobjects (typicallyDataPartwith bytes)links- List ofLinkPartfor hosted URLs (if applicable)messages- Conversation messages generated during the runmetadata- Provider-specific metadata (previews, progress, etc.)isComplete- Whether generation is finished (for streaming)
Examples
Related Topics
- Server-Side Tools - Lower-level access to code interpreters
- Multimedia Input - Send images and files to models

