[PR #11788] fix: provider headers from config not applied to fetch requests #13931

Closed
opened 2026-02-16 18:18:45 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11788

State: closed
Merged: Yes


Fixed #11789

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:

    {
      "provider": {
        "myprovider": {
           "options": {
              "apiKey": "sk-xxx",
              "baseURL": "https://apis.iflow.cn/v1",
              "headers": {
                 "user-agent": "MyCustomAgent/1.0" // custom user-agent
              }
           },
          "models": {
            "my-model": {
              "headers": {
                "User-Agent": "MyCustomAgent/2.0" //  custom user-agent (higher priority)
              }
            }
          }
        }
      }
    }

In packages/opencode/src/provider/provider.ts, the getSDK function correctly merges model.headers into options["headers"]:

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:

        opts.headers = {
          ...(typeof opts.headers === 'object' ? opts.headers : {}),
          ...options["headers"],
        };
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11788 **State:** closed **Merged:** Yes --- Fixed #11789 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": { "options": { "apiKey": "sk-xxx", "baseURL": "https://apis.iflow.cn/v1", "headers": { "user-agent": "MyCustomAgent/1.0" // custom user-agent } }, "models": { "my-model": { "headers": { "User-Agent": "MyCustomAgent/2.0" // custom user-agent (higher priority) } } } } } } ``` 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"], }; ```
yindo added the pull-request label 2026-02-16 18:18:45 -05:00
yindo closed this issue 2026-02-16 18:18:45 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13931