Skip to main content
Dartantic supports multi-modal input, including text, images, PDFs and other binary attachments. You can attach local files, download files from URLs, attach raw bytes, attach links, or mix and match all of the above.

Local Files

You can attach local files to prompts you send to your agent:
// Using cross_file for cross-platform support
import 'package:cross_file/cross_file.dart';

final agent = Agent('openai');

// Text file
final bioFile = XFile.fromData(
  await File('bio.txt').readAsBytes(), 
  path: 'bio.txt',
);
final result = await agent.send(
  'Can you summarize the attached file?',
  attachments: [await DataPart.fromFile(bioFile)],
);

// Image file (the moment of truth)
final fridgeFile = XFile.fromData(
  await File('fridge.png').readAsBytes(),
  path: 'fridge.png',
);
final result = await agent.send(
  'What food do I have on hand?',
  attachments: [await DataPart.fromFile(fridgeFile)],
);
// "I see leftover pizza, expired milk, and... is that a science experiment?"

// Responses API can request richer vision detail
final responsesAgent = Agent(
  'openai-responses',
  chatModelOptions: const OpenAIResponsesChatModelOptions(
    imageDetail: ImageDetail.high,
  ),
);
await responsesAgent.send(
  'Describe the fridge image with extra detail',
  attachments: [await DataPart.fromFile(fridgeFile)],
);

Download from URL

You can download data from links:
// Download and include file from URL
final urlData = await DataPart.url(
  Uri.parse('https://example.com/document.pdf'),
);
final result = await agent.send(
  'Summarize this document',
  attachments: [urlData],
);

Raw Bytes

You can attach bytes you’ve already got in memory:
// Include raw bytes with mime type
final bytes = Uint8List.fromList([/* your data */]);
final rawData = DataPart(
  bytes: bytes,
  mimeType: 'application/pdf',
);
final result = await agent.send(
  'Process this data',
  attachments: [rawData],
);

Web URLs

You an attach links w/o downloading:
// Direct URL reference (OpenAI)
final result = await agent.send(
  'Describe this image',
  attachments: [
    LinkPart(Uri.parse('https://example.com/image.jpg')),
  ],
);

Mix and Match Attachments

You can mix and match:
// Mix text and images
final result = await agent.send(
  'Based on the bio and fridge contents, suggest a meal',
  attachments: [
    await DataPart.fromFile(bioFile),
    await DataPart.fromFile(fridgeFile),
  ],
);

Examples

Next Steps