Add Anthropic option to pass API Token as Authorization header instead of X-Api-Key for the custom base URL #2531
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.
Context
Add an option for Anthropic to pass the API Token as an Authorization header instead of using the X-Api-Key header when the user is using a custom base URL.
Background
I am using the Anthropic API through a certain gateway server and it requires my API token to be passed in the
Authorizationheader instead of theX-Api-Keyheader. Currently Roo Code passes the API token in theX-Api-Keyheader even when the user is using a custom base URL, so I had to make this change to use Roo Code with that gateway.It may look like an edgy use case, but the Anthropic SDK supports initialization by the
authTokenwhich can be used to pass the API token in the Authorization header. This suggests it's an expected scenario, and I believe adding this option to Roo Code would be a good solution that may be useful for other users too.Implementation
I implemented the following changes:
anthropicUseAuthTokento the settingsanthropicBaseUrl) is setapiKeyorauthTokenparameters based on the configurationapiKeyandauthTokenparameters. However, I decided to keep it simple by using a single token and configuring how it is passed -- I am not sure if there would be a scenario where users would need to set both parameters.Screenshots
How to Test
npm testImportant
Adds
anthropicUseAuthTokenoption to use Authorization header for Anthropic API token with custom base URL, updating UI, tests, and translations.anthropicUseAuthTokenoption to pass API token asAuthorizationheader whenanthropicBaseUrlis set.AnthropicHandlerinanthropic.tsto useauthTokenorapiKeybased on configuration.anthropicUseAuthTokeninApiOptions.tsx.anthropic.test.tsto verifyauthTokenusage.settings.json) for multiple languages to includeanthropicUseAuthTokenoption.This description was created by
for ac19a60db07a9b8e2c551e32c28fb28ebeda8b16. It will automatically update as commits are pushed.