Skip to content

Commit ed4128c

Browse files
author
Karl Kurzer
committed
fix(provider): split Bedrock 1M context models into explicit 200K and 1M variants
Bedrock Claude Opus 4.6 and Sonnet 4.5 support 1M token context, but only when the anthropic_beta flag context-1m-2025-08-07 is sent in the request body. Without it, Bedrock enforces a 200K hard limit. Split these models at models.dev ingestion time into a safe 200K default and an opt-in 1M Experimental variant that sends the required beta flag via the AI SDK anthropicBeta provider option. Custom user-configured models are not affected. Closes anomalyco#13199
1 parent 62a24c2 commit ed4128c

2 files changed

Lines changed: 206 additions & 1 deletion

File tree

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,39 @@ export namespace Provider {
623623
})
624624
export type Info = z.infer<typeof Info>
625625

626+
const BEDROCK_1M_MODELS = ["claude-opus-4-6", "claude-sonnet-4-5"]
627+
const BEDROCK_1M_BETA = "context-1m-2025-08-07"
628+
629+
function splitBedrock1m(providerID: string, models: Record<string, Model>) {
630+
if (providerID !== "amazon-bedrock") return
631+
632+
for (const [id, model] of Object.entries(models)) {
633+
if (!BEDROCK_1M_MODELS.some((m) => model.api.id.includes(m))) continue
634+
if (id.endsWith("-1m")) continue
635+
636+
const name = model.name.replace(/\s+\((200K|1M Experimental)\)$/i, "")
637+
const opts = { ...model.options }
638+
const raw = opts["anthropicBeta"]
639+
const existing = (Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : []).filter(
640+
(item): item is string => typeof item === "string",
641+
)
642+
delete opts["anthropicBeta"]
643+
644+
model.name = `${name} (200K)`
645+
model.options = opts
646+
model.limit = { ...model.limit, context: Math.min(model.limit.context, 200_000) }
647+
648+
models[`${id}-1m`] = {
649+
...model,
650+
id: `${id}-1m`,
651+
name: `${name} (1M Experimental)`,
652+
status: "beta",
653+
limit: { ...model.limit, context: 1_000_000 },
654+
options: { ...model.options, anthropicBeta: [...new Set([...existing, BEDROCK_1M_BETA])] },
655+
}
656+
}
657+
}
658+
626659
function fromModelsDevModel(provider: ModelsDev.Provider, model: ModelsDev.Model): Model {
627660
const m: Model = {
628661
id: model.id,
@@ -691,13 +724,16 @@ export namespace Provider {
691724
}
692725

693726
export function fromModelsDevProvider(provider: ModelsDev.Provider): Info {
727+
const models = mapValues(provider.models, (model) => fromModelsDevModel(provider, model))
728+
splitBedrock1m(provider.id, models)
729+
694730
return {
695731
id: provider.id,
696732
source: "custom",
697733
name: provider.name,
698734
env: provider.env ?? [],
699735
options: {},
700-
models: mapValues(provider.models, (model) => fromModelsDevModel(provider, model)),
736+
models,
701737
}
702738
}
703739

‎packages/opencode/test/provider/provider.test.ts‎

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,175 @@ test("model headers are preserved", async () => {
14071407
})
14081408
})
14091409

1410+
test("fromModelsDevProvider splits bedrock opus 4.6 into 200K and 1M variants", () => {
1411+
const provider = Provider.fromModelsDevProvider({
1412+
id: "amazon-bedrock",
1413+
name: "Amazon Bedrock",
1414+
env: [],
1415+
models: {
1416+
"us.anthropic.claude-opus-4-6-v1:0": {
1417+
id: "us.anthropic.claude-opus-4-6-v1:0",
1418+
name: "Claude Opus 4.6",
1419+
attachment: true,
1420+
reasoning: true,
1421+
tool_call: true,
1422+
temperature: true,
1423+
release_date: "2026-02-05",
1424+
limit: { context: 1_000_000, output: 128_000 },
1425+
options: {
1426+
anthropicBeta: ["existing-beta"],
1427+
},
1428+
},
1429+
},
1430+
})
1431+
1432+
const base = provider.models["us.anthropic.claude-opus-4-6-v1:0"]
1433+
const extended = provider.models["us.anthropic.claude-opus-4-6-v1:0-1m"]
1434+
1435+
expect(base).toBeDefined()
1436+
expect(extended).toBeDefined()
1437+
1438+
expect(base.name).toContain("(200K)")
1439+
expect(extended.name).toContain("(1M Experimental)")
1440+
1441+
expect(base.limit.context).toBe(200_000)
1442+
expect(extended.limit.context).toBe(1_000_000)
1443+
1444+
expect(base.options.anthropicBeta).toBeUndefined()
1445+
expect(extended.options.anthropicBeta).toEqual(expect.arrayContaining(["existing-beta", "context-1m-2025-08-07"]))
1446+
1447+
expect(extended.api.id).toBe(base.api.id)
1448+
expect(extended.status).toBe("beta")
1449+
})
1450+
1451+
test("fromModelsDevProvider splits bedrock sonnet 4.5 into 200K and 1M variants", () => {
1452+
const provider = Provider.fromModelsDevProvider({
1453+
id: "amazon-bedrock",
1454+
name: "Amazon Bedrock",
1455+
env: [],
1456+
models: {
1457+
"us.anthropic.claude-sonnet-4-5-20250929-v1:0": {
1458+
id: "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
1459+
name: "Claude Sonnet 4.5",
1460+
attachment: true,
1461+
reasoning: true,
1462+
tool_call: true,
1463+
temperature: true,
1464+
release_date: "2025-09-29",
1465+
limit: { context: 1_000_000, output: 64_000 },
1466+
options: {},
1467+
},
1468+
},
1469+
})
1470+
1471+
const base = provider.models["us.anthropic.claude-sonnet-4-5-20250929-v1:0"]
1472+
const extended = provider.models["us.anthropic.claude-sonnet-4-5-20250929-v1:0-1m"]
1473+
1474+
expect(base).toBeDefined()
1475+
expect(extended).toBeDefined()
1476+
1477+
expect(base.name).toContain("(200K)")
1478+
expect(extended.name).toContain("(1M Experimental)")
1479+
1480+
expect(base.limit.context).toBe(200_000)
1481+
expect(extended.limit.context).toBe(1_000_000)
1482+
1483+
expect(extended.options.anthropicBeta).toEqual(["context-1m-2025-08-07"])
1484+
expect(extended.status).toBe("beta")
1485+
})
1486+
1487+
test("bedrock custom opus 4.6 model is not auto-split", async () => {
1488+
await using tmp = await tmpdir({
1489+
init: async (dir) => {
1490+
await Bun.write(
1491+
path.join(dir, "opencode.json"),
1492+
JSON.stringify({
1493+
$schema: "https://opencode.ai/config.json",
1494+
provider: {
1495+
"amazon-bedrock": {
1496+
models: {
1497+
"anthropic.claude-opus-4-6-v1:0": {
1498+
name: "Claude Opus 4.6",
1499+
attachment: true,
1500+
reasoning: true,
1501+
tool_call: true,
1502+
temperature: true,
1503+
limit: { context: 1_000_000, output: 64_000 },
1504+
},
1505+
},
1506+
},
1507+
},
1508+
}),
1509+
)
1510+
},
1511+
})
1512+
1513+
await Instance.provide({
1514+
directory: tmp.path,
1515+
fn: async () => {
1516+
const providers = await Provider.list()
1517+
const base = providers["amazon-bedrock"].models["anthropic.claude-opus-4-6-v1:0"]
1518+
const extended = providers["amazon-bedrock"].models["anthropic.claude-opus-4-6-v1:0-1m"]
1519+
1520+
expect(base).toBeDefined()
1521+
expect(extended).toBeUndefined()
1522+
expect(base.name).toBe("Claude Opus 4.6")
1523+
expect(base.limit.context).toBe(1_000_000)
1524+
expect(base.options.anthropicBeta).toBeUndefined()
1525+
},
1526+
})
1527+
})
1528+
1529+
test("fromModelsDevProvider does not split non-1m bedrock models", () => {
1530+
const provider = Provider.fromModelsDevProvider({
1531+
id: "amazon-bedrock",
1532+
name: "Amazon Bedrock",
1533+
env: [],
1534+
models: {
1535+
"us.anthropic.claude-haiku-4-20250414-v1:0": {
1536+
id: "us.anthropic.claude-haiku-4-20250414-v1:0",
1537+
name: "Claude Haiku 4",
1538+
attachment: true,
1539+
reasoning: false,
1540+
tool_call: true,
1541+
temperature: true,
1542+
release_date: "2025-04-14",
1543+
limit: { context: 200_000, output: 64_000 },
1544+
options: {},
1545+
},
1546+
},
1547+
})
1548+
1549+
const models = Object.keys(provider.models)
1550+
expect(models).toEqual(["us.anthropic.claude-haiku-4-20250414-v1:0"])
1551+
expect(provider.models["us.anthropic.claude-haiku-4-20250414-v1:0-1m"]).toBeUndefined()
1552+
})
1553+
1554+
test("fromModelsDevProvider does not split non-bedrock providers", () => {
1555+
const provider = Provider.fromModelsDevProvider({
1556+
id: "anthropic",
1557+
name: "Anthropic",
1558+
env: ["ANTHROPIC_API_KEY"],
1559+
models: {
1560+
"claude-opus-4-6": {
1561+
id: "claude-opus-4-6",
1562+
name: "Claude Opus 4.6",
1563+
attachment: true,
1564+
reasoning: true,
1565+
tool_call: true,
1566+
temperature: true,
1567+
release_date: "2026-02-05",
1568+
limit: { context: 200_000, output: 128_000 },
1569+
options: {},
1570+
},
1571+
},
1572+
})
1573+
1574+
const models = Object.keys(provider.models)
1575+
expect(models).toEqual(["claude-opus-4-6"])
1576+
expect(provider.models["claude-opus-4-6-1m"]).toBeUndefined()
1577+
})
1578+
14101579
test("provider env fallback - second env var used if first missing", async () => {
14111580
await using tmp = await tmpdir({
14121581
init: async (dir) => {

0 commit comments

Comments
 (0)