-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(anthropic): properly handle OAuth tokens (sk-ant-oat*) across all… #19802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| ) | ||
| from litellm.proxy.auth.route_checks import RouteChecks | ||
| from litellm.router import Router | ||
| from litellm.llms.anthropic.common_utils import is_anthropic_oauth_key | ||
| from litellm.types.llms.anthropic import ANTHROPIC_API_HEADERS | ||
| from litellm.types.services import ServiceTypes | ||
| from litellm.types.utils import ( | ||
|
|
@@ -320,6 +321,7 @@ def _get_forwardable_headers( | |
| Looks for any `x-` headers and sends them to the LLM Provider. | ||
|
|
||
| [07/09/2025] - Support 'anthropic-beta' header as well. | ||
| [01/26/2026] - Support 'authorization' header for Anthropic OAuth tokens. | ||
| """ | ||
| forwarded_headers = {} | ||
| for header, value in headers.items(): | ||
|
|
@@ -329,6 +331,9 @@ def _get_forwardable_headers( | |
| forwarded_headers[header] = value | ||
| elif header.lower().startswith("anthropic-beta"): | ||
| forwarded_headers[header] = value | ||
| elif header.lower() == "authorization" and is_anthropic_oauth_key(value): | ||
| # Forward Authorization header for Anthropic OAuth tokens (sk-ant-oat*) | ||
| forwarded_headers[header] = value | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be the wrong place to add the header, if you have multiple providers listed in your router, it will forward the authentication header to all the providers listed in your router. function that should be modified is |
||
|
|
||
| return forwarded_headers | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean_headersfunction should be modified too, when you want to use the router for your anthropic llm calls (non-passthrough) - the code flow goes throughclean_headerswhich should be modified to pass the auth header through