feat: add Anthropic OAuth pre-call hook to litellm#51
Merged
Conversation
Switch Anthropic models from API key auth to OAuth auth using custom pre-call hook. This provides more flexible header injection and replaces the previous extra_headers approach. Changes: - Add hooks.py with async_pre_call_hook for OAuth injection - Update deployment.yaml: * Use litellm:main-v1.81.14-nightly (supports custom hooks) * Add OAUTH_TOKEN environment variable * Mount hooks.py as ConfigMap volume - Update configmap.yaml: * Remove extra_headers from Anthropic models * Add custom_llm_provider and async_pre_call_hook * Add new litellm-hooks ConfigMap with hooks.py Requires ANTHROPIC_OAUTH_TOKEN secret in litellm-env namespace.
There was a problem hiding this comment.
3 issues found across 2 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="infra/manifests/litellm/configmap.yaml">
<violation number="1" location="infra/manifests/litellm/configmap.yaml:123">
P1: Missing `:free` suffix on model path. All other free-tier OpenRouter models use `:free` but this one doesn't, which will route requests to the paid version and incur costs.</violation>
<violation number="2" location="infra/manifests/litellm/configmap.yaml:208">
P0: Bug: `OAUTH_TOKEN` is referenced as a bare Python variable but it's an environment variable. This will raise `NameError` at runtime. You need to read it from `os.environ`.</violation>
</file>
<file name="infra/manifests/litellm/deployment.yaml">
<violation number="1" location="infra/manifests/litellm/deployment.yaml:104">
P2: Mounting the ConfigMap at a file path without `subPath` will create a directory at `/etc/litellm/hooks.py`, so the hook file won’t be readable where the app expects it. Use a subPath (and/or configMap items) to mount the file instead of the whole directory.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Resolve conflicts in configmap.yaml: - Keep OAuth hook approach for Anthropic models (PR intent) - Fix OAUTH_TOKEN: use os.environ['OAUTH_TOKEN'] instead of bare variable (P0 review) - Add :free suffix to qwen3-235b model path to avoid paid routing (P1 review) - Add subPath to hooks.py volume mount to prevent directory creation (P2 review)
Owner
Author
|
All three review comments from cubic-dev-ai[bot] have been addressed in the merge commit:
|
binary64
added a commit
that referenced
this pull request
Feb 24, 2026
…s OAuth PR #19912 (merged Feb 17) fixed optionally_handle_anthropic_oauth() to: - Detect sk-ant-oat* tokens in api_key - Remove x-api-key header - Set Authorization: Bearer <token> correctly The custom pre-call hook (from PR #51) is now redundant and causes 'Extra inputs are not permitted' errors. Removing it and relying on ANTHROPIC_API_KEY env var containing the OAuth token.
binary64
added a commit
that referenced
this pull request
Feb 24, 2026
…s OAuth (#54) PR #19912 (merged Feb 17) fixed optionally_handle_anthropic_oauth() to: - Detect sk-ant-oat* tokens in api_key - Remove x-api-key header - Set Authorization: Bearer <token> correctly The custom pre-call hook (from PR #51) is now redundant and causes 'Extra inputs are not permitted' errors. Removing it and relying on ANTHROPIC_API_KEY env var containing the OAuth token.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Switch Anthropic models from API key auth to OAuth auth using custom pre-call hook.
Changes
New Files
Modified Files
What This Does
The hook replaces the previous approach with a proper OAuth flow:
Requirements
Testing
Test by making Anthropic API calls through the litellm proxy and verifying:
Summary by cubic
Switches Anthropic models in LiteLLM from API key auth to OAuth via a custom pre-call hook. Centralizes auth, injects required headers, and cleans up config; also routes the Qwen thinking model to the free tier.
New Features
Migration
Written for commit f42e156. Summary will update on new commits.