Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

feat(anthropic): add custom headers support for API gateways - #11078

Open
ghost wants to merge 2 commits into
mainfrom
feature/anthropic-custom-headers
Open

feat(anthropic): add custom headers support for API gateways#11078
ghost wants to merge 2 commits into
mainfrom
feature/anthropic-custom-headers

Conversation

@ghost

@ghost ghost commented Jan 29, 2026

Copy link
Copy Markdown

This PR attempts to address Issue #10939.

Summary

Adds support for custom HTTP headers in the Anthropic provider, enabling users to pass headers required by API gateways like Portkey. This mirrors the existing openAiHeaders pattern used by the OpenAI provider.

Changes

  1. Schema update (packages/types/src/provider-settings.ts):

    • Added anthropicHeaders: z.record(z.string(), z.string()).optional() to the anthropicSchema
  2. Handler update (src/api/providers/anthropic.ts):

    • Pass custom headers via the defaultHeaders option when initializing the Anthropic SDK client
  3. UI update (webview-ui/src/components/settings/providers/Anthropic.tsx):

    • Added custom headers UI matching the OpenAI pattern
    • Users can add, edit, and remove custom header key-value pairs
  4. Tests (src/api/providers/__tests__/anthropic.spec.ts):

    • Added tests to verify custom headers are passed to the SDK

UI Preview

The custom headers UI allows users to:

  • Add new headers using the + button
  • Enter header name and value in text fields
  • Remove headers using the trash icon
  • Headers are persisted in provider settings

Testing

  • All existing tests pass
  • TypeScript compilation succeeds
  • Lint checks pass

Feedback and guidance are welcome!


Important

Adds support for custom HTTP headers in the Anthropic provider, including schema, handler, UI, and test updates.

  • Behavior:
    • Adds anthropicHeaders to anthropicSchema in provider-settings.ts for custom HTTP headers.
    • Passes custom headers via defaultHeaders in AnthropicHandler constructor in anthropic.ts.
  • UI:
    • Adds UI for custom headers in Anthropic.tsx, allowing users to add, edit, and remove headers.
  • Tests:
    • Adds tests in anthropic.spec.ts to verify custom headers are passed correctly.
  • Misc:
    • Adds StandardTooltip for custom headers UI in ApiOptions.provider-filtering.spec.tsx.

This description was created by Ellipsis for b16fae9. You can customize this summary. It will automatically update as commits are pushed.

This change adds support for custom HTTP headers in the Anthropic provider,
enabling users to pass headers required by API gateways like Portkey.

Changes:
- Add anthropicHeaders field to provider settings schema
- Pass defaultHeaders to Anthropic SDK client constructor
- Add custom headers UI in Anthropic settings (matching OpenAI pattern)
- Add tests for custom headers functionality

Closes #10939
@ghost

ghost commented Jan 29, 2026

Copy link
Copy Markdown
Author

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation is clean and consistent with existing patterns:

  • Schema update correctly adds anthropicHeaders field
  • Handler properly passes headers via SDK's defaultHeaders option
  • UI mirrors the OpenAI compatible provider pattern
  • Tests adequately cover the new functionality
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@yunhailuo

Copy link
Copy Markdown

@roomote you seem to have failed checks. It seems to me related to ui. I wonder if you can learn from openai provide about how to configure the ui for custom header and update the code (then update tests if needed) to fix the failure?

@ghost

ghost commented Jan 29, 2026

Copy link
Copy Markdown
Author

Fixaroo Clock   See task on Roo Cloud

Fixed the reported issues. All local checks passed.

View commit | Revert commit

@yunhailuo

Copy link
Copy Markdown

I tested this pr just now and it solved the problem in my specific use case in #10939. Thank you. What's next or how should we proceed here? @roomote

@ghost

ghost commented Jan 29, 2026

Copy link
Copy Markdown
Author

Planneroo Clock   See task on Roo Cloud

Thank you for testing and confirming this works for your use case! The review found no issues with the implementation.

I have marked this PR as ready for review. The next step is for a maintainer to review and approve the changes, after which it can be merged.

@ghost
ghost marked this pull request as ready for review January 29, 2026 16:53
@ghost
ghost requested review from cte, jr and mrubens as code owners January 29, 2026 16:53
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. Enhancement New feature or request labels Jan 29, 2026
@ghost

ghost commented Jan 29, 2026

Copy link
Copy Markdown
Author

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly adds custom headers support for the Anthropic provider:

  • Schema properly extends anthropicSchema with anthropicHeaders field
  • Handler passes headers via SDK's defaultHeaders option
  • UI follows the established OpenAICompatible pattern with debounced state sync
  • Tests adequately cover the new functionality

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@yunhailuo

Copy link
Copy Markdown

@mrubens want to kindly ask if this PR is good to merge or there are concerns?

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

Labels

Enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

No open projects
Status: Triage

Development

Successfully merging this pull request may close these issues.

2 participants