Skip to content

Commit a36ba8f

Browse files
committed
fix(ai): honor disabled Azure prompt caching
1 parent 9ce0fd8 commit a36ba8f

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

packages/ai/src/api/azure-openai-responses.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ function buildParams(
294294
model: deploymentName,
295295
input: messages,
296296
stream: true,
297-
prompt_cache_key: clampOpenAIPromptCacheKey(options?.sessionId),
297+
...((options?.cacheRetention ?? model.cacheRetention) === "none"
298+
? {}
299+
: { prompt_cache_key: clampOpenAIPromptCacheKey(options?.sessionId) }),
298300
store: false,
299301
};
300302

packages/ai/src/changes.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
- Added `supportsRemoteCompactionV2` so verified OpenAI Responses proxies can explicitly advertise the native
2727
`compaction_trigger` request contract. Unknown custom proxies remain disabled by default.
2828

29+
## 2026-07-27 - Honor disabled Azure Responses prompt caching
30+
31+
### What changed and why
32+
33+
- `api/azure-openai-responses.ts`: requests with `cacheRetention: "none"` now omit `prompt_cache_key`,
34+
matching the OpenAI Responses adapter instead of silently enabling Azure prompt-cache affinity from the
35+
session id.
36+
- `../test/azure-openai-base-url.test.ts`: pins both the existing 64-character cache-key clamp and the
37+
disabled-cache omission path.
38+
39+
### Expected merge conflict zones
40+
41+
- LOW: `api/azure-openai-responses.ts` request payload construction.
42+
2943
## 2026-07-27 - Treat Anthropic policy blocks as classifier refusals
3044

3145
### What changed and why

packages/ai/test/azure-openai-base-url.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ describe("azure-openai-responses base URL normalization", () => {
157157
expect(azureMock.lastParams?.prompt_cache_key).toBe("x".repeat(64));
158158
});
159159

160+
it("omits prompt_cache_key when caching is disabled", async () => {
161+
const model = getModel("azure-openai-responses", "gpt-4o-mini");
162+
await streamAzureOpenAIResponses(model, context, {
163+
apiKey: "test-api-key",
164+
azureBaseUrl: "https://my-resource.openai.azure.com",
165+
cacheRetention: "none",
166+
sessionId: "cache-disabled-session",
167+
}).result();
168+
169+
expect(azureMock.lastParams).not.toHaveProperty("prompt_cache_key");
170+
});
171+
160172
it("disables server-side response storage", async () => {
161173
const model = getModel("azure-openai-responses", "gpt-4o-mini");
162174
await streamAzureOpenAIResponses(model, context, {

0 commit comments

Comments
 (0)