Skip to content

fix(bedrock): strip file extensions from filename#12971

Merged
aayush-kapoor merged 3 commits intovercel:mainfrom
heiwen:issue-11518-bedrock-file-attachments-are-broken
Mar 2, 2026
Merged

fix(bedrock): strip file extensions from filename#12971
aayush-kapoor merged 3 commits intovercel:mainfrom
heiwen:issue-11518-bedrock-file-attachments-are-broken

Conversation

@heiwen
Copy link
Copy Markdown
Contributor

@heiwen heiwen commented Mar 1, 2026

Background

This PR normalizes Bedrock document names derived from part.filename by stripping file extensions before sending requests in order to avoid Bedrock throwing an exception.

Summary

  • Added a shared stripFileExtension(filename: string) helper to @ai-sdk/provider-utils.
  • Exported the helper from provider-utils public index.
  • Updated Amazon Bedrock chat message conversion to use the helper for document name when part.filename is present.
  • Updated/added tests for Bedrock conversion behavior.
  • Added unit tests for the new helper.

Manual Verfication

repro example:
import { bedrock } from '@ai-sdk/amazon-bedrock';
import { generateText } from 'ai';
import fs from 'fs';
import { run } from '../../lib/run';

run(async () => {
  const result = await generateText({
    model: bedrock('global.anthropic.claude-sonnet-4-5-20250929-v1:0'),
    messages: [
      {
        role: 'user',
        content: [
          {
            type: 'text',
            text: 'Summarize the content of this text file in a few sentences.',
          },
          {
            type: 'file',
            data: fs.readFileSync('./data/error-message.txt'),
            mediaType: 'text/plain',
            filename: 'error-message.txt',
          },
        ],
      },
    ],
  });

  console.log('Response:', result.text);
  console.log();
  console.log('Finish reason:', result.finishReason);
  console.log('Usage:', result.usage);
});

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)

Future Work

n/a

Related Issues

Fixes #11518

@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/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider labels Mar 1, 2026
Copy link
Copy Markdown
Collaborator

@aayush-kapoor aayush-kapoor left a comment

Choose a reason for hiding this comment

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

before applying fix, it would help if we can reproduce the original issue described via an example. just for future prs, make sure to include a script in the manual verfication section of the PR description as a dropdown

@aayush-kapoor aayush-kapoor changed the title fix: issue 11518 - bedrock file attachments are broken fix(bedrock): strip file extensions from filename Mar 2, 2026
@aayush-kapoor aayush-kapoor enabled auto-merge (squash) March 2, 2026 22:17
@aayush-kapoor aayush-kapoor merged commit 08336f1 into vercel:main Mar 2, 2026
18 of 19 checks passed
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Mar 2, 2026

🚀 Published in:

Package Version
ai 6.0.107
@ai-sdk/alibaba 1.0.7
@ai-sdk/amazon-bedrock 4.0.71
@ai-sdk/angular 2.0.108
@ai-sdk/anthropic 3.0.52
@ai-sdk/assemblyai 2.0.22
@ai-sdk/azure 3.0.40
@ai-sdk/baseten 1.0.35
@ai-sdk/black-forest-labs 1.0.22
@ai-sdk/bytedance 1.0.2
@ai-sdk/cerebras 2.0.36
@ai-sdk/cohere 3.0.23
@ai-sdk/deepgram 2.0.22
@ai-sdk/deepinfra 2.0.36
@ai-sdk/deepseek 2.0.22
@ai-sdk/elevenlabs 2.0.22
@ai-sdk/fal 2.0.23
@ai-sdk/fireworks 2.0.37
@ai-sdk/gateway 3.0.61
@ai-sdk/gladia 2.0.22
@ai-sdk/google 3.0.36
@ai-sdk/google-vertex 4.0.70
@ai-sdk/groq 3.0.27
@ai-sdk/huggingface 1.0.34
@ai-sdk/hume 2.0.22
@ai-sdk/klingai 3.0.6
@ai-sdk/langchain 2.0.113
@ai-sdk/llamaindex 2.0.107
@ai-sdk/lmnt 2.0.22
@ai-sdk/luma 2.0.22
@ai-sdk/mcp 1.0.23
@ai-sdk/mistral 3.0.22
@ai-sdk/moonshotai 2.0.7
@ai-sdk/open-responses 1.0.4
@ai-sdk/openai 3.0.39
@ai-sdk/openai-compatible 2.0.32
@ai-sdk/perplexity 3.0.21
@ai-sdk/prodia 1.0.19
@ai-sdk/provider-utils 4.0.17
@ai-sdk/react 3.0.109
@ai-sdk/replicate 2.0.22
@ai-sdk/revai 2.0.22
@ai-sdk/rsc 2.0.107
@ai-sdk/svelte 4.0.107
@ai-sdk/togetherai 2.0.36
@ai-sdk/valibot 2.0.18
@ai-sdk/vercel 2.0.34
@ai-sdk/vue 3.0.107
@ai-sdk/xai 3.0.63

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/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bedrock] File attachments are broken - AI SDK v6

2 participants