- Add @lru_cache decorator to get_model_info() and _cached_get_model_info_helper()
- Update _invalidate_model_cost_lowercase_map() to clear these caches when model_cost changes
- Update test to call cache invalidation after modifying litellm.model_cost
Reduces get_model_cost_information from 46% to <1% of request handling time.
* perf: Optimize use_custom_pricing_for_model with set intersection
Cache CustomPricingLiteLLMParams.model_fields.keys() as a module-level
frozenset and use set intersection to reduce loop iterations from 882k
to 90k (only iterating over keys that exist in both sets).
Performance improvement: 84% faster (6.3x speedup)
- Before: 1.17s total, 65µs per call
- After: 0.19s total, 10µs per call
* Use .get() for defensive dictionary access
* perf: Optimize strip_trailing_slash with O(1) index check
Replace rstrip("/") with direct index check for O(1) performance
instead of O(n) string scanning.
Results:
- strip_trailing_slash: 311ms → 13ms (96% faster)
- get_standard_logging_object_payload: 6.11s → 5.80s (5% faster)
* Handle multiple trailing slashes in strip_trailing_slash
Use rstrip for correctness when URL ends with "//" or more,
otherwise use O(1) index check for single trailing slash.
The generic provider params update logic loop was unintentionaly overwriting `patterns` and `blocked_words` with empty values because these fields are managed by a separate component ContentFilterManager and not available in the main form values.
Changes:
- Excluded `patterns` and `blocked_words` from the generic provider params update loop in guardrail_info.tsx
- Ensured these fields are only added to the update payload when explicitly handled by the ContentFilterManager logic (detecting changes via `useRef`).
- Added a regression test in guardrail_info.test.tsx to verify that patterns are preserved when only the guardrail name is updated.
Fixes#19639
Add support for /embeddings endpoint via Vercel AI Gateway.
Closes#19658
Changes:
- Add VercelAIGatewayEmbeddingConfig in litellm/llms/vercel_ai_gateway/embedding/
- Register provider in utils.py and main.py
- Add unit tests for embedding transformation
- Update documentation with embeddings examples
Usage:
```python
from litellm import embedding
response = embedding(
model="vercel_ai_gateway/openai/text-embedding-3-small",
input="Hello world",
api_key="your-api-key"
)
```