Skip to content

feat(provider/anthropic): add return file_id property for anthropic code-execution-20250825 to download output files#9669

Merged
lgrammel merged 16 commits intovercel:mainfrom
tsuzaki430:tsuz/anthropic-code-execute-file-id
Oct 23, 2025
Merged

feat(provider/anthropic): add return file_id property for anthropic code-execution-20250825 to download output files#9669
lgrammel merged 16 commits intovercel:mainfrom
tsuzaki430:tsuz/anthropic-code-execute-file-id

Conversation

@tsuzaki430
Copy link
Copy Markdown
Collaborator

@tsuzaki430 tsuzaki430 commented Oct 20, 2025

Background

The Anthropic code execution bash tool provides a list of the generated files. This feature was missing from #9435 (although present in the zod schemas). It enables downloading generated files from the Anthropic API.

Summary

  • add response property file_id in code-execution-20250825
  • add example downloading file.

Example

Use code execution to have the AI ​​create an Excel file. Get the executed python code.
anthropic_code_execution_file_download

prompt:

Write a Python script to calculate fibonacci number and then execute it to find the 10th fibonacci number finally output data to excel file and python code.

Manual Verification

package/anthropic

  • packages/anthropic/src/anthropic-messages-language-model.test.ts
    • add fixtures anthropic-code-execution-20250825.2 for file_id return pattern.
    • check the snapshot and file_id was included in the result.

examples/ai-core

  • add the examples, src/stream-text/anthropic-code-execution-20250825-downloads.ts
  • add the examples, src/generate-text/anthropic-code-execution-20250825-downloads.ts

examples/next-openai

  • fix /components/tool/anthropic-code-execution-view.tsx (add a download button)
  • add route for submit native download api and provide files. /app/api/code-execution-files/anthropic/[file]/route.ts

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)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes gap from #9435

@tsuzaki430 tsuzaki430 marked this pull request as ready for review October 20, 2025 16:20
@tsuzaki430
Copy link
Copy Markdown
Collaborator Author

Hello ,
I finished self-review.
Thank you for every day's update!

@tsuzaki430 tsuzaki430 requested a review from lgrammel October 20, 2025 16:21
@lgrammel lgrammel changed the title feat(anthropic) add return file_id property for anthropic code-execution-20250825 to download output files. feat(provider/anthropic): add return file_id property for anthropic code-execution-20250825 to download output files Oct 23, 2025
Comment thread .changeset/shaggy-zebras-fetch.md Outdated
@lgrammel
Copy link
Copy Markdown
Collaborator

This is great! I'll update the changeset and merge.

@lgrammel lgrammel added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Oct 23, 2025
@tsuzaki430
Copy link
Copy Markdown
Collaborator Author

@lgrammel

Hello , thank you for the review😊
I just remove examples from changeset!

@lgrammel lgrammel self-assigned this Oct 23, 2025
@lgrammel lgrammel merged commit 80894b3 into vercel:main Oct 23, 2025
17 of 18 checks passed
vercel-ai-sdk bot pushed a commit that referenced this pull request Oct 23, 2025
@vercel-ai-sdk vercel-ai-sdk bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Oct 23, 2025
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Oct 23, 2025

⚠️ Backport to release-v5.0 created but has conflicts: #9737

lgrammel added a commit that referenced this pull request Oct 23, 2025
… anthropic code-execution-20250825 to download output files (#9737)

This is an automated backport of #9669 to the release-v5.0 branch.

---------

Co-authored-by: tsuzaki430 <58161200+tsuzaki430@users.noreply.github.com>
Co-authored-by: Lars Grammel <lars.grammel@gmail.com>
@tsuzaki430 tsuzaki430 deleted the tsuz/anthropic-code-execute-file-id branch October 23, 2025 11:48
@gr2m gr2m added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/anthropic Issues related to the @ai-sdk/anthropic provider labels Oct 27, 2025
@vishnukool
Copy link
Copy Markdown

Guys any documentation on how to download the said fileId ? Do we need to get it directly from anthropic ? or is there a way to seamlessly get it from AI SDK, the file ?

@tsuzaki430
Copy link
Copy Markdown
Collaborator Author

@vishnukool

Thanks for the question!

As far as I know, after you obtain the file_id from the AI SDK you need to call Anthropic’s Files API directly to download the file.

Here are examples that only use generateText / streamText:

  • examples/ai-core/src/generate-text/anthropic-code-execution-20250825-downloads.ts
  • examples/ai-core/src/stream-text/anthropic-code-execution-20250825-downloads.ts

And here is a Next.js example:

  • Next.js example
    cd examples/next-openai
    pnpm dev
    # then open:
    # http://localhost:3000/chat-anthropic-code-execution

The downloading route is here:
examples/next-openai/app/api/code-execution-files/anthropic/[file]/route.ts

I’m not sure there is dedicated documentation for this flow yet, but I’m confident that you can implement file downloads for code execution results in your app using this approach.

Does this help answer your question? 🙂

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants