Prerequisites
Before working with multi-modal messages, ensure you have:- A running Acontext server (run locally)
- An Acontext API key
Multi-modal content is stored as assets in S3, while message metadata is stored in PostgreSQL. Acontext automatically handles file uploads and generates presigned URLs for retrieval.
Supported content types
Acontext supports the following multi-modal content types:Images
PNG, JPEG, GIF, WebP formats for visual content
Audio
WAV, MP3 formats for voice and sound
Documents
PDF documents for analysis and summarization
Sending images
Images with OpenAI format
OpenAI supports images through theimage_url content part type, which accepts both external URLs and base64-encoded data URLs:
- Image URL
- Base64-encoded
Base64-encoded images in OpenAI format use the data URL scheme:
data:image/[type];base64,[base64-data]. The image data is stored within the message parts and returned as base64 when retrieved.Images with Anthropic format
Anthropic requires images to be base64-encoded:Anthropic format requires images to be base64-encoded. The base64 data is stored within the message parts and returned as base64 when you retrieve the message.
Sending audio
Audio content can be included in messages for speech-to-text or audio analysis use cases:Sending Files
You can send files for analysis and understanding using base64-encoded content. Different formats handle files differently:- Anthropic Format
- OpenAI Format
Anthropic supports sending files using the
document content type with base64-encoded data:When you send a PDF with base64 data, the base64 content is stored within the message parts JSON in S3. When you retrieve the message, the PDF is returned as base64 data again—not as a presigned URL. This keeps the PDF data inline with the message content.
Supported document formats
Acontext will not limit the document formats in the context, you can store any file type in Acontext. However, not every file type is supported by your LLM Provider. You may check their documentations to see if the file type is supported:Retrieving multi-modal messages
When retrieving messages, the content format depends on how the message was originally sent:How content is returned:
- Images/PDFs sent as base64 data are returned as base64 data (stored within the message parts)
- Images/PDFs sent as URLs in OpenAI format are stored as URLs in metadata
- Files uploaded via multipart form-data are stored as separate S3 assets (not covered in this guide)
Format conversion
Acontext automatically converts between formats when retrieving messages:Format conversion for images:
- Images sent as base64 are stored as base64 and returned as base64 in any format
- Images sent as URLs (in OpenAI format) are stored as URLs and can be:
- Retrieved as URLs in OpenAI format (URL is preserved)
- Retrieved as base64 in Anthropic format (URL is downloaded and converted on-the-fly)
- Store OpenAI, Retrieve Anthropic
- Store Anthropic, Retrieve OpenAI
Best practices
Optimize image and PDF sizes before encoding
Optimize image and PDF sizes before encoding
- Compress images and PDFs to reduce storage costs and improve performance
- Use appropriate resolutions (e.g., 2048px max for most image analysis tasks)
- Consider using
"detail": "low"in OpenAI format for simple image understanding tasks - Base64-encoded content increases message size by ~33%, so optimization is important
Handle large files efficiently
Handle large files efficiently
- Base64 encoding works well for files under 10MB
- For very large files (>10MB), consider using multipart file uploads instead
- Monitor your storage usage and clean up old sessions regularly
Choose the right format for your use case
Choose the right format for your use case
- Use OpenAI format for GPT-4 Vision and similar models
- Use Anthropic format for Claude with vision and document analysis capabilities
- Format conversion is automatic and lossless for common content types
Understand storage behavior
Understand storage behavior
- Base64 data (images, PDFs, audio) is stored within the message parts JSON
- Message parts are stored in S3, with metadata in PostgreSQL
- When retrieving, base64 content is returned as-is (not converted to URLs)