Skip to content

Commit 19fe0e0

Browse files
authored
fix(ai): preserve ambient AWS auth for Bedrock
Do not treat Pi’s internal ambient-auth marker as a Bedrock bearer token. This preserves SigV4 signing for AWS profiles, IAM credentials, and roles while retaining bearer authentication for real Bedrock API keys.\n\nFixes #6531
1 parent 4c18610 commit 19fe0e0

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

packages/ai/src/api/bedrock-converse-stream.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export interface BedrockOptions extends StreamOptions {
101101
type Block = (TextContent | ThinkingContent | ToolCall) & { index?: number; partialJson?: string };
102102

103103
const EMPTY_TEXT_PLACEHOLDER = "<empty>";
104+
const AMBIENT_AUTH_MARKER = "<authenticated>";
104105

105106
export const stream: StreamFunction<"bedrock-converse-stream", BedrockOptions> = (
106107
model: Model<"bedrock-converse-stream">,
@@ -153,7 +154,7 @@ export const stream: StreamFunction<"bedrock-converse-stream", BedrockOptions> =
153154
const skipAuth = getProviderEnvValue("AWS_BEDROCK_SKIP_AUTH", options.env) === "1";
154155
const bearerToken =
155156
options.bearerToken ||
156-
options.apiKey ||
157+
(options.apiKey !== AMBIENT_AUTH_MARKER ? options.apiKey : undefined) ||
157158
getProviderEnvValue("AWS_BEARER_TOKEN_BEDROCK", options.env) ||
158159
undefined;
159160
const useBearerToken = bearerToken !== undefined && !skipAuth;

packages/ai/test/bedrock-endpoint-resolution.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,13 @@ describe("bedrock endpoint resolution", () => {
190190
expect(config.token).toEqual({ token: "bedrock-api-key" });
191191
expect(config.authSchemePreference).toEqual(["httpBearerAuth"]);
192192
});
193+
194+
it("does not use the ambient AWS auth marker as a bearer token", async () => {
195+
const model = getModel("amazon-bedrock", "us.anthropic.claude-opus-4-8");
196+
197+
const config = await captureClientConfig(model, { apiKey: "<authenticated>" });
198+
199+
expect(config.token).toBeUndefined();
200+
expect(config.authSchemePreference).toBeUndefined();
201+
});
193202
});

0 commit comments

Comments
 (0)