Skip to content

Commit 70ba002

Browse files
ntdatt812decolua
authored andcommitted
fix(translator): preserve prompt_cache_key when converting chat to responses
1 parent 80afb59 commit 70ba002

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎open-sse/translator/request/openai-responses.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ export function openaiToOpenAIResponsesRequest(model, body, stream, credentials)
421421
if (body.reasoning !== undefined) result.reasoning = body.reasoning;
422422
if (body.reasoning_effort !== undefined) result.reasoning = { effort: body.reasoning_effort, summary: "auto" };
423423
if (body.service_tier !== undefined) result.service_tier = body.service_tier;
424+
if (body.prompt_cache_key !== undefined) result.prompt_cache_key = body.prompt_cache_key;
424425

425426
return result;
426427
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
const { openaiToOpenAIResponsesRequest, openaiResponsesToOpenAIRequest } =
4+
await import("../../open-sse/translator/request/openai-responses.js");
5+
6+
const CHAT_BODY = (extra = {}) => ({
7+
model: "example-model",
8+
messages: [{ role: "user", content: "hello" }],
9+
...extra,
10+
});
11+
12+
describe("#3216 prompt_cache_key across the chat/responses translation", () => {
13+
it("preserves an explicit key when converting chat → responses", () => {
14+
const out = openaiToOpenAIResponsesRequest(
15+
"example-model",
16+
CHAT_BODY({ prompt_cache_key: "stable-cache-key" }),
17+
true,
18+
{},
19+
);
20+
21+
expect(out.prompt_cache_key).toBe("stable-cache-key");
22+
});
23+
24+
it("does not invent a key when the client sent none", () => {
25+
const out = openaiToOpenAIResponsesRequest("example-model", CHAT_BODY(), true, {});
26+
27+
expect(out.prompt_cache_key).toBeUndefined();
28+
});
29+
30+
it("still drops the key on the responses → chat direction", () => {
31+
const out = openaiResponsesToOpenAIRequest(
32+
"example-model",
33+
{
34+
model: "example-model",
35+
input: [{ role: "user", content: [{ type: "input_text", text: "hello" }] }],
36+
prompt_cache_key: "stable-cache-key",
37+
},
38+
true,
39+
{},
40+
);
41+
42+
expect(out.prompt_cache_key).toBeUndefined();
43+
});
44+
});

0 commit comments

Comments
 (0)