Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bedrock-request-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ai-sdk/amazon-bedrock": patch
---

fix(amazon-bedrock): return `request.body` from `doGenerate` and `doStream`. Previously the Bedrock provider never populated the `request` field, so observability/tracing tools received `undefined` instead of the Converse API request payload.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ There are 3 r's.",
},
},
},
"request": {
"body": {
"additionalModelRequestFields": undefined,
"additionalModelResponseFieldPaths": [
"/delta/stop_sequence",
],
"messages": [
{
"content": [
{
"text": "Hello",
},
],
"role": "user",
},
],
"system": [
{
"text": "System Prompt",
},
],
},
},
"response": {
"headers": {
"content-length": "865",
Expand Down Expand Up @@ -107,6 +130,29 @@ There are **3** "r"s in "strawberry."",
},
},
},
"request": {
"body": {
"additionalModelRequestFields": undefined,
"additionalModelResponseFieldPaths": [
"/delta/stop_sequence",
],
"messages": [
{
"content": [
{
"text": "Hello",
},
],
"role": "user",
},
],
"system": [
{
"text": "System Prompt",
},
],
},
},
"response": {
"headers": {
"content-length": "435",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,43 @@ describe('doStream', () => {
`);
});

it('should return the request body', async () => {
setupMockEventStreamHandler();
server.urls[streamUrl].response = {
type: 'stream-chunks',
chunks: [],
};

const result = await model.doStream({
prompt: TEST_PROMPT,
includeRawChunks: false,
});

expect(result.request?.body).toMatchInlineSnapshot(`
{
"additionalModelRequestFields": undefined,
"additionalModelResponseFieldPaths": [
"/delta/stop_sequence",
],
"messages": [
{
"content": [
{
"text": "Hello",
},
],
"role": "user",
},
],
"system": [
{
"text": "System Prompt",
},
],
}
`);
});

it('should support guardrails', async () => {
setupMockEventStreamHandler();
server.urls[streamUrl].response = {
Expand Down Expand Up @@ -3225,6 +3262,36 @@ describe('doGenerate', () => {
expect(result).toMatchSnapshot();
});

it('should return the request body', async () => {
const result = await model.doGenerate({
prompt: TEST_PROMPT,
});

expect(result.request?.body).toMatchInlineSnapshot(`
{
"additionalModelRequestFields": undefined,
"additionalModelResponseFieldPaths": [
"/delta/stop_sequence",
],
"messages": [
{
"content": [
{
"text": "Hello",
},
],
"role": "user",
},
],
"system": [
{
"text": "System Prompt",
},
],
}
`);
});

it('should extract usage', async () => {
const { usage } = await model.doGenerate({
prompt: TEST_PROMPT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
raw: response.stopReason ?? undefined,
},
usage: convertAmazonBedrockUsage(response.usage),
request: { body: args },
response: {
id: responseHeaders?.['x-amzn-requestid'] ?? undefined,
timestamp:
Expand Down Expand Up @@ -1043,7 +1044,7 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
},
}),
),
// TODO request?
request: { body: args },
response: { headers: responseHeaders },
};
}
Expand Down