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"