Skip to content

provider headers from config not applied to fetch requests #11789

Closed

Description

@cloudyan

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

Activity

  1. github-actions commented on Feb 2, 2026

    @github-actions
    Contributor

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

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

  2. added a commit that references this issue on Feb 3, 2026
    c10b269
  3. lailoo commented on Feb 3, 2026

    @lailoo
    Contributor

    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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions