Skip to content

Conversation

@mecab
Copy link
Contributor

@mecab mecab commented Apr 12, 2025

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 Authorization header instead of the X-Api-Key header. Currently Roo Code passes the API token in the X-Api-Key header 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 authToken which 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:

  • Added a new configuration option anthropicUseAuthToken to the settings
  • Made this option effective only when a custom base URL (anthropicBaseUrl) is set
  • Modified the Anthropic SDK initialization to use either apiKey or authToken parameters based on the configuration
    • A possible option would be to enable users to set separate apiKey and authToken parameters. 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.
  • Added a new checkbox to the settings UI allowing users to select this option
  • Updated translation files for multiple languages
    • The translations were machine translated from English, so they need to be reviewed
      • (Japanese is my native language, and I think that translation is acceptable)

Screenshots

before after
image image

How to Test

  • I added test cases in the unit test to verify the Anthropic SDK initialization, so you can test it by running npm test
  • I tested it live against the gateway and confirmed it works
    • Since it is a private gateway, I cannot share it. You might be able to test it by writing a proxy to the Anthropic API.

Important

Adds anthropicUseAuthToken option to use Authorization header for Anthropic API token with custom base URL, updating UI, tests, and translations.

  • Behavior:
    • Adds anthropicUseAuthToken option to pass API token as Authorization header when anthropicBaseUrl is set.
    • Updates AnthropicHandler in anthropic.ts to use authToken or apiKey based on configuration.
  • UI:
    • Adds checkbox for anthropicUseAuthToken in ApiOptions.tsx.
  • Tests:
    • Adds test cases in anthropic.test.ts to verify authToken usage.
  • Translations:
    • Updates translation files (settings.json) for multiple languages to include anthropicUseAuthToken option.

This description was created by Ellipsis for ac19a60db07a9b8e2c551e32c28fb28ebeda8b16. It will automatically update as commits are pushed.

@changeset-bot
Copy link

changeset-bot bot commented Apr 12, 2025

⚠️ No Changeset found

Latest commit: 494b98d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Apr 12, 2025
@mecab mecab force-pushed the feature/anthropic-authToken-over-apiKey branch from ac19a60 to 494b98d Compare April 12, 2025 13:56
Copy link
Collaborator

@mrubens mrubens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 13, 2025
@mrubens mrubens merged commit 37cfd75 into RooCodeInc:main Apr 13, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Apr 13, 2025
@mecab
Copy link
Contributor Author

mecab commented Apr 13, 2025

Thanks for merging it!

SmartManoj pushed a commit to SmartManoj/Raa-Code that referenced this pull request May 6, 2025
* Update Changeset Workflow

* Remove RELEASE related content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants