Skip to content

fix: python 3.10 typing compatibility in compact editor and claude 3 cache pricing (#38076, #38056) - #38189

Open
Alphaxiaoteng wants to merge 1 commit into
BerriAI:mainfrom
Alphaxiaoteng:fix/python-310-typing-and-claude-cache-pricing
Open

fix: python 3.10 typing compatibility in compact editor and claude 3 cache pricing (#38076, #38056)#38189
Alphaxiaoteng wants to merge 1 commit into
BerriAI:mainfrom
Alphaxiaoteng:fix/python-310-typing-and-claude-cache-pricing

Conversation

@Alphaxiaoteng

Copy link
Copy Markdown

Description

This PR resolves two issues:

  1. Issue [Bug]: import litellm fails on Python 3.10 — NotRequired imported from stdlib typing without fallback #38076: Python 3.10 typing compatibility in compact.py

    • In litellm/llms/anthropic/experimental_pass_through/context_management/editors/compact.py, NotRequired was imported directly from typing, which causes an ImportError on Python < 3.11.
    • Updated the import to conditionally import NotRequired from typing on Python >= 3.11 and fallback to typing_extensions on Python < 3.11.
  2. Issue [Bug]: claude-3-haiku and claude-3-opus have the Sonnet 1-hour cache write price (12x over / 5x under) #38056: Claude 3 cache creation pricing above 1hr

    • Corrected cache_creation_input_token_cost_above_1hr in model_prices_and_context_window.json and model_prices_and_context_window_backup.json:
      • claude-3-haiku-20240307: 5e-07 (2x input cost 2.5e-07, was incorrectly set to 6e-06)
      • claude-3-opus-20240229: 3e-05 (2x input cost 1.5e-05, was incorrectly set to 6e-06)

Tests

  • Added unit tests:
    • tests/test_litellm/llms/anthropic/experimental_pass_through/context_management/test_compact_typing_compatibility.py
    • tests/test_litellm/test_claude_3_cache_pricing.py
  • Verified with pytest across Python 3.10 and Python 3.11.
  • Validated model prices schema against model_prices_and_context_window.schema.json.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a version-compatible NotRequired import for the compact Anthropic editor and corrects Claude 3 long-duration cache-creation prices in both model-cost maps.

  • Adds compatibility and TypedDict regression tests for the compact editor.
  • Updates Haiku and Opus cache pricing and tests both canonical and backup maps.
  • The compatibility test does not exercise its Python 3.10 branch in the standard Python 3.12 unit workflow, and two new comments conflict with the repository’s source-comment convention.

Confidence Score: 4/5

The PR appears safe to merge, with non-blocking improvements needed in Python 3.10 regression coverage and test-comment cleanup.

The implementation and synchronized pricing updates have no established runtime defect, while the accepted findings concern an unexercised compatibility-test branch and redundant comments.

Files Needing Attention: tests/test_litellm/llms/anthropic/experimental_pass_through/context_management/test_compact_typing_compatibility.py; tests/test_litellm/test_claude_3_cache_pricing.py

Important Files Changed

Filename Overview
litellm/llms/anthropic/experimental_pass_through/context_management/editors/compact.py Selects NotRequired from typing on Python 3.11+ and typing_extensions on older supported runtimes; no concrete implementation defect was identified.
model_prices_and_context_window.json Corrects the Claude 3 Haiku and Opus above-one-hour cache-creation rates in the canonical model-cost map.
litellm/model_prices_and_context_window_backup.json Mirrors the same corrected rates in the packaged backup map.
tests/test_litellm/llms/anthropic/experimental_pass_through/context_management/test_compact_typing_compatibility.py Adds import and TypedDict checks, but the standard Python 3.12 workflow cannot exercise the Python 3.10 fallback branch.
tests/test_litellm/test_claude_3_cache_pricing.py Verifies both pricing maps, with two redundant comments that violate the repository’s source-comment convention.

Reviews (1): Last reviewed commit: "fix: python 3.10 typing compatibility in..." | Re-trigger Greptile

Comment on lines +18 to +25
if sys.version_info >= (3, 11):
import typing

assert compact_module.NotRequired is typing.NotRequired
else:
import typing_extensions

assert compact_module.NotRequired is typing_extensions.NotRequired

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Python 3.10 Branch Untested

The test selects its assertion from the interpreter running pytest, while the standard unit workflow uses Python 3.12. As a result, the newly added typing_extensions.NotRequired fallback is not exercised there, so a Python 3.10 compatibility regression would not be caught by this test.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

assert model in prices, f"{model} not found in {path}"
model_info = prices[model]

input_cost = model_info["input_cost_per_token"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant Pricing Comments

This comment and the equivalent Opus comment merely restate the immediately following input_cost * 2 calculations. Removing both avoids duplicated prose that can become stale and follows the repository convention of reserving source comments for complex logic, tool directives, or TODO/FIXME items.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...pass_through/context_management/editors/compact.py 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing Alphaxiaoteng:fix/python-310-typing-and-claude-cache-pricing (2b5c4e2) with main (947dbbf)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants