Commit Graph

34378 Commits

Author SHA1 Message Date
Cesar Garcia
0ed261b34e
fix(gemini): fix negative text_tokens when using cache with images (#18768)
* fix(gemini): prevent negative text_tokens with explicit caching (#18750)

## Problem
When using Gemini with explicit caching (especially with images),
text_tokens would become negative (e.g., -3327) due to incorrectly
subtracting total cached_tokens from modality-specific text_tokens.

## Root Cause
The old code did:
```python
text_tokens = text_tokens - cached_tokens  # 737 - 4064 = -3327
```

This was wrong because:
- cached_tokens includes ALL modalities (text + image + audio + video)
- text_tokens only contains text
- Subtracting total from specific caused negative values

## Solution
Parse cacheTokensDetails to get per-modality cached token breakdown:
```python
if "cacheTokensDetails" in usage_metadata:
    cached_text_tokens = parse from cacheTokensDetails["TEXT"]
    text_tokens = text_tokens - cached_text_tokens  # Correct!
```

Now we subtract cached tokens per modality, preventing negatives.

## Changes
- Parse cacheTokensDetails field from Gemini response
- Calculate non-cached tokens per modality (text, image, audio)
- Remove incorrect global cached_tokens subtraction
- Add tests for explicit caching and implicit/no caching scenarios

## Testing
- Added test_gemini_cache_tokens_details_no_negative_values
- Added test_gemini_without_cache_tokens_details
- All existing Gemini caching tests pass

Fixes #18750

* feat: add cache_read_input_tokens to Usage object

Addresses reviewer feedback to include cached tokens at the top level
of the Usage object. This aligns with how Anthropic provider handles
cached tokens and ensures they are visible in the final usage response.

* fix: add cacheTokensDetails field to UsageMetadata TypedDict

Fixes mypy error where cacheTokensDetails was being accessed but not defined
in the UsageMetadata TypedDict type definition.
2026-01-12 17:04:33 +05:30
Cesar Garcia
932f06104d
fix: include IMAGE token count in cost calculation for Gemini models (#18876)
* fix: include IMAGE token count as separate usage count and pricing

* fix: remove duplicate TypedDict key and variable definitions

- Remove duplicate input_cost_per_image_token in ModelInfoBase TypedDict
- Remove duplicate image_tokens variable declaration in _calculate_usage()

Fixes MyPy errors:
- types/utils.py:146: Duplicate TypedDict key
- vertex_and_google_ai_studio_gemini.py:1541: Name already defined

---------

Co-authored-by: Thomas Rehn <271119+tremlin@users.noreply.github.com>
2026-01-12 17:03:42 +05:30
Harshit Jain
5ce3a56ac3
add better err handling for antropic (#18955) 2026-01-12 17:03:03 +05:30
Harshit Jain
3257cc7129
doc: updated pass_through with guided param (#18886) 2026-01-12 16:56:16 +05:30
Harshit Jain
45ac107bee
doc: update load balancing and routing with enable_pre_call_checks (#18888) 2026-01-12 16:47:25 +05:30
Harshit Jain
f9430d1cab
docs: add Redis requirement warning for high-traffic deployments (#18892) 2026-01-12 16:46:52 +05:30
Ryan Malloy
c2366194d4
fix(anthropic): prevent dropping thinking when any message has thinking_blocks (#18929)
* fix(anthropic): prevent dropping thinking when any message has thinking_blocks

When Claude returns multiple assistant messages in a conversation, some may
have thinking_blocks while others may not (Claude's behavior varies). The
previous logic only checked the LAST assistant message with tool_calls,
dropping the thinking param if it had no thinking_blocks.

This caused errors when earlier messages still contained thinking_blocks:
"When thinking is disabled, an assistant message cannot contain thinking"

The fix adds a new check: only drop thinking if NO assistant messages
have thinking_blocks. If any message has thinking_blocks, we keep
thinking enabled.

Fixes #18926

* chore: re-trigger CI
2026-01-12 16:29:44 +05:30
Igal Boxerman
6bb63525db
fix(guardrails): fix SerializationIterator error and pass tools to guardrail (#18932)
* fix(generic-guardrail-api): fix SerializationIterator error on multimodal requests

When sending multimodal messages (with images) through the Generic Guardrail API,
the `model_dump()` call fails with "Object of type SerializationIterator is not
JSON serializable" error.

Root cause: The `ChatCompletionAssistantMessage` type defines `content` as an
`Iterable` (not just `List`), and Pydantic's `model_dump()` creates a
`SerializationIterator` for iterables which is not JSON serializable.

Fix: Use `model_dump(mode="json")` which properly converts all iterables to
lists and ensures all complex objects are JSON serializable.

* fix(guardrails): pass tools (function definitions) to guardrail inputs

The unified guardrail handler was not passing the `tools` parameter
(function definitions) from the request to the guardrail inputs.
This meant guardrails could not inspect or validate tool definitions.

Added extraction of `data.get("tools")` and inclusion in the
GenericGuardrailAPIInputs passed to `apply_guardrail()`.

* test(guardrails): add tests for tools passed to guardrail

Added tests verifying that tools (function definitions) are correctly
passed to guardrails in the unified guardrail handler:
- test_tools_passed_to_guardrail
- test_multiple_tools_passed_to_guardrail
- test_no_tools_in_request
- test_tools_and_tool_calls_both_passed
2026-01-12 16:27:54 +05:30
Jonathan Hoyt
1169be44b5
fix(google_genai): forward extra_headers in generateContent adapter (#18935)
When using the generateContent endpoint with non-Google providers like
github_copilot, the extra_headers from model config were not being
forwarded to the underlying litellm.completion/acompletion calls.

This caused providers requiring custom headers (e.g., Editor-Version
for GitHub Copilot authentication) to reject requests with errors like
"missing Editor-Version header for IDE auth".

Changes:
- Forward extra_headers in _prepare_completion_kwargs() handler
- Pass extra_headers explicitly to adapter in generate_content()
- Pass extra_headers explicitly to adapter in agenerate_content_stream()
- Pass extra_headers explicitly to adapter in generate_content_stream()
- Add tests for extra_headers forwarding behavior
- Update existing test to expect extra_headers in passed fields

Co-authored-by: Claude <noreply@anthropic.com>
2026-01-12 16:23:58 +05:30
Rayan Pal
ec25e16784
fix: add created_at/updated_at fields to LiteLLM_ProxyModelTable (#18937)
The Pydantic model was missing these timestamp fields that exist in the
Prisma schema. This caused the UI to display "Unknown date" for models
added via the dashboard, even though the data was being stored in the DB.

The fields were being read in get_model_info_with_id() using getattr(),
but since they weren't defined in the Pydantic model, getattr() always
returned None.

Fixes #15487
2026-01-12 16:21:35 +05:30
Sameer Kankute
028cdaf77b Add starting status for replicate 2026-01-12 15:20:38 +05:30
Sameer Kankute
3d38ec4756 Add all replicate models in model cost map 2026-01-12 15:19:49 +05:30
Sameer Kankute
548716ab59 Add steps-to-reproduce section in bug report 2026-01-12 13:53:26 +05:30
Sameer Kankute
68fdcaea4a Fix: [Bug]: Gemini Image Generation: imageConfig parameters (imageSize, aspectRatio) are completely ignored #18656 2026-01-12 13:38:37 +05:30
Sameer Kankute
508e4da40e Fix: respect max_completion_tokens in thinking feat 2026-01-12 12:44:46 +05:30
Sameer Kankute
c96a7e80dd
Merge pull request #18898 from yogeshwaran10/litellm_fix_gemini_token_usage_details
fix: missing completion_tokens_details in gemini 3 flash when reasoning_effort is not used (#18896)
2026-01-12 12:33:40 +05:30
Sameer Kankute
3c1ffda117 Add: missing anthropic tool results 2026-01-12 11:44:07 +05:30
yogeshwaran10
0e960df8f4 refactor(tests): move gemini token usage tests to test_vertex_and_google_ai_studio_gemini.py 2026-01-12 11:20:13 +05:30
Sameer Kankute
dabb459d2b Fix : model id encoding for bedrock passthrough 2026-01-12 10:57:17 +05:30
Sameer Kankute
7e3760b740
Merge pull request #18899 from Chesars/claude/check-gpt-oss-pricing-4wKrq
fix: correct pricing for openrouter/openai/gpt-oss-20b
2026-01-12 09:09:20 +05:30
Sameer Kankute
aa97a34a83 Fix tests/test_litellm/llms/bedrock/test_base_aws_llm.py 2026-01-12 09:05:28 +05:30
Sameer Kankute
a9e57cf272 [Bug]: Add Custom CA certificates to boto3 clients 2026-01-12 09:05:09 +05:30
Yuta Saito
76f79610b3 fix: forward MCP extra headers case-insensitively 2026-01-12 10:32:51 +09:00
YutaSaito
dd299c93c2
Merge pull request #18934 from BerriAI/litellm_fix_multiple_mcp_scheduler
[fix] prevent duplicate MCP reload scheduler registration
2026-01-12 07:51:29 +09:00
Yuta Saito
73f66b101c fix: prevent duplicate MCP reload scheduler registration 2026-01-12 07:10:22 +09:00
YutaSaito
c171954629
Merge pull request #18912 from BerriAI/litellm_fix_pangea_guardrail
[fix] respect pangea guardrail default_on during initialization
2026-01-12 05:43:54 +09:00
YutaSaito
a0b7e28fbc
Merge pull request #18882 from BerriAI/litellm_fix_db-migration-log-grep-flaky
[test] stabilize db_migration_disable_update_check test log check
2026-01-12 05:41:46 +09:00
Ishaan Jaffer
f768b698a9 docs fix 2026-01-11 11:57:23 -08:00
Ishaan Jaffer
1271044b06 1.80.15 2026-01-11 11:57:04 -08:00
Marco Vinciguerra
c82d74587d
Add ScrapeGraph MCP server configuration (#18923) 2026-01-11 21:57:46 +05:30
Ishaan Jaffer
7aee1fcb81 OCR test fixes 2026-01-11 08:00:31 -08:00
Ishaan Jaffer
080982e157 1.80.15 2026-01-10 17:50:13 -08:00
Ishaan Jaffer
f36e898cce bump: version 1.80.14 → 1.80.15 2026-01-10 17:49:46 -08:00
yuneng-jiang
0cc935325b Fixing build 2026-01-10 17:08:00 -08:00
yuneng-jiang
e783a66f2a Organization Filters UI 2026-01-10 17:06:00 -08:00
Alexsander Hamir
624c9420b9
perf release notes (#18915) 2026-01-10 16:41:54 -08:00
yuneng-jiang
707c2b55f5 Merge remote-tracking branch 'origin' into litellm_ui_org_filters_1 2026-01-10 15:55:48 -08:00
yuneng-jiang
9bcd6b7bc5
Merge pull request #18914 from BerriAI/ui_build_jan10
[Infra] Building UI
2026-01-10 15:49:15 -08:00
yuneng-jiang
c781bcfabb building ui 2026-01-10 15:46:55 -08:00
Ishaan Jaffer
34383ce97b fix route_request 2026-01-10 15:45:55 -08:00
yuneng-jiang
ecaa449f56
Merge pull request #18913 from BerriAI/endpoint_usage_docs
[Docs] Endpoint Usage Docs
2026-01-10 15:43:30 -08:00
yuneng-jiang
039e11cbe5 Endpoint activity writeup 2026-01-10 15:42:20 -08:00
yuneng-jiang
489a4730ab Merge remote-tracking branch 'origin' into endpoint_usage_docs 2026-01-10 15:41:46 -08:00
Yuta Saito
cef087f88b fix: respect pangea guardrail default_on during initialization 2026-01-11 08:33:31 +09:00
yuneng-jiang
728c5297cf
Merge pull request #18911 from BerriAI/litellm_ui_endpoint_usage_trend
[Fix] UI - Endpoint Activity Trend X-Axis and Time Range
2026-01-10 15:31:57 -08:00
Ishaan Jaffer
f1d516f0ae test fixes 2026-01-10 15:15:41 -08:00
yuneng-jiang
ef74f5edb1 fixing test 2026-01-10 15:15:27 -08:00
yuneng-jiang
0b34bfa14c Flipping x axis and removing time range picker 2026-01-10 15:14:17 -08:00
yuneng-jiang
dcae3d569f Flipping x axis and removing time range picker 2026-01-10 15:13:43 -08:00
Ishaan Jaffer
1ebe979eee test_manus_responses_api_with_file_upload 2026-01-10 15:12:00 -08:00