Skip to content

Claude w/ bedrock custom inference profile - no caching #9803

@stevoland

Description

@stevoland

Description

With custom inference profile model.api.id == arn:aws:bedrock:xxx:yyy:application-inference-profile/zzz so the special case for anthropic caching isn't entered:

if (
model.providerID === "anthropic" ||
model.api.id.includes("anthropic") ||
model.api.id.includes("claude") ||
model.api.npm === "@ai-sdk/anthropic"
) {
msgs = applyCaching(msgs, model.providerID)
}

and cached tokens always 0

tokens: {
    input: 19373,
    output: 12,
    reasoning: 0,
    cache: {
      write: 0,
      read: 0,
    },
  },

Propose this change

index f6b7ec8cbc..a0209b8c31 100644
--- a/packages/opencode/src/provider/transform.ts
+++ b/packages/opencode/src/provider/transform.ts
@@ -251,6 +251,8 @@
       model.providerID === "anthropic" ||
       model.api.id.includes("anthropic") ||
       model.api.id.includes("claude") ||
+      model.id.includes("anthropic") ||
+      model.id.includes("claude") ||
       model.api.npm === "@ai-sdk/anthropic"
     ) {
       msgs = applyCaching(msgs, model.providerID)

Which fixes for this config

"amazon-bedrock": {
  "options": {
    "profile": "xxx",
    "region": "yyy",
    "setCacheKey": true
  },
  "models": {
    "claude-sonnet-4.5": {
      "id": "arn:aws:bedrock:yyy:zzz:application-inference-profile/nnn"
    }
  }
},

Unless you have an alternative approach?

Will raise PR in the meantime, thanks!

Plugins

n/a

OpenCode version

1.1.26

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

macOS 26.2

Terminal

ghostty

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions