fix(ai): send Baseten session affinity headers

Enable session affinity for cataloged Baseten models so related requests reach the same replica and benefit from prompt caching.

Closes #9629
This commit is contained in:
David Brailovsky 2026-09-16 12:09:28 +02:00
parent 9b791a4cc1
commit 6671c60476
3 changed files with 13 additions and 0 deletions

View file

@ -20,6 +20,7 @@
- Removed GPT-5.4 and GPT-5.4 mini from the OpenAI Codex catalog after they became unavailable to ChatGPT accounts ([#9394](https://github.com/earendil-works/pi/issues/9394)).
- Fixed Mistral-hosted GLM-5.2 reasoning requests to use `reasoning_effort` instead of the ignored `prompt_mode` ([#9375](https://github.com/earendil-works/pi/issues/9375)).
- Fixed OpenAI-compatible Responses errors to identify the actual provider instead of always labeling them as OpenAI errors ([#9298](https://github.com/earendil-works/pi/issues/9298)).
- Fixed Baseten requests to send session-affinity headers from `sessionId` for automatic prompt-cache routing ([#9629](https://github.com/earendil-works/pi/issues/9629)).
## [0.85.1] - 2026-09-05

View file

@ -1333,6 +1333,10 @@ function processBasetenModels(provider: ModelsDevProvider | undefined): Model<Ap
supportsUsageInStreaming: true,
maxTokensField: "max_tokens",
supportsStrictMode: true,
// Baseten automatic prompt caching needs session affinity so related
// requests land on the same replica. See:
// https://docs.baseten.co/inference/model-apis/pricing-and-limits
sendSessionAffinityHeaders: true,
supportsLongCacheRetention: false,
};
const reasoningEffortCompat: OpenAICompletionsCompat = {

View file

@ -181,6 +181,14 @@ describe("openai-completions prompt caching", () => {
},
);
it("sends Baseten session affinity for built-in catalog models", async () => {
const model = getModel("baseten", "zai-org/GLM-5.2");
const { headers } = await captureRequest({ sessionId: "baseten-catalog-session" }, model);
expect(headers["x-session-affinity"]).toBe("baseten-catalog-session");
expect(headers["x-client-request-id"]).toBe("baseten-catalog-session");
});
it("uses OpenAI no-session format when configured", async () => {
const model = createModel({
compat: { sendSessionAffinityHeaders: true, sessionAffinityFormat: "openai-nosession" },