#630·evolver

feat: 支持 LLM 运行程序中的自定义头 (EVOLVER_LLM_HEADERS)

作者: chliuqi创建于 2026年9月17日更新于 2026年9月17日

Problem The built-in LLM runner (llmRunner.js) hardcodes HTTP headers in the complete() function: + "" + + "" + + "JavaScript headers: { 'content-type': 'application/json', authorization: \Bearer \ }, + "" + + "" + + "" + Some OpenAI-compatible API providers require additional headers for routing/authentication. For example, OpenCode Go requires + "" + x-opencode-session + "" + for request routing: + "" + + "" + + "json { "error": { "type": "MissingSessionID", "message": "Request is missing x-opencode-session and cannot be routed efficiently." } } + "" + + "" + + "" + Without this header, the API returns 400 Bad Request. ## Proposed Solution Add support for custom headers via environment variable + "" + EVOLVER_LLM_HEADERS + "" + : Simple format (single header): + "" + + "" + + "ash export EVOLVER_LLM_HEADERS='x-opencode-session:evolver-autoexec-12345' + "" + + "" + + "" + JSON format (multiple headers): + "" + + "" + + "ash export EVOLVER_LLM_HEADERS='{"x-opencode-session":"evolver-12345","user-agent":"my-agent/1.0"}' + "" + + "" + + "" + ## Implementation Proposal Parse + "" + EVOLVER_LLM_HEADERS + "" + in + "" + readLlmRunnerConfig() + "" + and merge it into the request headers: + "" + + "" + + "JavaScript // readLlmRunnerConfig const rawHeaders = env['EVOLVER_LLM_HEADERS'] ?? ''; const extraHeaders = rawHeaders.startsWith('{') ? JSON.parse(rawHeaders) : Object.fromEntries(rawHeaders.split(',').map(h => h.split(':').map(s => s.trim()))); return { apiKey, baseUrl, model, maxTurns, maxFileBytes, extraHeaders }; // complete() const response = await fetch(/chat/completions, { method: 'POST', headers: { 'content-type': 'application/json', authorization: \Bearer \, ...config.extraHeaders, }, body: JSON.stringify({ model: config.model, messages, tools: TOOLS, tool_choice: 'auto' }), signal, }); + "" + + "" + + "" + ## Temporary Solution Currently, we use a local proxy to add the required request headers and then forward them to the upstream API. While this is feasible, it adds an extra process and network hop.