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: 5 additions & 0 deletions .changeset/exclude-chatgpt-from-prompt-cache-breakpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kilocode/cli": patch
---

Exclude ChatGPT subscriptions from explicit prompt cache breakpoints.
17 changes: 11 additions & 6 deletions packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,20 @@ function normalizeMessages(
return msgs
}

// kilocode_change start - explicit prompt cache breakpoints for GPT-5.6+
function supportsPromptCacheBreakpoint(modelId: string): boolean {
const match = modelId.match(/gpt-(\d+)\.(\d+)/)
// kilocode_change start - explicit prompt cache breakpoints for GPT-5.6+ (excluding ChatGPT subscriptions)
function isLikelyChatGPTSubscription(model: Provider.Model): boolean {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this is joke!

return model.providerID === "openai" && model.cost?.input === 0 && model.cost?.output === 0
}

function supportsPromptCacheBreakpoint(model: Provider.Model): boolean {
if (isLikelyChatGPTSubscription(model)) return false
const match = model.api.id.match(/gpt-(\d+)\.(\d+)/)
if (match) {
const major = Number(match[1])
const minor = Number(match[2])
if (major > 5 || (major === 5 && minor >= 6)) return true
}
const majorMatch = modelId.match(/gpt-(\d+)/)
const majorMatch = model.api.id.match(/gpt-(\d+)/)
if (majorMatch && Number(majorMatch[1]) >= 6) return true
return false
}
Expand Down Expand Up @@ -366,7 +371,7 @@ function applyCaching(msgs: ModelMessage[], model: Provider.Model): ModelMessage
cacheControl: { type: "ephemeral" },
},
// kilocode_change start
...(supportsPromptCacheBreakpoint(model.api.id)
...(supportsPromptCacheBreakpoint(model)
? {
openai: {
promptCacheBreakpoint: { mode: "explicit" },
Expand Down Expand Up @@ -494,7 +499,7 @@ export function message(msgs: ModelMessage[], model: Provider.Model, options: Re
((model.api.npm === "@ai-sdk/openai" ||
model.api.npm === "@ai-sdk/azure" ||
model.api.npm === "@kilocode/kilo-gateway") &&
supportsPromptCacheBreakpoint(model.api.id))) &&
supportsPromptCacheBreakpoint(model))) &&
model.api.npm !== "@ai-sdk/gateway"
) {
msgs = applyCaching(msgs, model)
Expand Down
32 changes: 32 additions & 0 deletions packages/opencode/test/provider/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3162,6 +3162,38 @@ describe("ProviderTransform.message - cache control on gateway", () => {
},
})
})

test("openai gpt-5.6 with ChatGPT subscription (zero cost heuristic) does not apply promptCacheBreakpoint", () => {
const model = createModel({
providerID: "openai",
api: {
id: "gpt-5.6",
url: "https://api.openai.com/v1",
npm: "@ai-sdk/openai",
},
id: "gpt-5.6",
cost: {
input: 0,
output: 0,
cache: { read: 0, write: 0 },
},
})
const msgs = [
{
role: "system",
content: "You are a helpful assistant",
},
{
role: "user",
content: "Hello",
},
] as any[]

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

expect(result[0].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined()
expect(result[1].providerOptions?.openai?.promptCacheBreakpoint).toBeUndefined()
})
// kilocode_change end
})

Expand Down
Loading