Skip to content

Commit 0e1a8a1

Browse files
fix: Claude w/bedrock custom inference profile - caching support (anomalyco#9838)
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
1 parent 178767a commit 0e1a8a1

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

packages/opencode/src/provider/transform.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ export namespace ProviderTransform {
248248
model.providerID === "anthropic" ||
249249
model.api.id.includes("anthropic") ||
250250
model.api.id.includes("claude") ||
251+
model.id.includes("anthropic") ||
252+
model.id.includes("claude") ||
251253
model.api.npm === "@ai-sdk/anthropic"
252254
) {
253255
msgs = applyCaching(msgs, model.providerID)

packages/opencode/test/provider/transform.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,41 @@ describe("ProviderTransform.message - providerOptions key remapping", () => {
996996
})
997997
})
998998

999+
describe("ProviderTransform.message - claude w/bedrock custom inference profile", () => {
1000+
test("adds cachePoint", () => {
1001+
const model = {
1002+
id: "amazon-bedrock/custom-claude-sonnet-4.5",
1003+
providerID: "amazon-bedrock",
1004+
api: {
1005+
id: "arn:aws:bedrock:xxx:yyy:application-inference-profile/zzz",
1006+
url: "https://api.test.com",
1007+
npm: "@ai-sdk/amazon-bedrock",
1008+
},
1009+
name: "Custom inference profile",
1010+
capabilities: {},
1011+
options: {},
1012+
headers: {},
1013+
} as any
1014+
1015+
const msgs = [
1016+
{
1017+
role: "user",
1018+
content: "Hello",
1019+
},
1020+
] as any[]
1021+
1022+
const result = ProviderTransform.message(msgs, model, {})
1023+
1024+
expect(result[0].providerOptions?.bedrock).toEqual(
1025+
expect.objectContaining({
1026+
cachePoint: {
1027+
type: "ephemeral",
1028+
},
1029+
}),
1030+
)
1031+
})
1032+
})
1033+
9991034
describe("ProviderTransform.variants", () => {
10001035
const createMockModel = (overrides: Partial<any> = {}): any => ({
10011036
id: "test/test-model",

packages/web/src/content/docs/providers.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,27 @@ To use Amazon Bedrock with OpenCode:
229229
/models
230230
```
231231

232+
:::note
233+
For custom inference profiles, use the model and provider name in the key and set the `id` property to the arn. This ensures correct caching:
234+
235+
```json title="opencode.json"
236+
{
237+
"$schema": "https://opencode.ai/config.json",
238+
"provider": {
239+
"amazon-bedrock": {
240+
// ...
241+
"models": {
242+
"anthropic-claude-sonnet-4.5": {
243+
"id": "arn:aws:bedrock:us-east-1:xxx:application-inference-profile/yyy"
244+
}
245+
}
246+
}
247+
}
248+
}
249+
```
250+
251+
:::
252+
232253
---
233254

234255
### Anthropic

0 commit comments

Comments
 (0)