Skip to content

Conversation

@horita-yuya
Copy link
Contributor

@horita-yuya horita-yuya commented Sep 24, 2025

close #8511

Background

Summary

I added "citations" option as bedrock part provider options

We need this to analyze PDF using anthropic model through bedrock converse api.
https://docs.claude.com/en/docs/build-with-claude/pdf-support#amazon-bedrock-pdf-support

Reference:
Official type definition - https://github.com/aws/aws-sdk-js-v3/blob/281c666796e62691a6af521d21a87ad788b54c68/clients/client-bedrock-runtime/src/commands/ConverseCommand.ts#L80

Manual Verification

  1. I prepared pdf whose contents is only image, no text.
  2. I called bedrock anthropic model to extract information from it with citations: true and citations: false
  3. I checked if citations is enabled I could extract information, but not with citations disabled.

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)

Future Work

Related Issues

@horita-yuya
Copy link
Contributor Author

horita-yuya commented Sep 24, 2025

This change helps some people using claude on bedrock.

Could you review it?

@horita-yuya horita-yuya changed the title Support citations in amazon-bedrock-provider [I’m in trouble right now] Support citations in amazon-bedrock-provider Sep 24, 2025
@horita-yuya horita-yuya changed the title [I’m in trouble right now] Support citations in amazon-bedrock-provider feat(@ai-sdk/amazon-bedrock): Support citations in amazon-bedrock-provider Sep 24, 2025
async function shouldEnableCitations(
providerMetadata: SharedV2ProviderMetadata | undefined,
): Promise<boolean> {
const bedrockOptions = await parseProviderOptions({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed anthropic's implementation.

@horita-yuya
Copy link
Contributor Author

@gr2m

Hi, I'm in trouble right now. I need this feature or I have to strip out ai-sdk...

@gr2m
Copy link
Collaborator

gr2m commented Sep 25, 2025

Hi, I'm in trouble right now. I need this feature or I have to strip out ai-sdk...

preassure like this will never work, if anything it will achieve the opposite. If you need a patch urgently, you can release your own fork to npm

Copy link
Collaborator

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

Can you please add an example (like this one) and update the documentation for the bedrock provider at content/providers/01-ai-sdk-providers/08-amazon-bedrock.mdx

import fs from 'fs';

const result = await generateObject({
model: bedrock('apac.anthropic.claude-sonnet-4-20250514-v1:0'),
Copy link
Contributor Author

Choose a reason for hiding this comment

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


Amazon Bedrock supports citations for document-based inputs across compatible models. When enabled:
- Some models can read documents with visual understanding, not just extracting text
- Models can cite specific parts of documents you provide, making it easier to trace information back to its source (Not Supported Yet)
Copy link
Contributor Author

@horita-yuya horita-yuya Sep 25, 2025

Choose a reason for hiding this comment

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

Accessing citation parameters in response is not supported yet. May be another PR.

visual understanding reference:
https://docs.claude.com/en/docs/build-with-claude/pdf-support#amazon-bedrock-pdf-support

@horita-yuya
Copy link
Contributor Author

@gr2m

preassure like this will never work

I'm really sorry.

Copy link
Collaborator

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

Does the example that you added work for you?

You can run it with

cd examples/ai-core
pnpm tsx src/generate-object/amazon-bedrock-document-citations.ts

You might need to update/create examples/ai-core/.env and set ANTHROPIC_API_KEY


async function main() {
const result = await generateObject({
model: bedrock('apac.anthropic.claude-sonnet-4-20250514-v1:0'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

that model didn't work for me. I tried anthropic.claude-sonnet-4-20250514-v1:0 but got the error

APICallError [AI_APICallError]: Invocation of model ID anthropic.claude-sonnet-4-20250514-v1:0 with on-demand throughput isn’t supported. Retry your request with the ID or ARN of an inference profile that contains this model.

Copy link
Contributor Author

@horita-yuya horita-yuya Sep 25, 2025

Choose a reason for hiding this comment

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

Does the example that you added work for you?

Yes, I tried and it worked. I tried with old document.pdf then I deleted it not to commit it.
I changed it to ./data/ai.pdf following your review, #8861 (comment), it also worked.

スクリーンショット 2025-09-26 7 20 36

Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible that the apac.anthropic.claude-sonnet-4-20250514-v1:0 model id you set is bound to the API key you are using?

Copy link
Contributor Author

@horita-yuya horita-yuya Sep 25, 2025

Choose a reason for hiding this comment

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

I tried setting AWS_BEARER_TOKEN_BEDROCK key for easy.
But it should work setting AWS_ACCESS_KEY_ID="" , AWS_SECRET_ACCESS_KEY="" , AWS_REGION="" . These variables are already defined in .env.example.

スクリーンショット 2025-09-26 7 27 30

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not directly related, but just as a note I used sonnet 4 because pdf functionality of sonnet 3.5 is deprecated.

https://docs.claude.com/en/docs/build-with-claude/pdf-support#supported-platforms-and-models

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah I got it now. us.anthropic.claude-sonnet-4-20250514-v1:0 works for you, apac. stands for Asia-Pacific which probably correlates with your AWS region. I'll change it to us. since it will work for us, and we need these examples primarily for our own testing, cheers!

Comment on lines +26 to +30
providerOptions: {
bedrock: {
citations: { enabled: true },
},
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

the example behaves the same to me when I remove the providerOptions. What effect should it have? Does it need a PDF with certain content for it to work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.
PDF documents whose content is mainly texts works without this option.
But contents like graphs or images, you need this option to analyze correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you have such a pdf that we could use for this example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course. Try this one.

vercel-graph.pdf

citations: true

スクリーンショット 2025-09-26 9 13 32

citations: false

スクリーンショット 2025-09-26 9 13 48

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gr2m
Sorry for rushing you.
Could you try with this pdf?

@horita-yuya horita-yuya changed the title feat(@ai-sdk/amazon-bedrock): Support citations in amazon-bedrock-provider feat(provider/amazon-bedrock): Support citations in amazon-bedrock-provider Sep 30, 2025
Copy link
Collaborator

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

That worked, thanks!

@gr2m gr2m enabled auto-merge (squash) September 30, 2025 04:01
@gr2m gr2m merged commit c5e2a7c into vercel:main Sep 30, 2025
10 of 11 checks passed
vercel-ai-sdk bot pushed a commit that referenced this pull request Sep 30, 2025
…ovider (#8861)

## Summary

I added "citations" option as bedrock part provider options

We need this to analyze PDF using anthropic model through bedrock
converse api.

https://docs.claude.com/en/docs/build-with-claude/pdf-support#amazon-bedrock-pdf-support

Reference:
Official type definition -
https://github.com/aws/aws-sdk-js-v3/blob/281c666796e62691a6af521d21a87ad788b54c68/clients/client-bedrock-runtime/src/commands/ConverseCommand.ts#L80

## Manual Verification

1. I prepared pdf whose contents is only image, no text.
2. I called bedrock anthropic model to extract information from it with
citations: true and citations: false
3. I checked if citations is enabled I could extract information, but
not with citations disabled.

## Related Issues

close #8511

---------

Co-authored-by: Gregor Martynus <[email protected]>
@vercel-ai-sdk
Copy link
Contributor

vercel-ai-sdk bot commented Sep 30, 2025

✅ Backport PR created: #9062

@horita-yuya
Copy link
Contributor Author

horita-yuya commented Sep 30, 2025

Thank you very, very, very much

gr2m added a commit that referenced this pull request Sep 30, 2025
…bedrock-provider (#9062)

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

Co-authored-by: horita-yuya <[email protected]>
Co-authored-by: Gregor Martynus <[email protected]>
@gr2m gr2m added ai/provider provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider labels Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider feature request New feature or request 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.

Add support for Amazon Bedrock Citations Option within DocumentBlock object

2 participants