Skip to content

Commit 9f42bd4

Browse files
authored
feat: bump bedrock and add proper mantle support for openai models through aws bedrock (#30464)
1 parent 2a33add commit 9f42bd4

12 files changed

Lines changed: 305 additions & 92 deletions

File tree

‎bun.lock‎

Lines changed: 24 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bunfig.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
exact = true
33
# Only install newly resolved package versions published at least 3 days ago.
44
minimumReleaseAge = 259200
5-
minimumReleaseAgeExcludes = ["@opentui/core", "@opentui/core-darwin-arm64", "@opentui/core-darwin-x64", "@opentui/core-linux-arm64", "@opentui/core-linux-x64", "@opentui/core-win32-arm64", "@opentui/core-win32-x64", "@opentui/keymap", "@opentui/solid", "gitlab-ai-provider"]
5+
minimumReleaseAgeExcludes = ["@ai-sdk/amazon-bedrock", "@opentui/core", "@opentui/core-darwin-arm64", "@opentui/core-darwin-x64", "@opentui/core-linux-arm64", "@opentui/core-linux-x64", "@opentui/core-win32-arm64", "@opentui/core-win32-x64", "@opentui/keymap", "@opentui/solid", "gitlab-ai-provider"]
66

77
[test]
88
root = "./do-not-run-tests-from-root"

‎packages/core/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
},
5656
"dependencies": {
5757
"@ai-sdk/alibaba": "1.0.17",
58-
"@ai-sdk/amazon-bedrock": "4.0.107",
58+
"@ai-sdk/amazon-bedrock": "4.0.112",
5959
"@ai-sdk/anthropic": "3.0.71",
6060
"@ai-sdk/azure": "3.0.49",
6161
"@ai-sdk/cerebras": "2.0.41",
@@ -74,7 +74,7 @@
7474
"@ai-sdk/togetherai": "2.0.41",
7575
"@ai-sdk/vercel": "2.0.39",
7676
"@ai-sdk/xai": "3.0.82",
77-
"@aws-sdk/credential-providers": "3.993.0",
77+
"@aws-sdk/credential-providers": "3.1057.0",
7878
"@effect/opentelemetry": "catalog:",
7979
"@effect/platform-node": "catalog:",
8080
"@effect/sql-sqlite-bun": "catalog:",

‎packages/core/src/aisdk.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ function prepareOptions(model: ModelV2.Info, pkg: string) {
8282
if (abortSignals.length === 1) opts.signal = abortSignals[0]
8383
if (abortSignals.length > 1) opts.signal = AbortSignal.any(abortSignals)
8484

85-
if ((pkg === "@ai-sdk/openai" || pkg === "@ai-sdk/azure") && opts.body && opts.method === "POST") {
85+
if (
86+
(pkg === "@ai-sdk/openai" || pkg === "@ai-sdk/azure" || pkg === "@ai-sdk/amazon-bedrock/mantle") &&
87+
opts.body &&
88+
opts.method === "POST"
89+
) {
8690
const body = JSON.parse(opts.body as string)
8791
if (body.store !== true && Array.isArray(body.input)) {
8892
for (const item of body.input) {

‎packages/core/src/plugin/provider/amazon-bedrock.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { Effect } from "effect"
2+
import type { LanguageModelV3 } from "@ai-sdk/provider"
23
import { PluginV2 } from "../../plugin"
34
import { ProviderV2 } from "../../provider"
45

6+
type MantleSDK = {
7+
languageModel: (modelID: string) => LanguageModelV3
8+
chat: (modelID: string) => LanguageModelV3
9+
responses: (modelID: string) => LanguageModelV3
10+
}
11+
512
// Bedrock cross-region inference profiles require regional prefixes only for
613
// specific model/region combinations. Keep the mapping narrow and avoid
714
// double-prefixing model IDs that models.dev already marks as global/us/eu/etc.
@@ -46,6 +53,12 @@ function resolveModelID(modelID: string, region: string | undefined) {
4653
: modelID
4754
}
4855

56+
function selectMantleModel(sdk: MantleSDK, modelID: string) {
57+
if (modelID === "openai.gpt-oss-safeguard-20b" || modelID === "openai.gpt-oss-safeguard-120b")
58+
return sdk.chat(modelID)
59+
return sdk.responses(modelID)
60+
}
61+
4962
export const AmazonBedrockPlugin = PluginV2.define({
5063
id: PluginV2.ID.make("amazon-bedrock"),
5164
effect: Effect.gen(function* () {
@@ -65,7 +78,7 @@ export const AmazonBedrockPlugin = PluginV2.define({
6578
}
6679
}),
6780
"aisdk.sdk": Effect.fn(function* (evt) {
68-
if (evt.package !== "@ai-sdk/amazon-bedrock") return
81+
if (!["@ai-sdk/amazon-bedrock", "@ai-sdk/amazon-bedrock/mantle"].includes(evt.package)) return
6982
const options = { ...evt.options }
7083
const profile = typeof options.profile === "string" ? options.profile : process.env.AWS_PROFILE
7184
const region = typeof options.region === "string" ? options.region : (process.env.AWS_REGION ?? "us-east-1")
@@ -86,11 +99,21 @@ export const AmazonBedrockPlugin = PluginV2.define({
8699
options.credentialProvider = fromNodeProviderChain(profile ? { profile } : {})
87100
}
88101

102+
if (evt.package === "@ai-sdk/amazon-bedrock/mantle") {
103+
const mod = yield* Effect.promise(() => import("@ai-sdk/amazon-bedrock/mantle"))
104+
evt.sdk = mod.createBedrockMantle(options)
105+
return
106+
}
107+
89108
const mod = yield* Effect.promise(() => import("@ai-sdk/amazon-bedrock"))
90109
evt.sdk = mod.createAmazonBedrock(options)
91110
}),
92111
"aisdk.language": Effect.fn(function* (evt) {
93112
if (evt.model.providerID !== ProviderV2.ID.amazonBedrock) return
113+
if (evt.model.api.type === "aisdk" && evt.model.api.package === "@ai-sdk/amazon-bedrock/mantle") {
114+
evt.language = selectMantleModel(evt.sdk, evt.model.api.id)
115+
return
116+
}
94117
const region = typeof evt.options.region === "string" ? evt.options.region : process.env.AWS_REGION
95118
evt.language = evt.sdk.languageModel(resolveModelID(evt.model.api.id, region))
96119
}),

‎packages/core/test/plugin/provider-amazon-bedrock.test.ts‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ function bedrockFetch(sdk: unknown, modelID = "anthropic.claude-sonnet-4-5") {
1818
).config.fetch
1919
}
2020

21+
function openAIUrl(language: unknown, path: string, modelId: string) {
22+
return (language as { config: { url: (input: { path: string; modelId: string }) => string } }).config.url({
23+
path,
24+
modelId,
25+
})
26+
}
27+
2128
describe("AmazonBedrockPlugin", () => {
2229
it.effect("moves endpoint option to api URL", () =>
2330
Effect.gen(function* () {
@@ -242,6 +249,85 @@ describe("AmazonBedrockPlugin", () => {
242249
),
243250
)
244251

252+
it.effect("creates Mantle SDK with GPT-5 OpenAI base path", () =>
253+
withEnv({ AWS_BEARER_TOKEN_BEDROCK: undefined, AWS_PROFILE: undefined, AWS_ACCESS_KEY_ID: undefined }, () =>
254+
Effect.gen(function* () {
255+
const plugin = yield* PluginV2.Service
256+
yield* plugin.add(AmazonBedrockPlugin)
257+
const result = yield* plugin.trigger(
258+
"aisdk.sdk",
259+
{
260+
model: model("amazon-bedrock", "openai.gpt-5.5", {
261+
api: { type: "aisdk", package: "@ai-sdk/amazon-bedrock/mantle" },
262+
}),
263+
package: "@ai-sdk/amazon-bedrock/mantle",
264+
options: {
265+
name: "amazon-bedrock",
266+
bearerToken: "token",
267+
baseURL: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
268+
region: "us-east-2",
269+
},
270+
},
271+
{},
272+
)
273+
const language = result.sdk.responses("openai.gpt-5.5")
274+
expect(openAIUrl(language, "/responses", "openai.gpt-5.5")).toBe(
275+
"https://bedrock-mantle.us-east-2.api.aws/openai/v1/responses",
276+
)
277+
}),
278+
),
279+
)
280+
281+
it.effect("selects Mantle APIs without Bedrock cross-region prefixes", () =>
282+
Effect.gen(function* () {
283+
const plugin = yield* PluginV2.Service
284+
const calls: string[] = []
285+
yield* plugin.add(AmazonBedrockPlugin)
286+
yield* plugin.trigger(
287+
"aisdk.language",
288+
{
289+
model: model("amazon-bedrock", "openai.gpt-5.5", {
290+
api: { type: "aisdk", package: "@ai-sdk/amazon-bedrock/mantle" },
291+
}),
292+
sdk: fakeSelectorSdk(calls),
293+
options: { baseURL: "https://bedrock-mantle.us-east-2.api.aws/openai/v1", region: "us-east-2" },
294+
},
295+
{},
296+
)
297+
yield* plugin.trigger(
298+
"aisdk.language",
299+
{
300+
model: model("amazon-bedrock", "openai.gpt-oss-safeguard-120b", {
301+
api: { type: "aisdk", package: "@ai-sdk/amazon-bedrock/mantle" },
302+
}),
303+
sdk: fakeSelectorSdk(calls),
304+
options: { region: "us-east-1" },
305+
},
306+
{},
307+
)
308+
expect(calls).toEqual(["responses:openai.gpt-5.5", "chat:openai.gpt-oss-safeguard-120b"])
309+
}),
310+
)
311+
312+
it.effect("ignores other Bedrock provider subpaths", () =>
313+
Effect.gen(function* () {
314+
const plugin = yield* PluginV2.Service
315+
yield* plugin.add(AmazonBedrockPlugin)
316+
const result = yield* plugin.trigger(
317+
"aisdk.sdk",
318+
{
319+
model: model("amazon-bedrock", "anthropic.claude-sonnet-4-5", {
320+
api: { type: "aisdk", package: "@ai-sdk/amazon-bedrock/anthropic" },
321+
}),
322+
package: "@ai-sdk/amazon-bedrock/anthropic",
323+
options: { name: "amazon-bedrock" },
324+
},
325+
{},
326+
)
327+
expect(result.sdk).toBeUndefined()
328+
}),
329+
)
330+
245331
it.effect("uses SigV4 credential env when bearer token is absent", () =>
246332
withEnv(
247333
{

‎packages/opencode/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@actions/github": "6.0.1",
5858
"@agentclientprotocol/sdk": "0.21.0",
5959
"@ai-sdk/alibaba": "1.0.17",
60-
"@ai-sdk/amazon-bedrock": "4.0.107",
60+
"@ai-sdk/amazon-bedrock": "4.0.112",
6161
"@ai-sdk/anthropic": "3.0.71",
6262
"@ai-sdk/azure": "3.0.49",
6363
"@ai-sdk/cerebras": "2.0.41",
@@ -75,7 +75,7 @@
7575
"@ai-sdk/togetherai": "2.0.41",
7676
"@ai-sdk/vercel": "2.0.39",
7777
"@ai-sdk/xai": "3.0.82",
78-
"@aws-sdk/credential-providers": "3.993.0",
78+
"@aws-sdk/credential-providers": "3.1057.0",
7979
"@clack/prompts": "1.0.0-alpha.1",
8080
"@effect/opentelemetry": "catalog:",
8181
"@effect/platform-node": "catalog:",

‎packages/opencode/src/provider/provider.ts‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,13 @@ function googleVertexAnthropicBaseURL(project: string | undefined, location: str
100100

101101
type BundledSDK = {
102102
languageModel(modelId: string): LanguageModelV3
103+
chat?: (modelId: string) => LanguageModelV3
104+
responses?: (modelId: string) => LanguageModelV3
103105
}
104106

105107
const BUNDLED_PROVIDERS: Record<string, () => Promise<(opts: any) => BundledSDK>> = {
106108
"@ai-sdk/amazon-bedrock": () => import("@ai-sdk/amazon-bedrock").then((m) => m.createAmazonBedrock),
109+
"@ai-sdk/amazon-bedrock/mantle": () => import("@ai-sdk/amazon-bedrock/mantle").then((m) => m.createBedrockMantle),
107110
"@ai-sdk/anthropic": () => import("@ai-sdk/anthropic").then((m) => m.createAnthropic),
108111
"@ai-sdk/azure": () => import("@ai-sdk/azure").then((m) => m.createAzure),
109112
"@ai-sdk/google": () => import("@ai-sdk/google").then((m) => m.createGoogleGenerativeAI),
@@ -130,7 +133,7 @@ const BUNDLED_PROVIDERS: Record<string, () => Promise<(opts: any) => BundledSDK>
130133
"venice-ai-sdk-provider": () => import("venice-ai-sdk-provider").then((m) => m.createVenice),
131134
}
132135

133-
type CustomModelLoader = (sdk: any, modelID: string, options?: Record<string, any>) => Promise<any>
136+
type CustomModelLoader = (sdk: any, modelID: string, options?: Record<string, any>, model?: Model) => Promise<any>
134137
type CustomVarsLoader = (options: Record<string, any>) => Record<string, string>
135138
type CustomDiscoverModels = () => Promise<Record<string, Model>>
136139
type CustomLoader = (provider: Info) => Effect.Effect<{
@@ -156,6 +159,12 @@ function selectAzureLanguageModel(sdk: any, modelID: string, useChat: boolean) {
156159
return sdk.languageModel(modelID)
157160
}
158161

162+
function selectBedrockMantleLanguageModel(sdk: BundledSDK, modelID: string) {
163+
if (modelID === "openai.gpt-oss-safeguard-20b" || modelID === "openai.gpt-oss-safeguard-120b")
164+
return sdk.chat?.(modelID) ?? sdk.languageModel(modelID)
165+
return sdk.responses?.(modelID) ?? sdk.languageModel(modelID)
166+
}
167+
159168
function custom(dep: CustomDep): Record<string, CustomLoader> {
160169
return {
161170
anthropic: () =>
@@ -331,7 +340,9 @@ function custom(dep: CustomDep): Record<string, CustomLoader> {
331340
return {
332341
autoload: true,
333342
options: providerOptions,
334-
async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
343+
async getModel(sdk: any, modelID: string, options?: Record<string, any>, model?: Model) {
344+
if (model?.api.npm === "@ai-sdk/amazon-bedrock/mantle") return selectBedrockMantleLanguageModel(sdk, modelID)
345+
335346
// Skip region prefixing if model already has a cross-region inference profile prefix
336347
// Models from models.dev may already include prefixes like us., eu., global., etc.
337348
const crossRegionPrefixes = ["global.", "us.", "eu.", "jp.", "apac.", "au."]
@@ -1618,7 +1629,9 @@ export const layer = Layer.effect(
16181629

16191630
// Strip openai itemId metadata following what codex does
16201631
if (
1621-
(model.api.npm === "@ai-sdk/openai" || model.api.npm === "@ai-sdk/azure") &&
1632+
(model.api.npm === "@ai-sdk/openai" ||
1633+
model.api.npm === "@ai-sdk/azure" ||
1634+
model.api.npm === "@ai-sdk/amazon-bedrock/mantle") &&
16221635
opts.body &&
16231636
opts.method === "POST"
16241637
) {
@@ -1725,10 +1738,15 @@ export const layer = Layer.effect(
17251738
async () => {
17261739
const sdk = await resolveSDK(model, s, envs)
17271740
const language = s.modelLoaders[model.providerID]
1728-
? await s.modelLoaders[model.providerID](sdk, model.api.id, {
1729-
...provider.options,
1730-
...model.options,
1731-
})
1741+
? await s.modelLoaders[model.providerID](
1742+
sdk,
1743+
model.api.id,
1744+
{
1745+
...provider.options,
1746+
...model.options,
1747+
},
1748+
model,
1749+
)
17321750
: sdk.languageModel(model.api.id)
17331751
s.models.set(key, language)
17341752
return language

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ function sdkKey(npm: string): string | undefined {
3535
return "azure"
3636
case "@ai-sdk/openai":
3737
return "openai"
38+
case "@ai-sdk/amazon-bedrock/mantle":
39+
return "openai"
3840
case "@ai-sdk/amazon-bedrock":
3941
return "bedrock"
4042
case "@ai-sdk/anthropic":
@@ -815,6 +817,7 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
815817
},
816818
]),
817819
)
820+
case "@ai-sdk/amazon-bedrock/mantle":
818821
case "@ai-sdk/openai": {
819822
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/openai
820823
const efforts = openaiReasoningEfforts(model.api.id, model.release_date)
@@ -1021,7 +1024,8 @@ export function options(input: {
10211024
if (
10221025
input.model.providerID === "openai" ||
10231026
input.model.api.npm === "@ai-sdk/openai" ||
1024-
input.model.api.npm === "@ai-sdk/github-copilot"
1027+
input.model.api.npm === "@ai-sdk/github-copilot" ||
1028+
input.model.api.npm === "@ai-sdk/amazon-bedrock/mantle"
10251029
) {
10261030
result["store"] = false
10271031
}
@@ -1107,7 +1111,7 @@ export function options(input: {
11071111
if (!input.model.api.id.includes("gpt-5-pro")) {
11081112
result["reasoningEffort"] = "medium"
11091113
result["reasoningSummary"] = "auto"
1110-
if (input.model.api.npm === "@ai-sdk/openai") {
1114+
if (input.model.api.npm === "@ai-sdk/openai" || input.model.api.npm === "@ai-sdk/amazon-bedrock/mantle") {
11111115
result["include"] = INCLUDE_ENCRYPTED_REASONING
11121116
}
11131117
}

‎packages/opencode/src/session/message-v2.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export const toModelMessagesEffect = Effect.fnUntraced(function* (
159159
const supportsMediaInToolResult = (attachment: { mime: string }) => {
160160
if (model.api.npm === "@ai-sdk/anthropic") return true
161161
if (model.api.npm === "@ai-sdk/openai") return true
162+
if (model.api.npm === "@ai-sdk/amazon-bedrock/mantle") return true
162163
if (model.api.npm === "@ai-sdk/amazon-bedrock") return attachment.mime.startsWith("image/")
163164
if (model.api.npm === "@ai-sdk/xai") return attachment.mime.startsWith("image/")
164165
if (model.api.npm === "@ai-sdk/google-vertex/anthropic") return true

0 commit comments

Comments
 (0)