From 70bc44eb11a28ec3e338d9ef45d33d9beaac6873 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Sat, 20 Dec 2025 23:43:52 -0500 Subject: [PATCH] fix(openrouter): add ANTHROPIC_API_KEY="" default for OpenRouter profiles Per OpenRouter requirements, explicitly blank out the Anthropic API key to prevent conflicts when using OpenRouter's API. The key is visible in the "Additional Variables" section of the profile editor. --- src/api/services/profile-writer.ts | 9 +++++++++ .../components/profiles/editor/friendly-ui-section.tsx | 1 + 2 files changed, 10 insertions(+) diff --git a/src/api/services/profile-writer.ts b/src/api/services/profile-writer.ts index 748c1fb4..e48ff6fa 100644 --- a/src/api/services/profile-writer.ts +++ b/src/api/services/profile-writer.ts @@ -13,6 +13,11 @@ import { } from '../../config/unified-config-loader'; import type { ModelMapping, CreateApiProfileResult, RemoveApiProfileResult } from './profile-types'; +/** Check if URL is an OpenRouter endpoint */ +function isOpenRouterUrl(baseUrl: string): boolean { + return baseUrl.toLowerCase().includes('openrouter.ai'); +} + /** Create settings.json file for API profile (legacy format) */ function createSettingsFile( name: string, @@ -31,6 +36,8 @@ function createSettingsFile( ANTHROPIC_DEFAULT_OPUS_MODEL: models.opus, ANTHROPIC_DEFAULT_SONNET_MODEL: models.sonnet, ANTHROPIC_DEFAULT_HAIKU_MODEL: models.haiku, + // OpenRouter requires explicitly blanking the API key to prevent conflicts + ...(isOpenRouterUrl(baseUrl) && { ANTHROPIC_API_KEY: '' }), }, }; @@ -82,6 +89,8 @@ function createApiProfileUnified( ANTHROPIC_DEFAULT_OPUS_MODEL: models.opus, ANTHROPIC_DEFAULT_SONNET_MODEL: models.sonnet, ANTHROPIC_DEFAULT_HAIKU_MODEL: models.haiku, + // OpenRouter requires explicitly blanking the API key to prevent conflicts + ...(isOpenRouterUrl(baseUrl) && { ANTHROPIC_API_KEY: '' }), }, }; diff --git a/ui/src/components/profiles/editor/friendly-ui-section.tsx b/ui/src/components/profiles/editor/friendly-ui-section.tsx index e45ebe59..00312d0b 100644 --- a/ui/src/components/profiles/editor/friendly-ui-section.tsx +++ b/ui/src/components/profiles/editor/friendly-ui-section.tsx @@ -111,6 +111,7 @@ export function FriendlyUISection({ 'ANTHROPIC_DEFAULT_SONNET_MODEL', 'ANTHROPIC_DEFAULT_HAIKU_MODEL', 'ANTHROPIC_AUTH_TOKEN', // Managed by API Key section + 'ANTHROPIC_BASE_URL', // Base URL shown in profile header ]); // Get non-managed env vars for display in "Additional Variables"