Skip to content

Commit 5904178

Browse files
committed
fix(responses): drop the retired prompt_cache_retention for gpt-5.6
The ChatGPT backend 400s a gpt-5.6 request that still carries prompt_cache_retention: "Unsupported parameter". GPT-5.6 replaced the field with prompt_cache_options.ttl. Strip it on the canonical ChatGPT forward path for the gpt-5.6 family only. The retired value is not translated into the replacement field: 5.6 carries a different TTL contract and implicit caching still applies, so inventing one would change a caching decision the caller never made. The narrowness is the fix, not an omission. An older model may still honor the field, and a self-hosted or third-party forward gateway may still accept it, so both axes are pinned by non-match tests. Based on @lilinxiong's implementation in #2102, with an exact-or-dashed-prefix family match so a future gpt-5.60 is not swept up. Closes #2092
1 parent 890d339 commit 5904178

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

‎src/adapters/openai-responses.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,28 @@ function stripUnsupportedReasoningParams(body: unknown): unknown {
185185
return { ...body, reasoning: Object.keys(rest).length > 0 ? rest : undefined };
186186
}
187187

188+
/**
189+
* GPT-5.6 replaced the legacy 24-hour retention field with `prompt_cache_options.ttl`, and the
190+
* ChatGPT backend 400s the whole request when the retired field is present (issue #2092).
191+
*
192+
* The retired field is NOT translated to the replacement: 5.6 carries a different TTL contract,
193+
* and implicit caching still applies when the caller sent no replacement options. Inventing a
194+
* value here would silently change a caching decision the caller never made.
195+
*
196+
* Deliberately narrow on both axes, because a wider strip is a behavior change rather than a fix:
197+
* only the gpt-5.6 family (an older model may still honor the field), and only on the canonical
198+
* ChatGPT backend, which is the deployment that rejects it. Matching is exact-or-dashed-prefix so
199+
* a future `gpt-5.60` is not swept up by a bare `startsWith`.
200+
*/
201+
function stripDeprecatedPromptCacheRetention(body: unknown, modelId: unknown): unknown {
202+
if (!isPlainObject(body)) return body;
203+
if (typeof modelId !== "string") return body;
204+
if (modelId !== "gpt-5.6" && !modelId.startsWith("gpt-5.6-")) return body;
205+
if (!Object.hasOwn(body, "prompt_cache_retention")) return body;
206+
const { prompt_cache_retention: _retention, ...rest } = body;
207+
return rest;
208+
}
209+
188210
/**
189211
* A false model capability prevents Codex from emitting summary fields after the catalog refresh.
190212
* Strip them here as well so an already-running client with a stale catalog cannot keep sending an
@@ -1491,6 +1513,11 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
14911513
}
14921514
if (forward) {
14931515
outBody = stripUnsupportedForwardParams(outBody);
1516+
// Only the canonical ChatGPT backend rejects the retired field; a self-hosted or
1517+
// third-party forward gateway may still accept it, so this must not be widened.
1518+
if (isCanonicalOpenAiForwardProvider(provider)) {
1519+
outBody = stripDeprecatedPromptCacheRetention(outBody, parsed.modelId);
1520+
}
14941521
} else {
14951522
outBody = preferConfiguredHostedTools(
14961523
outBody,

‎tests/openai-responses-passthrough.test.ts‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,92 @@ describe("OpenAI Responses passthrough sanitization", () => {
822822
expect(body.prompt_cache_retention).toBe("24h");
823823
});
824824

825+
/**
826+
* Issue #2092: the ChatGPT backend 400s a gpt-5.6 request that still carries the retired
827+
* `prompt_cache_retention`. The strip is deliberately narrow, and these cases pin the
828+
* narrowness itself — a wider strip passes the first block and fails the second.
829+
*/
830+
test.each(["gpt-5.6", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"])(
831+
"drops the retired prompt_cache_retention for %s without inventing replacement options",
832+
modelId => {
833+
const adapter = createResponsesPassthroughAdapter(provider);
834+
const request = adapter.buildRequest({
835+
modelId,
836+
context: { messages: [] },
837+
stream: true,
838+
options: {},
839+
_rawBody: { model: modelId, input: "hi", prompt_cache_retention: "24h" },
840+
}, { headers: new Headers({ authorization: "Bearer token" }) });
841+
const body = JSON.parse(request.body) as {
842+
prompt_cache_retention?: string;
843+
prompt_cache_options?: unknown;
844+
};
845+
846+
expect(body.prompt_cache_retention).toBeUndefined();
847+
// Translating "24h" into the replacement field would invent a caching decision the
848+
// caller never made, so absence must stay absence.
849+
expect(body.prompt_cache_options).toBeUndefined();
850+
},
851+
);
852+
853+
test("keeps caller-sent prompt_cache_options while dropping the retired retention", () => {
854+
const adapter = createResponsesPassthroughAdapter(provider);
855+
const request = adapter.buildRequest({
856+
modelId: "gpt-5.6-sol",
857+
context: { messages: [] },
858+
stream: true,
859+
options: {},
860+
_rawBody: {
861+
model: "gpt-5.6-sol",
862+
input: "hi",
863+
prompt_cache_retention: "24h",
864+
prompt_cache_options: { ttl: "30m" },
865+
},
866+
}, { headers: new Headers({ authorization: "Bearer token" }) });
867+
const body = JSON.parse(request.body) as {
868+
prompt_cache_retention?: string;
869+
prompt_cache_options?: { ttl?: string };
870+
};
871+
872+
expect(body.prompt_cache_retention).toBeUndefined();
873+
expect(body.prompt_cache_options).toEqual({ ttl: "30m" });
874+
});
875+
876+
test("a near-miss model id is not swept up by the gpt-5.6 family match", () => {
877+
const adapter = createResponsesPassthroughAdapter(provider);
878+
const request = adapter.buildRequest({
879+
modelId: "gpt-5.60",
880+
context: { messages: [] },
881+
stream: true,
882+
options: {},
883+
_rawBody: { model: "gpt-5.60", input: "hi", prompt_cache_retention: "24h" },
884+
}, { headers: new Headers({ authorization: "Bearer token" }) });
885+
const body = JSON.parse(request.body) as { prompt_cache_retention?: string };
886+
887+
// A bare startsWith("gpt-5.6") would strip here and silently change an unrelated model.
888+
expect(body.prompt_cache_retention).toBe("24h");
889+
});
890+
891+
test("a noncanonical forward gateway keeps the field even for gpt-5.6", () => {
892+
const adapter = createResponsesPassthroughAdapter({
893+
adapter: "openai-responses",
894+
baseUrl: "https://gateway.example/v1",
895+
authMode: "forward" as const,
896+
});
897+
const request = adapter.buildRequest({
898+
modelId: "gpt-5.6-sol",
899+
context: { messages: [] },
900+
stream: true,
901+
options: {},
902+
_rawBody: { model: "gpt-5.6-sol", input: "hi", prompt_cache_retention: "24h" },
903+
}, { headers: new Headers({ authorization: "Bearer token" }) });
904+
const body = JSON.parse(request.body) as { prompt_cache_retention?: string };
905+
906+
// Only the canonical ChatGPT backend is known to reject it. Stripping everywhere would be
907+
// a behavior change for deployments that still honor the field.
908+
expect(body.prompt_cache_retention).toBe("24h");
909+
});
910+
825911
const expandedRawBody = {
826912
model: "gpt-5.5",
827913
previous_response_id: "resp_1",

0 commit comments

Comments
 (0)