Skip to content

Commit deda6fa

Browse files
committed
fix(responses): strip unsupported cache retention
1 parent f2e5e76 commit deda6fa

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

‎src/adapters/openai-responses.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,15 +909,24 @@ function stripStatefulResponsesParams(body: unknown): unknown {
909909
* with `{"detail":"Unsupported parameter: …"}` (strict allowlist). Codex CLI never
910910
* sends these — it controls output length via `reasoning.effort` — but third-party
911911
* Responses API clients (GJC, SDK wrappers) include `max_output_tokens` per the
912-
* public spec. `metadata` is likewise absent from the allowlist. No-op when the
913-
* body carries neither field, keeping the common Codex path allocation-free.
912+
* public spec. `metadata` is likewise absent from the allowlist. Codex can also
913+
* send `prompt_cache_retention`, but the ChatGPT backend rejects it for models
914+
* that do not expose extended retention instead of falling back to normal cache
915+
* retention. No-op when the body carries none of these fields, keeping the common
916+
* Codex path allocation-free. API-key Responses requests retain all three fields.
914917
*/
915918
function stripUnsupportedForwardParams(body: unknown): unknown {
916919
if (!isPlainObject(body)) return body;
917920
const hasMot = Object.prototype.hasOwnProperty.call(body, "max_output_tokens");
918921
const hasMeta = Object.prototype.hasOwnProperty.call(body, "metadata");
919-
if (!hasMot && !hasMeta) return body;
920-
const { max_output_tokens: _mot, metadata: _meta, ...rest } = body;
922+
const hasPromptCacheRetention = Object.prototype.hasOwnProperty.call(body, "prompt_cache_retention");
923+
if (!hasMot && !hasMeta && !hasPromptCacheRetention) return body;
924+
const {
925+
max_output_tokens: _mot,
926+
metadata: _meta,
927+
prompt_cache_retention: _promptCacheRetention,
928+
...rest
929+
} = body;
921930
return rest;
922931
}
923932

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,13 @@ describe("OpenAI Responses passthrough sanitization", () => {
804804
expect(body.prompt_cache_key).toBe("project-cache-v1");
805805
});
806806

807-
test("preserves prompt_cache_retention in the raw Responses passthrough body", () => {
808-
const adapter = createResponsesPassthroughAdapter(provider);
807+
test("preserves prompt_cache_retention for OpenAI API-key Responses requests", () => {
808+
const adapter = createResponsesPassthroughAdapter({
809+
adapter: "openai-responses",
810+
baseUrl: "https://api.openai.com/v1",
811+
authMode: "key",
812+
apiKey: "sk-test",
813+
});
809814
const request = adapter.buildRequest({
810815
modelId: "gpt-5.5",
811816
context: { messages: [] },
@@ -822,6 +827,24 @@ describe("OpenAI Responses passthrough sanitization", () => {
822827
expect(body.prompt_cache_retention).toBe("24h");
823828
});
824829

830+
test("strips prompt_cache_retention from ChatGPT forward requests", () => {
831+
const adapter = createResponsesPassthroughAdapter(provider);
832+
const request = adapter.buildRequest({
833+
modelId: "gpt-5.5",
834+
context: { messages: [] },
835+
stream: true,
836+
options: {},
837+
_rawBody: {
838+
model: "gpt-5.5",
839+
input: "hi",
840+
prompt_cache_retention: "24h",
841+
},
842+
}, { headers: new Headers({ authorization: "Bearer token" }) });
843+
const body = JSON.parse(request.body) as { prompt_cache_retention?: string };
844+
845+
expect(body).not.toHaveProperty("prompt_cache_retention");
846+
});
847+
825848
const expandedRawBody = {
826849
model: "gpt-5.5",
827850
previous_response_id: "resp_1",

0 commit comments

Comments
 (0)