litellm - ✅(Solved) Fix [Bug]: Valid API key not accepted: "Invalid proxy server token passed" [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#24680Fetched 2026-04-08 01:42:13
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
1
Participants
Timeline (top)
labeled ×2cross-referenced ×1subscribed ×1

Error Message

11:34:20 - LiteLLM Proxy:ERROR: auth_exception_handler.py:78 - litellm.proxy.proxy_server.user_api_key_auth(): Exception occured - Requester IP Address:<ip> Traceback (most recent call last): File "/usr/lib/python3.13/site-packages/litellm/proxy/auth/user_api_key_auth.py", line 1149, in _user_api_key_auth_builder raise e File "/usr/lib/python3.13/site-packages/litellm/proxy/auth/user_api_key_auth.py", line 1137, in _user_api_key_auth_builder valid_token = await get_key_object( ^^^^^^^^^^^^^^^^^^^^^ ...<5 lines>... ) ^ File "/usr/lib/python3.13/site-packages/litellm/proxy/db/log_db_metrics.py", line 99, in wrapper raise e File "/usr/lib/python3.13/site-packages/litellm/proxy/db/log_db_metrics.py", line 42, in wrapper result = await func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/litellm/proxy/auth/auth_checks.py", line 2197, in get_key_object raise ProxyException( ...<6 lines>... ) litellm.proxy._types.ProxyException INFO: <ip>:<port> - "GET /key/info HTTP/1.0" 401 Unauthorized

Fix Action

Fixed

PR fix notes

PR #24731: fix(proxy): restore deprecated key auth cache lookups

Description (problem / solution / changelog)

Relevant issues

Fixes #24680

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the [tests/test_litellm/](https://github.com/BerriAI/ litellm/tree/main/tests/test_litellm) directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on [make test-unit](https://docs.litellm.ai/docs/ extras/contributing_code)
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on [Slack (#pr- review)](https://join.slack.com/t/litellmossslack/shared_invite/zt-3o7nkuyfr- p_kbNJj8taRfXGgQI1~YyA).

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run Link:

  • CI run for the last commit Link:

  • Merge / cherry-pick CI run Links:

Type

🐛 Bug Fix

Changes

Problem

After upgrading to v1.82.3, some previously valid LiteLLM virtual keys started failing auth with:

Authentication Error, Invalid proxy server token passed ... Unable to find token in cache or LiteLLM_VerificationTokenTable

This affects keys that are still expected to work during the deprecated-key grace period after regeneration / rotation.

Root cause

LiteLLM supports grace-period auth for rotated keys via _lookup_deprecated_key(), which checks LiteLLM_DeprecatedVerificationToken and caches old-key -> active-key mappings in memory.

The bug was in the in-memory cache tuple handling:

  • cache reads expected 3 values:
    • active_token_id
    • cache_expires_at_ts
    • revoke_at_ts
  • cache writes only stored 2 values:
    • active_token_id
    • cache_expires_at_ts

That means the first deprecated-key lookup could succeed from DB, but the next lookup could fail when reading the malformed cache entry. In practice this breaks auth for keys relying on the deprecated-key grace-period fallback and surfaces as token_not_found_in_db.

Fix

This PR updates litellm/proxy/utils.py to make deprecated-key cache reads and writes consistent:

  • store revoke_at.timestamp() in the cache tuple
  • support both the new 3-field tuple and legacy 2-field tuples when reading
  • evict malformed cache entries safely
  • remove the duplicate cache read in _lookup_deprecated_key()

Test

Added a regression test in tests/test_litellm/proxy/auth/test_user_api_key_auth.py to verify:

  • the first deprecated-key lookup resolves via DB
  • the second lookup resolves from the in-memory cache
  • the cached path no longer breaks auth

Local verification completed:

  • tests/test_litellm/proxy/auth/test_user_api_key_auth.py -k deprecated_key_uses_cache_on_subsequent_requests

Changed files

  • litellm/proxy/utils.py (modified, +25/-5)
  • tests/test_litellm/proxy/auth/test_user_api_key_auth.py (modified, +38/-9)

Code Example

yuri🐝bee:~> curl -s https://<liteLLM_url>/key/info -H "Authorization: Bearer <api_key>" | jq
{
  "error": {
    "message": "Authentication Error, Invalid proxy server token passed. Received API Key = sk-...m31Q, Key Hash (Token) =<hash>. Unable to find token in cache or `LiteLLM_VerificationTokenTable`",
    "type": "token_not_found_in_db",
    "param": "key",
    "code": "401"
  }
}

---

11:34:20 - LiteLLM Proxy:ERROR: auth_exception_handler.py:78 - litellm.proxy.proxy_server.user_api_key_auth(): Exception occured - 
Requester IP Address:<ip>
Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/proxy/auth/user_api_key_auth.py", line 1149, in _user_api_key_auth_builder
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/proxy/auth/user_api_key_auth.py", line 1137, in _user_api_key_auth_builder
    valid_token = await get_key_object(
                  ^^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/proxy/db/log_db_metrics.py", line 99, in wrapper
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/proxy/db/log_db_metrics.py", line 42, in wrapper
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/proxy/auth/auth_checks.py", line 2197, in get_key_object
    raise ProxyException(
    ...<6 lines>...
    )
litellm.proxy._types.ProxyException
INFO:     <ip>:<port> - "GET /key/info HTTP/1.0" 401 Unauthorized
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

Since updating to 1.82.3, some of the API keys that were created in liteLLM can no longer access any of the models.

Example with a valid key using curl (Same error appears when using the playground in the web UI)

yuri🐝bee:~> curl -s https://<liteLLM_url>/key/info -H "Authorization: Bearer <api_key>" | jq
{
  "error": {
    "message": "Authentication Error, Invalid proxy server token passed. Received API Key = sk-...m31Q, Key Hash (Token) =<hash>. Unable to find token in cache or `LiteLLM_VerificationTokenTable`",
    "type": "token_not_found_in_db",
    "param": "key",
    "code": "401"
  }
}

This key created a long time ago and has worked perfectly well. But since the update, the key can't make any sort of request, neither administrative (/key/info) nor model related (completions). The key is not disabled, or expired, or canceled.

We've been troubleshooting this for a few hours, and we can't determine why this happens.

I've found a few other issues that may be releated:

#13887 - Not applicable, since we have not blocked this API key. #18474 - Issue was never resolved

This has happened not only with this one api key, but with a bunch of others, and is severely impacting our use of liteLLM.

Steps to Reproduce

Relevant log output

11:34:20 - LiteLLM Proxy:ERROR: auth_exception_handler.py:78 - litellm.proxy.proxy_server.user_api_key_auth(): Exception occured - 
Requester IP Address:<ip>
Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/proxy/auth/user_api_key_auth.py", line 1149, in _user_api_key_auth_builder
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/proxy/auth/user_api_key_auth.py", line 1137, in _user_api_key_auth_builder
    valid_token = await get_key_object(
                  ^^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/proxy/db/log_db_metrics.py", line 99, in wrapper
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/proxy/db/log_db_metrics.py", line 42, in wrapper
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/proxy/auth/auth_checks.py", line 2197, in get_key_object
    raise ProxyException(
    ...<6 lines>...
    )
litellm.proxy._types.ProxyException
INFO:     <ip>:<port> - "GET /key/info HTTP/1.0" 401 Unauthorized

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.82.3

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

The fix involves updating the LiteLLM_VerificationTokenTable to include the missing tokens. Here are the steps:

  • Check the LiteLLM_VerificationTokenTable for missing tokens
  • Update the get_key_object function in auth_checks.py to handle missing tokens
  • Add a retry mechanism to handle token cache misses

Example code:

# auth_checks.py
async def get_key_object(key):
    try:
        # existing code
    except ProxyException:
        # retry mechanism
        await retry_get_key_object(key)

async def retry_get_key_object(key):
    # retry logic
    pass

Verification

To verify the fix, use the curl command to test the API key:

curl -s https://<liteLLM_url>/key/info -H "Authorization: Bearer <api_key>" | jq

Check the response for a successful authentication.

Extra Tips

  • Make sure to update the LiteLLM_VerificationTokenTable regularly to prevent token expiration.
  • Consider implementing a token refresh mechanism to handle token cache misses.
  • Review the auth_checks.py file for any other potential issues that may be causing the authentication error.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING