From d64ab076f2ccf37aee99a6b43d5d52b36f9324c3 Mon Sep 17 00:00:00 2001 From: Cloudyan Date: Mon, 2 Feb 2026 21:33:04 +0800 Subject: [PATCH] fix: provider headers from config not applied to fetch requests When configuring custom headers (including User-Agent) for a provider or model in opencode.jsonc, the headers are not actually sent with the API requests. For example, this configuration does not work: ```json { "provider": { "myprovider": { "models": { "my-model": { "headers": { "User-Agent": "MyCustomAgent/1.0" } } } } } } ``` In packages/opencode/src/provider/provider.ts, the getSDK function correctly merges model.headers into options["headers"]: ```ts if (model.headers) options["headers"] = { ...options["headers"], ...model.headers, } ``` However, in the custom fetch function, opts.headers comes from the init parameter passed by the AI SDK, not from options["headers"]. This means the configured headers are never actually included in the request. Solution Update the custom fetch function to merge options["headers"] into opts.headers: ```ts opts.headers = { ...(typeof opts.headers === 'object' ? opts.headers : {}), ...options["headers"], }; ``` --- packages/opencode/src/provider/provider.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index e01c583ff348..57a58ba8cf22 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -992,6 +992,12 @@ export namespace Provider { const fetchFn = customFetch ?? fetch const opts = init ?? {} + // Merge configured headers into request headers + opts.headers = { + ...(typeof opts.headers === 'object' ? opts.headers : {}), + ...options["headers"], + } + if (options["timeout"] !== undefined && options["timeout"] !== null) { const signals: AbortSignal[] = [] if (opts.signal) signals.push(opts.signal)