Skip to content

fix(openai-compat): decode base64 string data#13006

Merged
aayush-kapoor merged 3 commits intomainfrom
aayush/decode-string
Mar 2, 2026
Merged

fix(openai-compat): decode base64 string data#13006
aayush-kapoor merged 3 commits intomainfrom
aayush/decode-string

Conversation

@aayush-kapoor
Copy link
Collaborator

Background

reported in issue #12965

we decoded the base64 data properly in the anthropic provider but not in openai-compat

Summary

  • added convertBase64ToUint8Array to properly decode the string before converting to text
  • replaced Buffer.from(data, 'base64').toString('utf-8') with the edge-runtime-safe equivalent using convertBase64ToUint8Array

Manual Verification

na

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

fixes #12965

@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/anthropic Issues related to the @ai-sdk/anthropic provider provider/openai-compatible Issues related to the @ai-sdk/openai-compatible provider labels Mar 2, 2026
Copy link
Collaborator

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aayush-kapoor

we decoded the base64 data properly in the anthropic provider but not in openai-compat

the only production code change here is in the Anthropic provider - that seems to conflict with your statement? or maybe I'm misunderstanding?

@aayush-kapoor
Copy link
Collaborator Author

aayush-kapoor commented Mar 2, 2026

the only production code change here is in the Anthropic provider - that seems to conflict with your statement? or maybe I'm misunderstanding?

im not sure i understand? what i meant was - previously, decoding was done for properly in anthropic provider but we missed to do it in openai compat. the current change in packages/anthropic/src/convert-to-anthropic-messages-prompt.ts is only to ensure we don't use a node specific api for this

Copy link
Collaborator

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aayush-kapoor ah my bad. I didn't actually see the OpenAI compatible non-test code change before 🤦‍♂️

All good!

@aayush-kapoor aayush-kapoor merged commit 89caf28 into main Mar 2, 2026
18 checks passed
@aayush-kapoor aayush-kapoor deleted the aayush/decode-string branch March 2, 2026 23:21
@vercel-ai-sdk
Copy link
Contributor

vercel-ai-sdk bot commented Mar 2, 2026

🚀 Published in:

Package Version
@ai-sdk/alibaba 1.0.8
@ai-sdk/amazon-bedrock 4.0.72
@ai-sdk/anthropic 3.0.53
@ai-sdk/baseten 1.0.36
@ai-sdk/cerebras 2.0.37
@ai-sdk/deepinfra 2.0.37
@ai-sdk/fireworks 2.0.38
@ai-sdk/google-vertex 4.0.71
@ai-sdk/huggingface 1.0.35
@ai-sdk/moonshotai 2.0.8
@ai-sdk/openai-compatible 2.0.33
@ai-sdk/togetherai 2.0.37
@ai-sdk/vercel 2.0.35
@ai-sdk/xai 3.0.64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/anthropic Issues related to the @ai-sdk/anthropic provider provider/openai-compatible Issues related to the @ai-sdk/openai-compatible provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants