Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions apps/server/src/provider/openrouter/OpenRouterRuntime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,23 @@ describe("OpenRouterRuntime", () => {
expect(env.X_TITLE).toBe("T3 Code");
// Claude Code only forwards headers through ANTHROPIC_CUSTOM_HEADERS.
expect(env.ANTHROPIC_CUSTOM_HEADERS).toBe("HTTP-Referer: https://t3.chat\nX-Title: T3 Code");
// OpenRouter rejects deferred tools for non-Anthropic models.
expect(env.ENABLE_TOOL_SEARCH).toBe("false");
expect(env.OR_SITE_URL).toBeUndefined();
expect(env.OR_APP_NAME).toBeUndefined();
expect(env.PATH).toBe("/usr/bin");
});

it("keeps an explicit host tool-search choice", () => {
const settings = decodeOpenRouterSettings({ apiKey: "sk-or-test" });
const env = buildOpenRouterProcessEnv(settings, { ENABLE_TOOL_SEARCH: "true" });
expect(env.ENABLE_TOOL_SEARCH).toBe("true");

// A blank host value is not a choice, so the OpenRouter default applies.
const blank = buildOpenRouterProcessEnv(settings, { ENABLE_TOOL_SEARCH: " " });
expect(blank.ENABLE_TOOL_SEARCH).toBe("false");
});

it("clears inherited Anthropic credentials when settings apiKey is empty", () => {
const settings = decodeOpenRouterSettings({
apiKey: "",
Expand Down
11 changes: 11 additions & 0 deletions apps/server/src/provider/openrouter/OpenRouterRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ export function buildOpenRouterProcessEnv(
next.ANTHROPIC_CUSTOM_HEADERS = customHeaders.join("\n");
}

// Claude Code defaults to tool search, which omits tools from `tools[]` and
// refers to them with tool_reference blocks. OpenRouter's Anthropic-compatible
// endpoint rejects that for every non-Anthropic model ("Deferred custom tools
// are only supported on Anthropic models"), which kills the turn outright.
// "false" is Claude Code's own off switch (ENABLE_TOOL_SEARCH => "standard"
// mode). An explicit host value still wins, for proxies that do forward
// tool_reference blocks.
if (next.ENABLE_TOOL_SEARCH === undefined || next.ENABLE_TOOL_SEARCH.trim().length === 0) {
next.ENABLE_TOOL_SEARCH = "false";
}

return next;
}

Expand Down
Loading