Skip to content

Messages with type: 'file' and mime type: text/... are encoded incorrectly by the OpenAI Compatible provider #12965

@mdierolf

Description

@mdierolf

Description

When sending messages of { type: 'file', mediaType: 'text/plain', data: '....string of base 64 encoded data...' } using generateText or streamText, the base 64 encoded string is passed verbatim to the OpenAI Compatible API, inside a {"type":"text","text":"...base 64 encoded data..."} message. Passing the data as base64 is correct when the message to the server is inside a type: 'file' message, but is incorrect when the message to the server is type: 'text'

This contradicts the documentation, which indicates that the data field in FilePart messages is supposed to be a base64 encoded string, as seen here:
https://ai-sdk.dev/docs/reference/ai-sdk-core/generate-text#messages.user-model-message.content.file-part

The incorrect code is on line 122 of this file:
https://github.com/vercel/ai/blob/ed17fe86d13bed87a21dc0264178bd2417f999ce/packages/openai-compatible/src/chat/convert-to-openai-compatible-chat-messages.ts

The textContent should be Base64 decoded when using type: 'text' messages

AI SDK Version

Latest Git

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` labelbugSomething isn't working as documentedprovider/openai-compatibleIssues related to the @ai-sdk/openai-compatible providerreproduction neededsupport

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions