fix(ai): enable cache control for OpenRouter aliases

closes #6940
This commit is contained in:
Mario Zechner
2026-07-22 11:46:21 +02:00
parent 33e40c3e15
commit 6f95a33888
9 changed files with 45 additions and 5 deletions
+4
View File
@@ -2,6 +2,10 @@
## [Unreleased]
### Fixed
- Fixed OpenRouter Anthropic cache breakpoints to advance through tool results and enabled cache control for `~anthropic/*-latest` aliases ([#6941](https://github.com/earendil-works/pi/pull/6941) by [@mteam88](https://github.com/mteam88)).
## [0.81.1] - 2026-07-21
### Added
+2 -1
View File
@@ -572,7 +572,8 @@ function detectOpenAICompletionsCompat(model: Model<"openai-completions">): Open
const isDeepSeek = provider === "deepseek" || baseUrl.includes("deepseek.com");
const isOpenRouterDeveloperRoleModel =
isOpenRouter && (model.id.startsWith("anthropic/") || model.id.startsWith("openai/"));
const cacheControlFormat = provider === "openrouter" && model.id.startsWith("anthropic/") ? "anthropic" : undefined;
const cacheControlFormat =
provider === "openrouter" && /^~?anthropic\//.test(model.id) ? "anthropic" : undefined;
return {
supportsStore: !isNonStandard,
@@ -193,6 +193,10 @@ export const OPENCODE_MODELS = values as {
id: "kimi-k2.7-code";
provider: "opencode";
};
"laguna-s-2.1-free": Model<"openai-completions"> & {
id: "laguna-s-2.1-free";
provider: "opencode";
};
"mimo-v2.5-free": Model<"openai-completions"> & {
id: "mimo-v2.5-free";
provider: "opencode";
@@ -745,6 +745,14 @@ export const OPENROUTER_MODELS = values as {
id: "poolside/laguna-m.1:free";
provider: "openrouter";
};
"poolside/laguna-s-2.1": Model<"openai-completions"> & {
id: "poolside/laguna-s-2.1";
provider: "openrouter";
};
"poolside/laguna-s-2.1:free": Model<"openai-completions"> & {
id: "poolside/laguna-s-2.1:free";
provider: "openrouter";
};
"poolside/laguna-xs-2.1": Model<"openai-completions"> & {
id: "poolside/laguna-xs-2.1";
provider: "openrouter";
@@ -637,6 +637,14 @@ export const VERCEL_AI_GATEWAY_MODELS = values as {
id: "openai/o4-mini";
provider: "vercel-ai-gateway";
};
"poolside/laguna-s-2.1": Model<"anthropic-messages"> & {
id: "poolside/laguna-s-2.1";
provider: "vercel-ai-gateway";
};
"poolside/laguna-s-2.1-free": Model<"anthropic-messages"> & {
id: "poolside/laguna-s-2.1-free";
provider: "vercel-ai-gateway";
};
"sakana/fugu-ultra": Model<"anthropic-messages"> & {
id: "sakana/fugu-ultra";
provider: "vercel-ai-gateway";
+1 -1
View File
@@ -524,7 +524,7 @@ export interface OpenAICompletionsCompat {
zaiToolStream?: boolean;
/** Whether the provider supports the `strict` field in tool definitions. Default: true. */
supportsStrictMode?: boolean;
/** Cache control convention for prompt caching. "anthropic" applies Anthropic-style `cache_control` markers to the system prompt, last tool definition, and last user/assistant text content. */
/** Cache control convention for prompt caching. "anthropic" applies Anthropic-style `cache_control` markers to the system prompt, last tool definition, and last user, assistant, or tool-result text content. */
cacheControlFormat?: "anthropic";
/** Whether to send session-affinity data from `options.sessionId`. Default: false. */
sendSessionAffinityHeaders?: boolean;
@@ -0,0 +1,15 @@
import { describe, expect, it } from "vitest";
import { getModel } from "../src/compat.ts";
const OPENROUTER_ANTHROPIC_LATEST_MODEL_IDS = [
"~anthropic/claude-fable-latest",
"~anthropic/claude-haiku-latest",
"~anthropic/claude-opus-latest",
"~anthropic/claude-sonnet-latest",
] as const;
describe("OpenRouter Anthropic cache control metadata", () => {
it.each(OPENROUTER_ANTHROPIC_LATEST_MODEL_IDS)("enables cache control for %s", (modelId) => {
expect(getModel("openrouter", modelId).compat?.cacheControlFormat).toBe("anthropic");
});
});