Skip to content
Open

Bedrock #1659

Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
"prettier-fix": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
"typecheck": "tsc --noEmit",
"prepare": "npm run build",
"prepublishOnly": "npm run build"
},
"keywords": [
Expand Down Expand Up @@ -65,13 +66,15 @@
"typescript-eslint": "^8.53.1"
},
"dependencies": {
"@ai-sdk/amazon-bedrock": "^3.0.84",
"@ai-sdk/anthropic": "^2.0.17",
"@ai-sdk/azure": "^2.0.79",
"@ai-sdk/deepseek": "^1.0.5",
"@ai-sdk/google": "^2.0.11",
"@ai-sdk/mistral": "^2.0.19",
"@ai-sdk/openai": "^2.0.32",
"@ai-sdk/xai": "^2.0.29",
"@aws-sdk/credential-providers": "^3.998.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

LGTM post-pin resolve

Copy link
Author

Choose a reason for hiding this comment

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

hello, version is fixed :) thanks for your work, sdk is working great :)

"@modelcontextprotocol/sdk": "^1.26.0",
"@openrouter/ai-sdk-provider": "^2.2.0",
"ai": "^6.0.50",
Expand Down
38 changes: 36 additions & 2 deletions sdk/src/model-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Supports both built-in providers and user-defined custom providers.
*/

import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";
import { fromIni, fromTemporaryCredentials, fromNodeProviderChain } from "@aws-sdk/credential-providers";
import { createAnthropic } from "@ai-sdk/anthropic";
import { createAzure } from "@ai-sdk/azure";
import { createDeepSeek } from "@ai-sdk/deepseek";
Expand Down Expand Up @@ -32,8 +34,8 @@ export interface CreateModelOptions {
baseUrls?: BaseUrls;
/** Custom providers registry (name -> config) */
customProviders?:
| Map<string, CustomProvider>
| Record<string, CustomProvider>;
| Map<string, CustomProvider>
| Record<string, CustomProvider>;
}

/** Built-in providers list */
Expand All @@ -47,6 +49,7 @@ const BUILT_IN_PROVIDERS: LLMProvider[] = [
"mistral",
"openrouter",
"xai",
"bedrock",
];

/**
Expand Down Expand Up @@ -252,6 +255,37 @@ export function createModelFromString(
return azure(model) as ProviderLanguageModel;
}

case "bedrock": {
const bedrockProfile = process.env.BEDROCK_PROFILE;
const bedrockRoleArn = process.env.BEDROCK_ROLE_ARN;
const bedrockSourceProfile = process.env.BEDROCK_SOURCE_PROFILE;
const bedrockRegion = process.env.AWS_REGION;

let credentialProvider;
if (bedrockRoleArn) {
const sourceCredentials = fromIni({
profile: bedrockSourceProfile ?? bedrockProfile,
});
credentialProvider = fromTemporaryCredentials({
masterCredentials: sourceCredentials,
params: {
RoleArn: bedrockRoleArn,
RoleSessionName: "bedrock-session",
},
});
} else if (bedrockProfile || process.env.AWS_PROFILE) {
credentialProvider = fromIni({ profile: bedrockProfile || process.env.AWS_PROFILE });
} else {
credentialProvider = fromNodeProviderChain();
}

const bedrock = createAmazonBedrock({
...(bedrockRegion && { region: bedrockRegion }),
credentialProvider,
});
return bedrock(model) as ProviderLanguageModel;
}

default: {
const _exhaustiveCheck: never = provider;
throw new Error(`Unhandled provider: ${_exhaustiveCheck}`);
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export type LLMProvider =
| "ollama"
| "mistral"
| "openrouter"
| "xai";
| "xai"
| "bedrock";

/**
* Compatible API protocols for custom providers
Expand Down