Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ export namespace ProviderTransform {
}

for (const msg of unique([...system, ...final])) {
const useMessageLevelOptions = model.providerID === "anthropic" || model.providerID.includes("bedrock")
const useMessageLevelOptions =
model.providerID === "anthropic" ||
model.providerID.includes("bedrock") ||
model.api.npm === "@ai-sdk/amazon-bedrock"
const shouldUseContentOptions = !useMessageLevelOptions && Array.isArray(msg.content) && msg.content.length > 0

if (shouldUseContentOptions) {
Expand Down
37 changes: 37 additions & 0 deletions packages/opencode/test/provider/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,43 @@ describe("ProviderTransform.message - claude w/bedrock custom inference profile"
})
})

describe("ProviderTransform.message - bedrock caching with non-bedrock providerID", () => {
test("applies cache options at message level when npm package is amazon-bedrock", () => {
const model = {
id: "aws/us.anthropic.claude-opus-4-6-v1",
providerID: "aws",
api: {
id: "us.anthropic.claude-opus-4-6-v1",
url: "https://bedrock-runtime.us-east-1.amazonaws.com",
npm: "@ai-sdk/amazon-bedrock",
},
name: "Claude Opus 4.6",
capabilities: {},
options: {},
headers: {},
} as any

const msgs = [
{
role: "system",
content: [{ type: "text", text: "You are a helpful assistant" }],
},
{
role: "user",
content: [{ type: "text", text: "Hello" }],
},
] as any[]

const result = ProviderTransform.message(msgs, model, {}) as any[]

// Cache should be at the message level and not the content-part level
expect(result[0].providerOptions?.bedrock).toEqual({
cachePoint: { type: "default" },
})
expect(result[0].content[0].providerOptions?.bedrock).toBeUndefined()
})
})

describe("ProviderTransform.message - cache control on gateway", () => {
const createModel = (overrides: Partial<any> = {}) =>
({
Expand Down
Loading