Skip to content

feat: send custom HTTP headers on Anthropic provider requests - #645

Open
Ueslei Lima (uesleilima) wants to merge 1 commit into
langchain-ai:mainfrom
uesleilima:feat/anthropic-custom-headers
Open

feat: send custom HTTP headers on Anthropic provider requests#645
Ueslei Lima (uesleilima) wants to merge 1 commit into
langchain-ai:mainfrom
uesleilima:feat/anthropic-custom-headers

Conversation

@uesleilima

Copy link
Copy Markdown

What and why

Anthropic-compatible enterprise gateways often require extra HTTP headers (tenant ID, APIM subscription key, anthropic-version) beyond the API key. This PR adds OPENWIKI_PROVIDER_DEFAULT_HEADERS, a JSON object of header names to string values, and sends them on every Anthropic request via clientOptions.defaultHeaders.

When a custom Anthropic baseURL is set, the client also enables streaming and streamUsage so gateway transports that reject non-streaming requests still work.

Header values can contain secrets, so the env var is persisted as a managed key but treated as a secret: diagnostics redact it, and debug dumps report length only (no preview).

How tested

  • Unit tests for resolveProviderDefaultHeaders (empty/invalid JSON, non-string values, invalid header names, successful parse).
  • createModel tests for default headers and streaming-when-custom-base-URL (and that neither is forced against api.anthropic.com).
  • Redaction tests that header JSON never leaks into diagnostic text or debug previews.
  • Env persistence / diagnostics tests that the key is managed and masked.
  • Locally: pnpm run format, pnpm run lint, pnpm test (174 files passed, 2340 tests passed).

Changeset

Minor changeset in .changeset/anthropic-default-headers.md — user-facing feature.

Historical context

This was previously bundled with an Anthropic-on-Azure-Foundry provider in #55. This PR isolates custom Anthropic headers (and the related custom-base-URL streaming tweak) as a single concern per CONTRIBUTING.md. It does not add a Foundry provider or HTTP proxy support.

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9c389a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openwiki Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant