feat: add support for ANTHROPIC_CUSTOM_HEADERS environment variable #48
+285
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds support for the
ANTHROPIC_CUSTOM_HEADERSenvironment variable, allowing users to inject custom HTTP headers into all Anthropic API requests.Changes
CustomHeadersfield toAnthropicConfigparseCustomHeaders()to parse the environment variableName: Valuewith multiple headers separated by newlinesnewAnthropicClient()to inject headers usingoption.WithHeader()TestParseCustomHeaders: 12 test cases for parsing logicTestCustomHeadersIntegration: 3 test cases for API integrationUsage Example
Testing
✅ All tests pass (1.486s)
✅ Race detection passes (2.463s)
✅ No linting issues introduced
✅ Code formatted with gofumpt
Files Modified
config.go- Added CustomHeaders fieldprovider_anthropic.go- Header parsing and initializationintercept_anthropic_messages_base.go- Header injectionanthropic_internal_test.go- Comprehensive testsbridge_integration_test.go- Test helper fixesTotal: 285 lines added across 5 files