Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions open-sse/config/providerRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface RegistryModel {
toolCalling?: boolean;
supportsReasoning?: boolean;
supportsVision?: boolean;
supportsXHighEffort?: boolean;
targetFormat?: string;
unsupportedParams?: readonly string[];
/** Maximum context window in tokens */
Expand Down Expand Up @@ -277,12 +278,20 @@ export const REGISTRY: Record<string, RegistryEntry> = {
tokenUrl: "https://console.anthropic.com/v1/oauth/token",
},
models: [
{ id: "claude-opus-4-7", name: "Claude Opus 4.7" },
{ id: "claude-opus-4-6", name: "Claude Opus 4.6" },
{ id: "claude-sonnet-4-6", name: "Claude 4.6 Sonnet" },
{ id: "claude-opus-4-5-20251101", name: "Claude 4.5 Opus" },
{ id: "claude-sonnet-4-5-20250929", name: "Claude 4.5 Sonnet" },
{ id: "claude-haiku-4-5-20251001", name: "Claude 4.5 Haiku" },
{ id: "claude-opus-4-7", name: "Claude Opus 4.7", supportsXHighEffort: true },
{ id: "claude-opus-4-6", name: "Claude Opus 4.6", supportsXHighEffort: false },
{ id: "claude-sonnet-4-6", name: "Claude 4.6 Sonnet", supportsXHighEffort: false },
{ id: "claude-opus-4-5-20251101", name: "Claude 4.5 Opus", supportsXHighEffort: false },
{
id: "claude-sonnet-4-5-20250929",
name: "Claude 4.5 Sonnet",
supportsXHighEffort: false,
},
{
id: "claude-haiku-4-5-20251001",
name: "Claude 4.5 Haiku",
supportsXHighEffort: false,
},
],
},

Expand Down
18 changes: 15 additions & 3 deletions open-sse/services/claudeCodeCompatible.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createHash, randomUUID } from "node:crypto";

import { getStainlessTimeoutSeconds } from "@/shared/utils/runtimeTimeouts";
import { getModelsByProviderId } from "../config/providerModels.ts";
import { prepareClaudeRequest } from "../translator/helpers/claudeHelper.ts";
import { signRequestBody } from "./claudeCodeCCH.ts";
import { computeFingerprint, extractFirstUserMessageText } from "./claudeCodeFingerprint.ts";
Expand Down Expand Up @@ -46,6 +47,11 @@ export const CLAUDE_CODE_COMPATIBLE_BILLING_HEADER = `x-anthropic-billing-header
export const CLAUDE_CODE_COMPATIBLE_STAINLESS_TIMEOUT_SECONDS = getStainlessTimeoutSeconds(
process.env
);
const CLAUDE_XHIGH_SUPPORTED_MODELS = new Set(
getModelsByProviderId("claude")
.filter((model) => model.supportsXHighEffort)
.map((model) => model.id)
);

type HeaderLike =
| Headers
Expand All @@ -71,6 +77,10 @@ type BuildRequestOptions = {
preserveCacheControl?: boolean;
};

function supportsClaudeXHighEffort(model: string | null | undefined): boolean {
return typeof model === "string" && CLAUDE_XHIGH_SUPPORTED_MODELS.has(model);
}

export function isClaudeCodeCompatibleProvider(provider: string | null | undefined): boolean {
return typeof provider === "string" && provider.startsWith(CLAUDE_CODE_COMPATIBLE_PREFIX);
}
Expand Down Expand Up @@ -331,7 +341,7 @@ export function resolveClaudeCodeCompatibleEffort(
sourceBody?: Record<string, unknown> | null,
normalizedBody?: Record<string, unknown> | null,
model?: string | null
): "low" | "medium" | "high" {
): "low" | "medium" | "high" | "xhigh" {
const raw =
readNestedString(sourceBody, ["output_config", "effort"]) ||
readNestedString(sourceBody, ["reasoning", "effort"]) ||
Expand All @@ -342,14 +352,16 @@ export function resolveClaudeCodeCompatibleEffort(
"";

const normalizedEffort = raw.toLowerCase();
void model;

if (!normalizedEffort) return "high";
if (normalizedEffort === "low") return "low";
if (normalizedEffort === "medium") return "medium";
if (normalizedEffort === "high") return "high";
if (normalizedEffort === "none" || normalizedEffort === "disabled") return "low";
if (normalizedEffort === "max" || normalizedEffort === "xhigh") {
if (normalizedEffort === "xhigh") {
return supportsClaudeXHighEffort(model) ? "xhigh" : "high";
}
if (normalizedEffort === "max") {
return "high";
}
return "high";
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/cc-compatible-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ test("buildClaudeCodeCompatibleRequest keeps prior role history while dropping t
assert.equal(JSON.parse(payload.metadata.user_id).session_id, "session-1");
});

test("buildClaudeCodeCompatibleRequest preserves xhigh for Claude models that support it", () => {
const payload = buildClaudeCodeCompatibleRequest({
sourceBody: {
reasoning_effort: "xhigh",
},
normalizedBody: {
messages: [{ role: "user", content: "u1" }],
},
model: "claude-opus-4-7",
cwd: "/tmp/work",
now: new Date("2026-04-01T12:00:00.000Z"),
});

assert.equal(payload.output_config.effort, "xhigh");
assert.equal(payload.thinking.type, "adaptive");
});

test("buildClaudeCodeCompatibleRequest preserves Claude cache markers when requested", () => {
const payload = buildClaudeCodeCompatibleRequest({
sourceBody: {
Expand Down
27 changes: 26 additions & 1 deletion tests/unit/claude-code-compatible-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
resolveClaudeCodeCompatibleMaxTokens,
buildClaudeCodeCompatibleRequest,
} = await import("../../open-sse/services/claudeCodeCompatible.ts");
const { getModelsByProviderId } = await import("../../open-sse/config/providerModels.ts");

test("Claude Code compatible URL helpers cover empty values, version trimming and legacy session headers", () => {
assert.equal(stripClaudeCodeCompatibleEndpointSuffix(""), "");
Expand All @@ -33,9 +34,33 @@ test("Claude Code compatible URL helpers cover empty values, version trimming an
});

test("Claude Code compatible effort and max token helpers cover priority fallbacks", () => {
const claudeModels = getModelsByProviderId("claude");
assert.equal(
claudeModels.find((model) => model.id === "claude-opus-4-7")?.supportsXHighEffort,
true
);
assert.equal(
claudeModels.find((model) => model.id === "claude-opus-4-6")?.supportsXHighEffort,
false
);
assert.equal(resolveClaudeCodeCompatibleEffort({ reasoning_effort: "medium" }), "medium");
assert.equal(resolveClaudeCodeCompatibleEffort({ reasoning: { effort: "none" } }), "low");
assert.equal(resolveClaudeCodeCompatibleEffort({ output_config: { effort: "xhigh" } }), "high");
assert.equal(
resolveClaudeCodeCompatibleEffort(
{ output_config: { effort: "xhigh" } },
null,
"claude-opus-4-7"
),
"xhigh"
);
assert.equal(
resolveClaudeCodeCompatibleEffort(
{ output_config: { effort: "xhigh" } },
null,
"claude-opus-4-6"
),
"high"
);
assert.equal(
resolveClaudeCodeCompatibleEffort({ output_config: { effort: "unexpected" } }),
"high"
Expand Down