provider headers from config not applied to fetch requests #8329

Closed
opened 2026-02-16 18:09:42 -05:00 by yindo · 2 comments
Owner

Originally created by @cloudyan on GitHub (Feb 2, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

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"],
        };

Plugins

oh-my-opencode

OpenCode version

1.1.48

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

macOS 26.2

Terminal

iTerm2

Originally created by @cloudyan on GitHub (Feb 2, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description 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"], }; ``` ### Plugins oh-my-opencode ### OpenCode version 1.1.48 ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System macOS 26.2 ### Terminal iTerm2
yindo added the bug label 2026-02-16 18:09:42 -05:00
yindo closed this issue 2026-02-16 18:09:42 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 2, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #11287: Support Model-Level Configuration override Provider-Level (includes discussion of configuration hierarchy for baseURL, apiKey, and other options)
  • #11466: Mistral Provider support for x-affinity header (related to custom header configuration for providers)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Feb 2, 2026): This issue might be a duplicate of existing issues. Please check: - #11287: Support Model-Level Configuration override Provider-Level (includes discussion of configuration hierarchy for baseURL, apiKey, and other options) - #11466: Mistral Provider support for x-affinity header (related to custom header configuration for providers) Feel free to ignore if none of these address your specific case.
Author
Owner

@lailoo commented on GitHub (Feb 3, 2026):

I addressed this issue in PR #11978

If you have some time, I'd really appreciate it if you could take a look.


Solution: Merged options["headers"] into opts.headers in the custom fetch function, exactly as you suggested in the issue description.

@lailoo commented on GitHub (Feb 3, 2026): I addressed this issue in PR #11978 If you have some time, I'd really appreciate it if you could take a look. --- **Solution:** Merged `options["headers"]` into `opts.headers` in the custom fetch function, exactly as you suggested in the issue description.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8329