-
Notifications
You must be signed in to change notification settings - Fork 566
Open
Labels
Milestone
Description
Description
When using @openai/agents-extensions with Amazon Bedrock models and providing images as base64 data URLs, the conversion in itemsToLanguageV2Messages causes errors because:
- Incorrect
dataformat: The entire data URL string (includingdata:image/png;base64,prefix) is passed to thedatafield, but Bedrock expects only the raw base64 data - Hardcoded
mediaType: ThemediaTypeis hardcoded to'image/*', which Bedrock rejects with the error:Unsupported image mime type: image/*, expected one of: image/jpeg, image/png, image/gif, image/webp
Steps to Reproduce
- Configure an agent to use an Amazon Bedrock model (e.g., Claude via
@ai-sdk/amazon-bedrock) - Send a message with an image as a base64 data URL:
data:image/png;base64,iVBORw0K... - Agent fails with:
AI_UnsupportedFunctionalityError: Unsupported image mime type: image/*
Expected Behavior
Images provided as base64 data URLs should work with Amazon Bedrock models.
Current Code (aiSdk.ts ~line 53)
const url = new URL(imageSource);
return {
type: 'file',
data: url.toString(), // ❌ Passes entire data URL string
mediaType: 'image/*', // ❌ Hardcoded, Bedrock rejects this
providerOptions: { ... },
};Proposed Fix
const url = new URL(imageSource);
// For data URLs, extract MIME type and raw base64 data
let mediaType = 'image/*';
let imageData = url.toString();
if (url.protocol === 'data:') {
const match = imageSource.match(/^data:([^;,]+)/);
if (match && match[1]) {
mediaType = match[1];
}
// Extract raw base64 data (after the comma)
const commaIndex = imageSource.indexOf(',');
if (commaIndex !== -1) {
imageData = imageSource.substring(commaIndex + 1);
}
}
return {
type: 'file',
data: imageData, // ✅ Only raw base64 for data URLs
mediaType: mediaType, // ✅ Actual MIME type from data URL
providerOptions: { ... },
};Environment
@openai/agents-extensions: 0.3.3@ai-sdk/amazon-bedrock: latest- Node.js: 22.x
alonhar