Skip to content

Commit 561dee1

Browse files
fix(ai-sdk): log AI SDK v7 inline file data as attachments (#2752)
build off of #2751 fixes #2750 > πŸ€– **This text was AI-generated.** ## Problem With AI SDK v7, file parts carry their bytes in a tagged wrapper (`SharedV4FileData`): ```ts { type: "file", mediaType: "image/png", data: { type: "data", data: Uint8Array } } ``` The AI SDK plugin only turned bare bytes into attachments, so it copied this wrapper into the span as is. `deepCopyEvent` then turned the `Uint8Array` into an object with one key per byte. 1 MB of image became about 120 MB of heap on every model call (#2750). The plugin fix in #2751 had only a unit test. No e2e scenario sent a v7 tagged file part, so the real `streamText` path was never tested. ## Solution The plugin now converts the inner bytes to an attachment and keeps the v7 wrapper around it. The logged span has the same shape as the v7 input and matches how decision images are already logged: ```text before: data: { type: "data", data: { "0": 137, "1": 80, ... } } after: data: { type: "data", data: <braintrust_attachment image/png> } ``` The `ai-sdk-instrumentation` scenario gets a new `ai-sdk-stream-image-file-operation`. It streams a real 32x32 red PNG to OpenAI and checks that the top-level call span and the model call span each log one PNG attachment and no raw bytes. v7 sends the tagged form; v5 and v6 send plain bytes. The test fails without the fix. Other changes in this commit: - Remove the plugin unit test and two live-API image tests in `ai-sdk.test.ts`, which the new e2e test covers. Delete their unused `test-image.png` fixture. - Replace `gpt-4.1-nano` (deprecated) and `gpt-4o-mini` with `gpt-5.4-nano-2026-03-17`. AI SDK v3 stays on `gpt-4o-mini` because its OpenAI provider sends `max_tokens`, which GPT-5 models reject. - Send `providerOptions: { openai: { store: false } }` on multi-step tool calls for AI SDK v5+. This sends earlier tool calls in full instead of by ID, so recording also works for OpenAI orgs with Zero Data Retention. - Re-record all scenario cassettes and snapshots. --------- Co-authored-by: Paulo Martins <paulo.martins@nectir.io>
1 parent 43d5223 commit 561dee1

62 files changed

Lines changed: 57017 additions & 32447 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"braintrust": patch
3+
---
4+
5+
fix(ai-sdk): log AI SDK v7 inline file data as attachments

β€Že2e/scenarios/ai-sdk-instrumentation/__cassettes__/ai-sdk-v3-latest.cassette.jsonβ€Ž

Lines changed: 612 additions & 627 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Že2e/scenarios/ai-sdk-instrumentation/__cassettes__/ai-sdk-v3.cassette.jsonβ€Ž

Lines changed: 64 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Že2e/scenarios/ai-sdk-instrumentation/__cassettes__/ai-sdk-v4-latest.cassette.jsonβ€Ž

Lines changed: 726 additions & 767 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Že2e/scenarios/ai-sdk-instrumentation/__cassettes__/ai-sdk-v4.cassette.jsonβ€Ž

Lines changed: 724 additions & 766 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Že2e/scenarios/ai-sdk-instrumentation/__cassettes__/ai-sdk-v5-latest.cassette.blobs/2c099aa095f2b05364fcf83f92250c00bfa2e06b04b90ccfa50f8a8cb5201347.binβ€Ž

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Že2e/scenarios/ai-sdk-instrumentation/__cassettes__/ai-sdk-v5-latest.cassette.blobs/4e4ebafb2070bb860ec639976a0a3b7173caf3f10701e398e0a68f9c7a88c009.binβ€Ž

Lines changed: 0 additions & 25 deletions
This file was deleted.

β€Že2e/scenarios/ai-sdk-instrumentation/__cassettes__/ai-sdk-v5-latest.cassette.jsonβ€Ž

Lines changed: 1393 additions & 1238 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)