Skip to content

prepareOptions() drops model.request.headers — custom headers from provider config never reach SDK factory #36619

Closed as not planned

Description

@jeffyuan

Describe the bug

When configuring a provider with custom headers (e.g. User-Agent or x-api-key for third-party compatible APIs), those headers are correctly extracted by the lowerer into model.request.headers, but prepareOptions() in aisdk.ts never merges them into the options object passed to the SDK factory (createAnthropic() etc.). The headers are silently dropped.

To reproduce

Configure any V1 provider with headers in options, for example a third-party API that requires User-Agent: opencode/1.0:

{
  "provider": {
    "my-provider": {
      "npm": "@ai-sdk/anthropic",
      "options": {
        "apiKey": "...",
        "baseURL": "...",
        "headers": {
          "User-Agent": "opencode/1.0"
        }
      }
    }
  }
}

Observe that the header never appears in the actual HTTP request — the lowerer places it in request.headers, but prepareOptions() ignores request.headers.

Expected behavior

model.request.headers should be merged into the SDK options, matching how settings and body are already handled.

Additional context

The data flow:

  1. Config provider options → lowerer correctly extracts headers into provider.request.headers
  2. projectModel() in catalog.ts correctly merges provider-level and model-level headers into model.request.headers
  3. prepareOptions() ignores model.request.headers — headers are lost

Fix is a 3-line addition in packages/core/src/aisdk.ts to merge model.request.headers into the options object.

Activity

  1. github-actions commented on Jul 13, 2026

    @github-actions
    Contributor

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

    Both describe headers configured under provider.<name>.options.headers not making it into outgoing HTTP requests. If those fixes didn't fully address the model.request.headers path in prepareOptions(), this may be a regression or a gap left by those fixes.

  2. github-actions commented on Sep 12, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions