Repository navigation
Closed
Copy link
Labels
ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` labelrelated to a provider package. Must be assigned together with at least one `provider/*` labelmerged-mainmerged-v5.0merged-v6.0provider/amazon-bedrockIssues related to the @ai-sdk/amazon-bedrock providerIssues related to the @ai-sdk/amazon-bedrock providersupporttask-backport-v5.0-createdtask-backport-v6.0-createdtask-bug-reproduction-successtask-bug-reproduction-v5.0-successtask-bug-reproduction-v6.0-successtask-identify-issue-type-done
Description
Description
Expected Behavior
Streaming with citations: { enabled: true } should return a citation delta without validation errors.
Actual Behavior
Fails validation with AI_TypeValidationError because citation is not part of the union in BedrockStreamSchema.
The Bedrock response itself is valid and usable — the error only appears in server logs.
_TypeValidationError [AI_TypeValidationError]: Type validation failed: Value: {"contentBlockDelta":{"contentBlockIndex":3,"delta":{"citation":{"location":{"documentPage":{"documentIndex":0,"end":2,"start":1}},"sourceContent":[{"text":"CONTENT_OF_PDF"}],"title":"document-1"}}}}.
Error message: [{"code":"invalid_union","errors":[[{"expected":"string","code":"invalid_type","path":["text"],"message":"Invalid input: expected string, received undefined"}],[{"expected":"object","code":"invalid_type","path":["toolUse"],"message":"Invalid input: expected object, received undefined"}],[{"expected":"object","code":"invalid_type","path":["reasoningContent"],"message":"Invalid input: expected object, received undefined"}],[{"expected":"object","code":"invalid_type","path":["reasoningContent"],"message":"Invalid input: expected object, received undefined"}],[{"expected":"object","code":"invalid_type","path":["reasoningContent"],"message":"Invalid input: expected object, received undefined"}]],"path":["contentBlockDelta","delta"],"message":"Invalid input"}]
at Object.validate (/src/node_modules/@ai-sdk/provider-utils/src/validator.ts:69:18)
at processTicksAndRejections (node:internal/process/task_queues:105:5)
at async safeValidateTypes (/src/node_modules/@ai-sdk/provider-utils/src/validate-types.ts:64:20)
at async Object.transform (/src/node_modules/@ai-sdk/amazon-bedrock/src/bedrock-event-stream-response-handler.ts:81:48)
at async transformStreamDefaultControllerPerformTransform (node:internal/webstreams/transformstream:527:12) {
cause: [
{
code: 'invalid_union',
errors: [Array],
path: [Array],
message: 'Invalid input'
}
],
value: { contentBlockDelta: { contentBlockIndex: 3, delta: [Object] } },
[Symbol(vercel.ai.error)]: true,
[Symbol(vercel.ai.error.AI_TypeValidationError)]: true
}
Minimal reproduction
const stream = await client.streamText({
model: createAmazonBedrock({...})
messages: [
{
role: "user",
content: [
{
data: PDF_BUFFER,
mediaType: "application/pdf",
type: "file",
providerOptions: {
bedrock: {
citations: { enabled: true },
},
},
},
],
},
],
});
Proposed Solution
Extend BedrockStreamSchema to include citation as a valid delta type:
var BedrockStreamSchema = import_v43.z.object({
contentBlockDelta: import_v43.z.object({
contentBlockIndex: import_v43.z.number(),
delta: import_v43.z.union([
// add validation here
import_v43.z.object({ text: import_v43.z.string() }),
import_v43.z.object({ toolUse: import_v43.z.object({ input: import_v43.z.string() }) }),
import_v43.z.object({
reasoningContent: import_v43.z.object({ text: import_v43.z.string() })
}),
import_v43.z.object({
reasoningContent: import_v43.z.object({
signature: import_v43.z.string()
})
}),
import_v43.z.object({
reasoningContent: import_v43.z.object({ data: import_v43.z.string() })
})
]).nullish()
}).nullish(),
AI SDK Version
- ai: 5.0.59
- ai-sdk/amazon-bedrock: 3.0.29
Code of Conduct
- I agree to follow this project's Code of Conduct
Reacted by Hendy
Metadata
Metadata
Assignees
Labels
ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` labelrelated to a provider package. Must be assigned together with at least one `provider/*` labelmerged-mainmerged-v5.0merged-v6.0provider/amazon-bedrockIssues related to the @ai-sdk/amazon-bedrock providerIssues related to the @ai-sdk/amazon-bedrock providersupporttask-backport-v5.0-createdtask-backport-v6.0-createdtask-bug-reproduction-successtask-bug-reproduction-v5.0-successtask-bug-reproduction-v6.0-successtask-identify-issue-type-done
Activity
hendychua commentedon Feb 24, 2026
Hi, facing this issue too. Any updates or workarounds for now? Thank you.
lgrammel commentedon Jul 2, 2026
Identify issue type
{ "evidence": [ "Streaming Bedrock with `citations: { enabled: true }` fails with `AI_TypeValidationError` in `BedrockStreamSchema`.", "The reported Bedrock response contains a valid `delta.citation`, but the schema union only accepts text, toolUse, or reasoningContent variants.", "A commenter confirms they are facing the same issue and asks for workarounds." ], "rationale": "The issue describes current Amazon Bedrock streaming behavior throwing a validation error for valid citation deltas when citations are enabled, which is a concrete failure in existing SDK behavior.", "type": "bug", "confidence": "high" }ai-sdk-factory commentedon Jul 31, 2026
Bug Reproduction
Bug was reproduced.
Branch:
mainPR: successful reproduction pull request
Details
citations.enabled: truereturned documented citation deltas, but AI SDK emittedAI_TypeValidationErrorinstead of accepting them.packages/amazon-bedrock/src/amazon-bedrock-chat-language-model.tsstill omitscitationfromAmazonBedrockStreamSchemaon current main (@ai-sdk/amazon-bedrock5.0.38), so upgrading from the reported versions does not resolve the issue.packages/amazon-bedrock/src/__fixtures__/amazon-bedrock-document-citations.chunks.txtrecords the live provider response containing six citation deltas.packages/amazon-bedrock/src/amazon-bedrock-chat-language-model-citations.test.tsexpected zero citation validation errors but observed six when replaying the live fixture.examples/ai-functions/src/reproduction/issue-9101-bedrock-stream-citations.tsexpected citation-enabled streaming without validation errors but observed the reported failure against the live provider.Relevant Documentation
ai-sdk-factory commentedon Jul 31, 2026
Bugfix
Created bugfix and opened PR: #18250
Root Cause
AmazonBedrockStreamSchema omitted citation from its contentBlockDelta union. The live reproduction produced six citation validation errors, and the focused schema-validation regression test failed before the schema change.
Summary
Added citation objects to the Bedrock stream schema, added regression coverage, removed reproduction-only artifacts, and added a patch changeset for @ai-sdk/amazon-bedrock.
Testing
Added a streaming regression test that validates a representative citation delta through AmazonBedrockStreamSchema and asserts that no error part is emitted.
5 remaining items
fix: accept valid citation deltas in Amazon Bedrock streams (#18250)
ai-sdk-factory commentedon Aug 27, 2026
Backport to v5.0
created: #19891 (fixed merge).
ai-sdk-factory commentedon Aug 27, 2026
Backport to v6.0
created: #19892 (fixed merge).
[v6.0] fix: accept valid citation deltas in Amazon Bedrock streams (#…
[v5.0] fix: accept valid citation deltas in Amazon Bedrock streams (#…
github-actions commentedon Aug 28, 2026
🚀 Published in:
ai@ai-sdk/alibaba@ai-sdk/amazon-bedrock@ai-sdk/angular@ai-sdk/anthropic@ai-sdk/anthropic-aws@ai-sdk/assemblyai@ai-sdk/azure@ai-sdk/baseten@ai-sdk/black-forest-labs@ai-sdk/bytedance@ai-sdk/cartesia@ai-sdk/cerebras@ai-sdk/code-mode@ai-sdk/cohere@ai-sdk/deepgram@ai-sdk/deepinfra@ai-sdk/deepseek@ai-sdk/elevenlabs@ai-sdk/fal@ai-sdk/fireworks@ai-sdk/fish-audio@ai-sdk/gateway@ai-sdk/gladia@ai-sdk/gmicloud@ai-sdk/google@ai-sdk/google-vertex@ai-sdk/groq@ai-sdk/harness@ai-sdk/harness-acp@ai-sdk/harness-claude-code@ai-sdk/harness-cline@ai-sdk/harness-codex@ai-sdk/harness-cursor@ai-sdk/harness-deepagents@ai-sdk/harness-fx@ai-sdk/harness-grok-build@ai-sdk/harness-opencode@ai-sdk/harness-pi@ai-sdk/huggingface@ai-sdk/hume@ai-sdk/klingai@ai-sdk/langchain@ai-sdk/llamaindex@ai-sdk/lmnt@ai-sdk/luma@ai-sdk/mcp@ai-sdk/minimax@ai-sdk/mistral@ai-sdk/moonshotai@ai-sdk/open-responses@ai-sdk/openai@ai-sdk/openai-compatible@ai-sdk/otel@ai-sdk/perplexity@ai-sdk/policy-opa@ai-sdk/prodia@ai-sdk/provider-utils@ai-sdk/quiverai@ai-sdk/react@ai-sdk/replicate@ai-sdk/revai@ai-sdk/rsc@ai-sdk/sandbox-just-bash@ai-sdk/sandbox-vercel@ai-sdk/svelte@ai-sdk/togetherai@ai-sdk/tui@ai-sdk/valibot@ai-sdk/voyage@ai-sdk/vue@ai-sdk/workflow@ai-sdk/workflow-harness@ai-sdk/xai@ai-sdk/zai