Skip to content

Conversation

@cloudyan
Copy link
Contributor

@cloudyan cloudyan commented Feb 2, 2026

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

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"],
        };
```
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@rekram1-node rekram1-node merged commit 39a5047 into anomalyco:dev Feb 3, 2026
7 checks passed
@rekram1-node
Copy link
Collaborator

this caused breaking changes, reverted.

ishaksebsib pushed a commit to ishaksebsib/opencode that referenced this pull request Feb 4, 2026
ishaksebsib pushed a commit to ishaksebsib/opencode that referenced this pull request Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

provider headers from config not applied to fetch requests

2 participants