fix: support Bedrock API key login
This commit is contained in:
@@ -152,7 +152,10 @@ export const stream: StreamFunction<"bedrock-converse-stream", BedrockOptions> =
|
||||
// Resolve bearer token for Bedrock API key auth.
|
||||
const skipAuth = getProviderEnvValue("AWS_BEDROCK_SKIP_AUTH", options.env) === "1";
|
||||
const bearerToken =
|
||||
options.bearerToken || getProviderEnvValue("AWS_BEARER_TOKEN_BEDROCK", options.env) || undefined;
|
||||
options.bearerToken ||
|
||||
options.apiKey ||
|
||||
getProviderEnvValue("AWS_BEARER_TOKEN_BEDROCK", options.env) ||
|
||||
undefined;
|
||||
const useBearerToken = bearerToken !== undefined && !skipAuth;
|
||||
|
||||
// in Node.js/Bun environment only
|
||||
|
||||
@@ -9,7 +9,11 @@ import { AMAZON_BEDROCK_MODELS } from "./amazon-bedrock.models.ts";
|
||||
* configured. A stored credential key is surfaced as the bearer token.
|
||||
*/
|
||||
const bedrockAuth: ApiKeyAuth = {
|
||||
name: "AWS credentials",
|
||||
name: "Bedrock API key or AWS credentials",
|
||||
login: async (callbacks) => ({
|
||||
type: "api_key",
|
||||
key: await callbacks.prompt({ type: "secret", message: "Enter Bedrock API key" }),
|
||||
}),
|
||||
resolve: async ({ ctx, credential }) => {
|
||||
if (credential?.key) return { auth: { apiKey: credential.key }, source: "stored credential" };
|
||||
if (await ctx.env("AWS_BEARER_TOKEN_BEDROCK")) return { auth: {}, source: "AWS_BEARER_TOKEN_BEDROCK" };
|
||||
|
||||
Reference in New Issue
Block a user