diff --git a/backend/open_webui/routers/openai.py b/backend/open_webui/routers/openai.py index e8865b90a0..8c5e3da736 100644 --- a/backend/open_webui/routers/openai.py +++ b/backend/open_webui/routers/openai.py @@ -190,6 +190,9 @@ async def get_headers_and_cookies( if token: headers["Authorization"] = f"Bearer {token}" + if config.get("headers") and isinstance(config.get("headers"), dict): + headers = {**headers, **config.get("headers")} + return headers, cookies diff --git a/src/lib/components/AddConnectionModal.svelte b/src/lib/components/AddConnectionModal.svelte index 240df839a8..784b3c0453 100644 --- a/src/lib/components/AddConnectionModal.svelte +++ b/src/lib/components/AddConnectionModal.svelte @@ -17,6 +17,7 @@ import Tags from './common/Tags.svelte'; import Spinner from '$lib/components/common/Spinner.svelte'; import XMark from '$lib/components/icons/XMark.svelte'; + import Textarea from './common/Textarea.svelte'; export let onSubmit: Function = () => {}; export let onDelete: Function = () => {}; @@ -42,6 +43,8 @@ let enable = true; let apiVersion = ''; + let headers = ''; + let tags = []; let modelId = ''; @@ -69,6 +72,19 @@ // remove trailing slash from url url = url.replace(/\/$/, ''); + if (headers) { + try { + const _headers = JSON.parse(headers); + if (typeof _headers !== 'object' || Array.isArray(_headers)) { + throw new Error('Headers must be a valid JSON object'); + } + headers = JSON.stringify(_headers, null, 2); + } catch (error) { + toast.error($i18n.t('Headers must be a valid JSON object')); + return; + } + } + const res = await verifyOpenAIConnection( localStorage.token, { @@ -77,7 +93,8 @@ config: { auth_type, azure: azure, - api_version: apiVersion + api_version: apiVersion, + headers: JSON.parse(headers) } }, direct @@ -136,6 +153,19 @@ } } + if (headers) { + try { + const _headers = JSON.parse(headers); + if (typeof _headers !== 'object' || Array.isArray(_headers)) { + throw new Error('Headers must be a valid JSON object'); + } + headers = JSON.stringify(_headers, null, 2); + } catch (error) { + toast.error($i18n.t('Headers must be a valid JSON object')); + return; + } + } + // remove trailing slash from url url = url.replace(/\/$/, ''); @@ -149,6 +179,7 @@ model_ids: modelIds, connection_type: connectionType, auth_type, + headers: headers ? JSON.parse(headers) : undefined, ...(!ollama && azure ? { azure: true, api_version: apiVersion } : {}) } }; @@ -172,6 +203,9 @@ key = connection.key; auth_type = connection.config.auth_type ?? 'bearer'; + headers = connection.config?.headers + ? JSON.stringify(connection.config.headers, null, 2) + : ''; enable = connection.config?.enable ?? true; tags = connection.config?.tags ?? []; @@ -376,6 +410,35 @@ + {#if !ollama && !direct} +
+
+ + +
+ +