From 07ef1a2fade05e81078f539ef349b272e0f94ae9 Mon Sep 17 00:00:00 2001 From: pasketti Date: Sun, 19 Apr 2026 14:54:59 -0400 Subject: [PATCH] Add LLM_HEADERS support for custom request headers Reads LLM_HEADERS as a JSON object from .env and merges it into every LLM request alongside the existing Authorization header. Useful for endpoints that require non-standard headers (e.g. x-openclaw-agent-id). LLM_API_KEY continues to be sent without the "Bearer" prefix in .env. Co-Authored-By: Claude Sonnet 4.6 --- .env.example | 6 +++++- server.js | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 32a1397..2383eb3 100644 --- a/.env.example +++ b/.env.example @@ -4,8 +4,12 @@ LLM_ENDPOINT=http://localhost:11434/v1/chat/completions # Model name passed to the endpoint LLM_MODEL=llama3 -# Optional API key (sent as Bearer token) — leave blank for local servers +# Optional API key — value is sent as "Bearer ", do NOT include the word "Bearer" here LLM_API_KEY= +# Optional extra headers sent with every LLM request, as a JSON object +# Example: LLM_HEADERS={"x-openclaw-agent-id":"jibo"} +LLM_HEADERS= + # Default system prompt for the voice AI loop LLM_SYSTEM_PROMPT=You are Jibo, a friendly social robot. Keep responses brief and conversational. diff --git a/server.js b/server.js index b6236cd..a7ceb27 100644 --- a/server.js +++ b/server.js @@ -922,6 +922,10 @@ app.post('/api/llm/chat', async (req, res) => { const headers = {}; if (apiKey) headers['Authorization'] = `Bearer ${apiKey}`; + try { + const extra = process.env.LLM_HEADERS ? JSON.parse(process.env.LLM_HEADERS) : {}; + Object.assign(headers, extra); + } catch { console.warn('[llm] LLM_HEADERS is not valid JSON — ignored'); } try { const result = await httpPost(url, headers, { model: mdl, messages: allMessages, stream: false });