Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Merge remote-tracking branch 'origin/litellm_internal_staging' into codex/budget-race-enforcement-greptile-fix

user64fadc3b8ed2
diff --cc litellm/proxy/db/spend_counter_reseed.py
index 0137acf5ed9,a979471dc8e..d4acb39062c
--- a/litellm/proxy/db/spend_counter_reseed.py
+++ b/litellm/proxy/db/spend_counter_reseed.py
@@@ -179,21 -152,9 +183,22 @@@ class SpendCounterReseed
return None
# Warm even when 0 so subsequent reads hit cache, not DB.
try:
- await spend_counter_cache.async_increment_cache(
- key=counter_key, value=db_spend, refresh_ttl=True
- )
+ if require_cache_warm and spend_counter_cache.redis_cache is not None:
+ current_value = (
+ await spend_counter_cache.redis_cache.async_increment(
+ key=counter_key,
+ value=db_spend,
++ refresh_ttl=True,
+ )
+ )
+ spend_counter_cache.in_memory_cache.set_cache(
+ key=counter_key,
+ value=current_value,
+ )
+ else:
+ await spend_counter_cache.async_increment_cache(
- key=counter_key, value=db_spend
++ key=counter_key, value=db_spend, refresh_ttl=True
+ )
except Exception:
verbose_proxy_logger.exception(
"SpendCounterReseed.coalesced: failed to warm counter %s",
diff --cc litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
index 77eb3a5ee0c,714b5f3c7b6..cc6c26fdf90
--- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
+++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
@@@ -2325,12 -2324,14 +2324,10 @@@ async def _register_pass_through_endpoi
dependencies = None
if auth is not None and str(auth).lower() == "true":
- if premium_user is not True:
- raise ValueError(
- "Error Setting Authentication on Pass Through Endpoint: {}".format(
- CommonProxyErrors.not_premium_user.value
- )
- )
- # Authentication on a pass-through endpoint used to be enterprise-
- # only — which left the OSS tier with no safe configuration: the
- # default was ``auth=False`` (unauthenticated forwarder) and the
- # safe ``auth=True`` raised at startup unless the operator had a
- # license. The default is now ``True`` (safe-by-default), and
- # turning it on no longer requires a license: an unauthenticated
- # forwarder is a deployment choice the operator should be allowed
- # to make explicitly, but the safe option must always be free.
++ # Authentication on a pass-through endpoint used to be enterprise-only.
++ # That left OSS with no safe configuration: auth=True raised at startup
++ # unless the operator had a license. The safe option must always be free,
++ # and unauthenticated forwarding should require explicit opt-in.
dependencies = [Depends(user_api_key_auth)]
if path not in LiteLLMRoutes.openai_routes.value:
LiteLLMRoutes.openai_routes.value.append(path)
diff --cc litellm/proxy/proxy_server.py
index dd46f09fbca,6cba6a3e96b..889f85c40af
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@@ -2116,50 -1980,12 +2121,52 @@@ async def _ensure_spend_counter_initial
else:
base_spend = getattr(source, "spend", 0.0) or 0.0
if base_spend > 0:
- await spend_counter_cache.async_increment_cache(
- key=counter_key, value=base_spend, refresh_ttl=True
+ await _increment_spend_counter_cache(
+ counter_key=counter_key, increment=base_spend
)
- await spend_counter_cache.async_increment_cache(
- key=counter_key, value=increment, refresh_ttl=True
+
+async def _ensure_window_spend_counter_initialized(
+ counter_key: str,
+ entity_type: str,
+ entity_id: str,
+ window_start: datetime,
+):
+ current = await spend_counter_cache.async_get_cache(key=counter_key)
+ if current is None:
+ window_spend = await SpendCounterReseed.coalesced_window(
+ prisma_client=prisma_client,
+ spend_counter_cache=spend_counter_cache,
+ counter_key=counter_key,
+ entity_type=entity_type,
+ entity_id=entity_id,
+ window_start=window_start,
+ )
+ if window_spend is None:
+ await _increment_spend_counter_cache(counter_key=counter_key, increment=0.0)
+
+
+async def _increment_spend_counter_cache(counter_key: str, increment: float):
+ if spend_counter_cache.redis_cache is not None:
+ try:
+ current_value = await spend_counter_cache.redis_cache.async_increment(
+ key=counter_key,
+ value=increment,
++ refresh_ttl=True,
+ )
+ except Exception:
+ await _invalidate_spend_counter(counter_key=counter_key)
+ raise
+ spend_counter_cache.in_memory_cache.set_cache(
+ key=counter_key,
+ value=current_value,
+ )
+ return current_value
+
+ return await spend_counter_cache.async_increment_cache(
+ key=counter_key,
+ value=increment,
++ refresh_ttl=True,
)