-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(provider/amazon-bedrock): Support citations in amazon-bedrock-provider #8861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This change helps some people using claude on bedrock. Could you review it? |
| async function shouldEnableCitations( | ||
| providerMetadata: SharedV2ProviderMetadata | undefined, | ||
| ): Promise<boolean> { | ||
| const bedrockOptions = await parseProviderOptions({ |
There was a problem hiding this comment.
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.
|
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 |
There was a problem hiding this 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'), |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
I'm really sorry. |
There was a problem hiding this 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
examples/ai-core/src/generate-object/amazon-bedrock-document-citations.ts
Outdated
Show resolved
Hide resolved
|
|
||
| async function main() { | ||
| const result = await generateObject({ | ||
| model: bedrock('apac.anthropic.claude-sonnet-4-20250514-v1:0'), |
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
…itations.ts Co-authored-by: Gregor Martynus <[email protected]>
examples/ai-core/src/generate-object/amazon-bedrock-document-citations.ts
Outdated
Show resolved
Hide resolved
| providerOptions: { | ||
| bedrock: { | ||
| citations: { enabled: true }, | ||
| }, | ||
| }, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
examples/ai-core/src/generate-object/amazon-bedrock-document-citations.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That worked, thanks!
…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]>
|
✅ Backport PR created: #9062 |
|
Thank you very, very, very much |
…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]>



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
Checklist
pnpm changesetin the project root)pnpm prettier-fixin the project root)Future Work
Related Issues