From 3e2118022ef18f95bf1e5ac30f1fd7195d161b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3n=20Levy?= Date: Sun, 17 Aug 2025 12:51:47 +0000 Subject: [PATCH 1/4] feat: add COHERE_BASE_URL configuration support for custom Cohere rerank endpoints - Add cohereBaseUrl to webSearchSchema configuration - Update loadWebSearchConfig to load cohereBaseUrl from environment - Add cohereBaseUrl to TWebSearchKeys type definition - Configure cohereBaseUrl as optional parameter for cohere reranker - Add COHERE_BASE_URL documentation to .env.example This enables configuration of custom Cohere endpoints (such as LiteLLM proxy) for web search reranking. The configuration infrastructure is ready for when the @librechat/agents package supports custom base URLs. Usage: COHERE_BASE_URL=http://litellm:8000/v1 COHERE_API_KEY=your_api_key --- .env.example | 1 + packages/api/src/web/web.ts | 11 +++++++++-- packages/data-provider/src/config.ts | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index d0435c746..5e9649853 100644 --- a/.env.example +++ b/.env.example @@ -698,3 +698,4 @@ OPENWEATHER_API_KEY= # JINA_API_KEY=your_jina_api_key # or # COHERE_API_KEY=your_cohere_api_key +# COHERE_BASE_URL=your_custom_cohere_base_url diff --git a/packages/api/src/web/web.ts b/packages/api/src/web/web.ts index 6e57226a1..6e3375418 100644 --- a/packages/api/src/web/web.ts +++ b/packages/api/src/web/web.ts @@ -22,6 +22,7 @@ export function loadWebSearchConfig( const firecrawlApiUrl = config?.firecrawlApiUrl ?? '${FIRECRAWL_API_URL}'; const jinaApiKey = config?.jinaApiKey ?? '${JINA_API_KEY}'; const cohereApiKey = config?.cohereApiKey ?? '${COHERE_API_KEY}'; + const cohereBaseUrl = config?.cohereBaseUrl ?? '${COHERE_BASE_URL}'; const safeSearch = config?.safeSearch ?? SafeSearchTypes.MODERATE; return { @@ -29,6 +30,7 @@ export function loadWebSearchConfig( safeSearch, jinaApiKey, cohereApiKey, + cohereBaseUrl, serperApiKey, searxngInstanceUrl, searxngApiKey, @@ -44,7 +46,8 @@ export type TWebSearchKeys = | 'firecrawlApiKey' | 'firecrawlApiUrl' | 'jinaApiKey' - | 'cohereApiKey'; + | 'cohereApiKey' + | 'cohereBaseUrl'; export type TWebSearchCategories = | SearchCategories.PROVIDERS @@ -71,7 +74,11 @@ export const webSearchAuth = { }, rerankers: { jina: { jinaApiKey: 1 as const }, - cohere: { cohereApiKey: 1 as const }, + cohere: { + cohereApiKey: 1 as const, + /** Optional (0) */ + cohereBaseUrl: 0 as const, + }, }, }; diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts index 83c193df2..16e039135 100644 --- a/packages/data-provider/src/config.ts +++ b/packages/data-provider/src/config.ts @@ -662,6 +662,7 @@ export const webSearchSchema = z.object({ firecrawlApiUrl: z.string().optional().default('${FIRECRAWL_API_URL}'), jinaApiKey: z.string().optional().default('${JINA_API_KEY}'), cohereApiKey: z.string().optional().default('${COHERE_API_KEY}'), + cohereBaseUrl: z.string().optional().default('${COHERE_BASE_URL}'), searchProvider: z.nativeEnum(SearchProviders).optional(), scraperType: z.nativeEnum(ScraperTypes).optional(), rerankerType: z.nativeEnum(RerankerTypes).optional(), From fc8d1384f1455d38d38446d90b1367224c92603e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3n=20Levy?= Date: Sun, 17 Aug 2025 13:08:40 +0000 Subject: [PATCH 2/4] feat: simple COHERE_BASE_URL support using environment variable Replace enum with dynamic getter to enable runtime environment variable lookup. CohereConstants.API_URL now automatically uses COHERE_BASE_URL if set, otherwise defaults to https://api.cohere.ai/v1. This enables using custom Cohere endpoints (like LiteLLM proxy) for web search reranking by simply setting the COHERE_BASE_URL environment variable. Usage: export COHERE_BASE_URL=http://litellm:8000/v1 export COHERE_API_KEY=your_api_key The change is backwards compatible and requires no configuration changes. --- .env.example | 3 ++- packages/api/src/web/web.ts | 11 ++--------- packages/data-provider/src/config.ts | 20 +++++++++++--------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/.env.example b/.env.example index 5e9649853..c74f93f4d 100644 --- a/.env.example +++ b/.env.example @@ -698,4 +698,5 @@ OPENWEATHER_API_KEY= # JINA_API_KEY=your_jina_api_key # or # COHERE_API_KEY=your_cohere_api_key -# COHERE_BASE_URL=your_custom_cohere_base_url +# Optional: Custom Cohere API base URL (defaults to https://api.cohere.ai/v1) +# COHERE_BASE_URL=http://litellm:8000/v1 diff --git a/packages/api/src/web/web.ts b/packages/api/src/web/web.ts index 6e3375418..6e57226a1 100644 --- a/packages/api/src/web/web.ts +++ b/packages/api/src/web/web.ts @@ -22,7 +22,6 @@ export function loadWebSearchConfig( const firecrawlApiUrl = config?.firecrawlApiUrl ?? '${FIRECRAWL_API_URL}'; const jinaApiKey = config?.jinaApiKey ?? '${JINA_API_KEY}'; const cohereApiKey = config?.cohereApiKey ?? '${COHERE_API_KEY}'; - const cohereBaseUrl = config?.cohereBaseUrl ?? '${COHERE_BASE_URL}'; const safeSearch = config?.safeSearch ?? SafeSearchTypes.MODERATE; return { @@ -30,7 +29,6 @@ export function loadWebSearchConfig( safeSearch, jinaApiKey, cohereApiKey, - cohereBaseUrl, serperApiKey, searxngInstanceUrl, searxngApiKey, @@ -46,8 +44,7 @@ export type TWebSearchKeys = | 'firecrawlApiKey' | 'firecrawlApiUrl' | 'jinaApiKey' - | 'cohereApiKey' - | 'cohereBaseUrl'; + | 'cohereApiKey'; export type TWebSearchCategories = | SearchCategories.PROVIDERS @@ -74,11 +71,7 @@ export const webSearchAuth = { }, rerankers: { jina: { jinaApiKey: 1 as const }, - cohere: { - cohereApiKey: 1 as const, - /** Optional (0) */ - cohereBaseUrl: 0 as const, - }, + cohere: { cohereApiKey: 1 as const }, }, }; diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts index 16e039135..c06939ea1 100644 --- a/packages/data-provider/src/config.ts +++ b/packages/data-provider/src/config.ts @@ -662,7 +662,6 @@ export const webSearchSchema = z.object({ firecrawlApiUrl: z.string().optional().default('${FIRECRAWL_API_URL}'), jinaApiKey: z.string().optional().default('${JINA_API_KEY}'), cohereApiKey: z.string().optional().default('${COHERE_API_KEY}'), - cohereBaseUrl: z.string().optional().default('${COHERE_BASE_URL}'), searchProvider: z.nativeEnum(SearchProviders).optional(), scraperType: z.nativeEnum(ScraperTypes).optional(), rerankerType: z.nativeEnum(RerankerTypes).optional(), @@ -1584,30 +1583,33 @@ export enum ForkOptions { } /** - * Enum for Cohere related constants + * Cohere related constants */ -export enum CohereConstants { +export const CohereConstants = { /** * Cohere API Endpoint, for special handling + * Uses COHERE_BASE_URL environment variable if set, otherwise defaults to official API */ - API_URL = 'https://api.cohere.ai/v1', + get API_URL(): string { + return process.env.COHERE_BASE_URL || 'https://api.cohere.ai/v1'; + }, /** * Role for "USER" messages */ - ROLE_USER = 'USER', + ROLE_USER: 'USER' as const, /** * Role for "SYSTEM" messages */ - ROLE_SYSTEM = 'SYSTEM', + ROLE_SYSTEM: 'SYSTEM' as const, /** * Role for "CHATBOT" messages */ - ROLE_CHATBOT = 'CHATBOT', + ROLE_CHATBOT: 'CHATBOT' as const, /** * Title message as required by Cohere */ - TITLE_MESSAGE = 'TITLE:', -} + TITLE_MESSAGE: 'TITLE:' as const, +} as const; export enum SystemCategories { ALL = 'sys__all__sys', From 67e0d587063ec36da629bf9a6bc3e42fcb52baa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3n=20Levy?= Date: Tue, 19 Aug 2025 10:22:23 +0000 Subject: [PATCH 3/4] fix: COHERE_API_URL --- .env.example | 4 ++-- packages/data-provider/src/config.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index c74f93f4d..cdbeeaaf5 100644 --- a/.env.example +++ b/.env.example @@ -698,5 +698,5 @@ OPENWEATHER_API_KEY= # JINA_API_KEY=your_jina_api_key # or # COHERE_API_KEY=your_cohere_api_key -# Optional: Custom Cohere API base URL (defaults to https://api.cohere.ai/v1) -# COHERE_BASE_URL=http://litellm:8000/v1 +# Optional: Custom Cohere API URL (defaults to https://api.cohere.ai/v1) +# COHERE_API_URL=http://litellm:8000/v1 diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts index c06939ea1..c9841e06f 100644 --- a/packages/data-provider/src/config.ts +++ b/packages/data-provider/src/config.ts @@ -1588,10 +1588,10 @@ export enum ForkOptions { export const CohereConstants = { /** * Cohere API Endpoint, for special handling - * Uses COHERE_BASE_URL environment variable if set, otherwise defaults to official API + * Uses COHERE_API_URL environment variable if set, otherwise defaults to official API */ get API_URL(): string { - return process.env.COHERE_BASE_URL || 'https://api.cohere.ai/v1'; + return process.env.COHERE_API_URL || 'https://api.cohere.ai/v1'; }, /** * Role for "USER" messages From 31ef89d38f9ae2f9b15bc27e297db8e83d1b6447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3n=20Levy?= Date: Wed, 10 Sep 2025 13:12:49 +0000 Subject: [PATCH 4/4] fix: simplified override --- packages/data-provider/src/config.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts index c9841e06f..57ae14f1a 100644 --- a/packages/data-provider/src/config.ts +++ b/packages/data-provider/src/config.ts @@ -1590,9 +1590,7 @@ export const CohereConstants = { * Cohere API Endpoint, for special handling * Uses COHERE_API_URL environment variable if set, otherwise defaults to official API */ - get API_URL(): string { - return process.env.COHERE_API_URL || 'https://api.cohere.ai/v1'; - }, + API_URL: process.env.COHERE_API_URL || 'https://api.cohere.ai/v1', /** * Role for "USER" messages */