fix(translator): preserve prompt_cache_key when converting chat to responses

This commit is contained in:
Nguyen Thanh Dat
2026-08-13 11:45:45 +07:00
committed by decolua
parent 80afb59907
commit 70ba0024b0
2 changed files with 45 additions and 0 deletions

View File

@@ -421,6 +421,7 @@ export function openaiToOpenAIResponsesRequest(model, body, stream, credentials)
if (body.reasoning !== undefined) result.reasoning = body.reasoning;
if (body.reasoning_effort !== undefined) result.reasoning = { effort: body.reasoning_effort, summary: "auto" };
if (body.service_tier !== undefined) result.service_tier = body.service_tier;
if (body.prompt_cache_key !== undefined) result.prompt_cache_key = body.prompt_cache_key;
return result;
}

View File

@@ -0,0 +1,44 @@
import { describe, expect, it } from "vitest";
const { openaiToOpenAIResponsesRequest, openaiResponsesToOpenAIRequest } =
await import("../../open-sse/translator/request/openai-responses.js");
const CHAT_BODY = (extra = {}) => ({
model: "example-model",
messages: [{ role: "user", content: "hello" }],
...extra,
});
describe("#3216 prompt_cache_key across the chat/responses translation", () => {
it("preserves an explicit key when converting chat → responses", () => {
const out = openaiToOpenAIResponsesRequest(
"example-model",
CHAT_BODY({ prompt_cache_key: "stable-cache-key" }),
true,
{},
);
expect(out.prompt_cache_key).toBe("stable-cache-key");
});
it("does not invent a key when the client sent none", () => {
const out = openaiToOpenAIResponsesRequest("example-model", CHAT_BODY(), true, {});
expect(out.prompt_cache_key).toBeUndefined();
});
it("still drops the key on the responses → chat direction", () => {
const out = openaiResponsesToOpenAIRequest(
"example-model",
{
model: "example-model",
input: [{ role: "user", content: [{ type: "input_text", text: "hello" }] }],
prompt_cache_key: "stable-cache-key",
},
true,
{},
);
expect(out.prompt_cache_key).toBeUndefined();
});
});