fix(anthropic): preserve opus fallback pricing

This commit is contained in:
Vincent Koc
2026-07-25 19:26:09 +08:00
parent 4df130d0be
commit e94ece85b6
2 changed files with 6 additions and 24 deletions

View File

@@ -21,14 +21,15 @@ describe("Anthropic server-side fallback", () => {
},
);
it("preserves fast-mode pricing when Opus 5 falls back to Opus 4.8", () => {
it("preserves requested pricing when Opus 5 falls back to Opus 4.8", () => {
const customOpusCost = { input: 12, output: 60, cacheRead: 1.2, cacheWrite: 15 };
expect(
resolveAnthropicFallbackServingModelCost({
requestedModelId: "claude-opus-5",
servingModelId: "claude-opus-4-8",
requestedCost: OPUS_FAST_COST,
requestedCost: customOpusCost,
}),
).toEqual(OPUS_FAST_COST);
).toBe(customOpusCost);
});
it("keeps requested pricing for an unknown future fallback target", () => {

View File

@@ -20,27 +20,11 @@ export const CLAUDE_OPUS_FALLBACK_MODEL_COST = {
cacheWrite: 6.25,
} as const;
const CLAUDE_OPUS_FAST_FALLBACK_MODEL_COST = {
input: 10,
output: 50,
cacheRead: 1,
cacheWrite: 12.5,
} as const;
export type AnthropicFallbackBoundary = {
fromModel: string | null;
toModel: string | null;
};
function isModelCostEqual(left: Model["cost"], right: Model["cost"]): boolean {
return (
left.input === right.input &&
left.output === right.output &&
left.cacheRead === right.cacheRead &&
left.cacheWrite === right.cacheWrite
);
}
function resolveFallbackModelIdentity(modelId: string | null): string | null {
if (!modelId?.trim()) {
return null;
@@ -78,11 +62,8 @@ export function resolveAnthropicFallbackServingModelCost(params: {
) {
return params.requestedCost;
}
if (
requestedModelId === "claude-opus-5" &&
isModelCostEqual(params.requestedCost, CLAUDE_OPUS_FAST_FALLBACK_MODEL_COST)
) {
return CLAUDE_OPUS_FAST_FALLBACK_MODEL_COST;
if (requestedModelId && isClaudeOpusFallbackModel(requestedModelId)) {
return params.requestedCost;
}
return CLAUDE_OPUS_FALLBACK_MODEL_COST;
}