mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 17:11:38 +00:00
fix(anthropic): preserve opus fallback pricing
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user