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 <noreply@anthropic.com>
This commit is contained in:
@@ -4,8 +4,12 @@ LLM_ENDPOINT=http://localhost:11434/v1/chat/completions
|
|||||||
# Model name passed to the endpoint
|
# Model name passed to the endpoint
|
||||||
LLM_MODEL=llama3
|
LLM_MODEL=llama3
|
||||||
|
|
||||||
# Optional API key (sent as Bearer token) — leave blank for local servers
|
# Optional API key — value is sent as "Bearer <value>", do NOT include the word "Bearer" here
|
||||||
LLM_API_KEY=
|
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
|
# Default system prompt for the voice AI loop
|
||||||
LLM_SYSTEM_PROMPT=You are Jibo, a friendly social robot. Keep responses brief and conversational.
|
LLM_SYSTEM_PROMPT=You are Jibo, a friendly social robot. Keep responses brief and conversational.
|
||||||
|
|||||||
@@ -922,6 +922,10 @@ app.post('/api/llm/chat', async (req, res) => {
|
|||||||
|
|
||||||
const headers = {};
|
const headers = {};
|
||||||
if (apiKey) headers['Authorization'] = `Bearer ${apiKey}`;
|
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 {
|
try {
|
||||||
const result = await httpPost(url, headers, { model: mdl, messages: allMessages, stream: false });
|
const result = await httpPost(url, headers, { model: mdl, messages: allMessages, stream: false });
|
||||||
|
|||||||
Reference in New Issue
Block a user