llm-optimizer 0.4.4__tar.gz → 0.4.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {llm_optimizer-0.4.4/llm_optimizer.egg-info → llm_optimizer-0.4.5}/PKG-INFO +79 -30
  2. llm_optimizer-0.4.4/PKG-INFO → llm_optimizer-0.4.5/README.md +1341 -1332
  3. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/__init__.py +1 -1
  4. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/batcher.py +2 -2
  5. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/budget.py +3 -3
  6. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/tracker.py +2 -2
  7. llm_optimizer-0.4.4/README.md → llm_optimizer-0.4.5/llm_optimizer.egg-info/PKG-INFO +1381 -1291
  8. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer.egg-info/SOURCES.txt +2 -1
  9. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/pyproject.toml +3 -4
  10. llm_optimizer-0.4.5/tests/test_v045_cleanups.py +24 -0
  11. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/LICENSE +0 -0
  12. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/analytics.py +0 -0
  13. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/bedrock.py +0 -0
  14. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/bedrock_cache.py +0 -0
  15. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/bedrock_converse.py +0 -0
  16. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/cache.py +0 -0
  17. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/caching.py +0 -0
  18. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/client.py +0 -0
  19. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/cross_provider_cache.py +0 -0
  20. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/document_parser.py +0 -0
  21. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/few_shot.py +0 -0
  22. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/history.py +0 -0
  23. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/local.py +0 -0
  24. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/models.py +0 -0
  25. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/optimizer.py +0 -0
  26. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/output_repair.py +0 -0
  27. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/pii.py +0 -0
  28. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/prefill.py +0 -0
  29. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/pricing.json +0 -0
  30. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/router.py +0 -0
  31. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/semantic_cache.py +0 -0
  32. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer/streaming.py +0 -0
  33. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer.egg-info/dependency_links.txt +0 -0
  34. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer.egg-info/entry_points.txt +0 -0
  35. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer.egg-info/requires.txt +0 -0
  36. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/llm_optimizer.egg-info/top_level.txt +0 -0
  37. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/setup.cfg +0 -0
  38. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/tests/test_llm_optimizer.py +0 -0
  39. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/tests/test_local.py +0 -0
  40. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/tests/test_v041.py +0 -0
  41. {llm_optimizer-0.4.4 → llm_optimizer-0.4.5}/tests/test_v044_fixes.py +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: llm-optimizer
3
- Version: 0.4.4
3
+ Version: 0.4.5
4
4
  Summary: Reduce LLM API costs by up to 90% — prompt caching, smart routing, batch processing, and more
5
5
  Author-email: Somnath Banerjee <banerjso30@gmail.com>
6
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/banerjeesollm-optimizer
8
8
  Project-URL: Documentation, https://github.com/banerjeeso/llm-optimizer#readme
9
9
  Project-URL: Issues, https://github.com/banerjeeso/llm-optimizer/issues
@@ -12,7 +12,6 @@ Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
- Classifier: License :: OSI Approved :: MIT License
16
15
  Classifier: Operating System :: OS Independent
17
16
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
17
  Classifier: Intended Audience :: Developers
@@ -58,9 +57,9 @@ client.print_summary()
58
57
  # 💰 Total cost: $0.000842 | Total saved: $0.007580 (90% savings)
59
58
  ```
60
59
 
61
- ![tests](https://img.shields.io/badge/tests-234%20passing-brightgreen) ![python](https://img.shields.io/badge/python-3.10%2B-blue) ![license](https://img.shields.io/badge/license-MIT-green)
60
+ ![tests](https://img.shields.io/badge/tests-245%20passing-brightgreen) ![python](https://img.shields.io/badge/python-3.10%2B-blue) ![license](https://img.shields.io/badge/license-MIT-green)
62
61
 
63
- > **v0.4.3** — Bedrock Converse API (Nova, Mistral, Llama support), Document Parser (PDF/DOCX/XLSX to Markdown), tracker cost_saved fix. See [CHANGELOG](#changelog).
62
+ > **v0.4.5** — Packaging and docs cleanup on top of the v0.4.4 bug fixes (batched requests now get prompt caching; cost and savings can no longer go negative). Pricing data refreshed. See [CHANGELOG](#changelog).
64
63
 
65
64
  ---
66
65
 
@@ -72,13 +71,14 @@ client.print_summary()
72
71
  - [Streaming](#streaming)
73
72
  - [Error Handling and Fallback Behavior](#error-handling-and-fallback-behavior)
74
73
  - [Limitations](#limitations)
74
+ - [Enterprise Features (upcoming)](#enterprise-features-upcoming)
75
75
  - [Configuration Reference](#configuration-reference)
76
76
  - [Pricing Data](#pricing-data)
77
77
  - [Available Models](#available-models)
78
78
  - [Test Suite](#test-suite)
79
79
  - [Project Structure](#project-structure)
80
80
  - [v0.4.3 — What's New](#v0.4.3--whats-new)
81
- - [Local Model Support](#19--local-model-support--ollama-lm-studio-vllm-llamacpp)
81
+ - [Local Model Support](#19--local-model-support--ollama-lm-studio-vllm-llamacpp)
82
82
  - [Changelog](#changelog)
83
83
 
84
84
  ---
@@ -151,7 +151,9 @@ response2 = client.complete(messages=[...], system=system) # 90% cheaper
151
151
  ```
152
152
 
153
153
  **How it works:** The library injects `cache_control: {type: "ephemeral"}` on content
154
- blocks that exceed 1,024 tokens, respecting Anthropic's 4-breakpoint limit. For OpenAI,
154
+ blocks that exceed the model's minimum (1,024 tokens; 2,048 for Haiku models), respecting
155
+ Anthropic's 4-breakpoint limit. Batched requests (`client.queue()`) get the same injection
156
+ since v0.4.4. For OpenAI,
155
157
  prefix caching is automatic on inputs ≥ 1,024 tokens — no markup needed.
156
158
 
157
159
  ---
@@ -225,7 +227,8 @@ result = opt.optimize(
225
227
  ### 4. 📦 Batch Processing — 50% off
226
228
 
227
229
  Queue non-urgent requests and submit via Anthropic's Message Batch API (50% cheaper,
228
- results within minutes to hours).
230
+ results within minutes to hours). Batched requests also receive prompt-cache breakpoints
231
+ (v0.4.4+), so the batch and cache discounts can stack.
229
232
 
230
233
  ```python
231
234
  client = OptimizedClient(
@@ -653,10 +656,28 @@ Both are implemented but not tested end-to-end in CI. Anthropic and Bedrock are
653
656
  the primary tested providers.
654
657
 
655
658
  **Enterprise features:**
656
- PII masking, compliance hashing, multi-tenant budgets, ROI reporting, cross-provider
657
- failover, rate limiting, corporate memory, and the enterprise proxy are available
658
- in `llm-optimizer-enterprise` — the companion package for corporate governance
659
- and compliance requirements.
659
+ Multi-tenant budgets, chargeback reports, failover and compliance tooling are not part
660
+ of this package. See [Enterprise Features (upcoming)](#enterprise-features-upcoming).
661
+
662
+ **Haiku 5.5 long prompts:**
663
+ Haiku 5.5 prices rise 5x above 100K input tokens. Tiered pricing is not modelled, so
664
+ cost estimates for very long prompts will be too low.
665
+
666
+ ---
667
+
668
+ ## Enterprise Features (upcoming)
669
+
670
+ A companion package, `llm-optimizer-enterprise`, is in preparation and will install on top
671
+ of this library. It is aimed at teams running llm-optimizer across departments:
672
+
673
+ - Multi-tenant budgets (company, department, user) and chargeback / ROI reports
674
+ - Cross-provider failover and a priority-aware rate limiter
675
+ - Compliance mode: salted cache keys and an audit log with no raw prompts
676
+ - Corporate-memory (RAG) hook and a central proxy for shared deployments
677
+
678
+ Not on PyPI yet. PII masking (`enable_pii_masking=True`) is already available in this
679
+ package. v0.4.4 adds a cache-key hook so the enterprise package can use salted keys;
680
+ default behaviour is unchanged.
660
681
 
661
682
  ---
662
683
 
@@ -749,7 +770,7 @@ Prices are stored in `llm_optimizer/pricing.json` — not hardcoded in source.
749
770
  ```python
750
771
  from llm_optimizer.models import pricing_info
751
772
  print(pricing_info())
752
- # {"version": "2026-07-14", "last_updated": "2026-07-14", "sources": {...}}
773
+ # {"version": "2026-11-29", "last_updated": "2026-11-19", "sources": {...}}
753
774
  ```
754
775
 
755
776
  The library emits a `UserWarning` automatically if pricing data is older than 30 days.
@@ -759,12 +780,16 @@ Update by editing `pricing.json` and bumping `last_updated`.
759
780
 
760
781
  ## Available Models
761
782
 
762
- > ⚠️ Prices as of `pricing.json` version `2026-07-14`. Verify at provider pricing pages.
783
+ > ⚠️ Prices as of `pricing.json` version `2026-11-29`. Anthropic rows were checked against a
784
+ > third-party copy of Anthropic's pricing page dated 2026-11-19; OpenAI, Google and Bedrock rows
785
+ > were not re-verified. Verify at provider pricing pages before financial decisions.
763
786
 
764
787
  | Key | Model | Provider | Input/1M | Cached/1M | Output/1M | Complexity |
765
788
  |---|---|---|---|---|---|---|
766
789
  | `claude-haiku-4-5` | Claude Haiku 4.5 | Anthropic | $1.00 | $0.10 | $5.00 | Simple, Medium |
767
- | `claude-haiku-3-5` | Claude Haiku 3.5 | Anthropic | $0.80 | $0.08 | $4.00 | Simple, Medium |
790
+ | `claude-haiku-5-5` | Claude Haiku 5.5 | Anthropic | $0.10 | $0.01 | $0.50 | Simple, Medium |
791
+ | `claude-sonnet-5-5` | Claude Sonnet 5.5 | Anthropic | $2.00 | $0.10 | $10.00 | Simple–Complex |
792
+ | `claude-opus-5-5` | Claude Opus 5.5 | Anthropic | $4.00 | $0.20 | $20.00 | All |
768
793
  | `claude-sonnet-4` | Claude Sonnet 4.5 | Anthropic | $3.00 | $0.30 | $15.00 | Simple–Complex |
769
794
  | `claude-opus-4` | Claude Opus 4.5 | Anthropic | $5.00 | $0.50 | $25.00 | All |
770
795
  | `bedrock-claude-haiku-4-5` | Claude Haiku 4.5 (Bedrock) | AWS Bedrock | $0.80 | $0.08 | $4.00 | Simple, Medium |
@@ -774,6 +799,9 @@ Update by editing `pricing.json` and bumping `last_updated`.
774
799
  | `gemini-flash` | Gemini 2.5 Flash | Google | $0.30 | $0.03 | $2.50 | Simple, Medium |
775
800
  | `gemini-pro` | Gemini 2.5 Pro | Google | $1.25 | $0.125 | $10.00 | All |
776
801
 
802
+ The 5.5 models are available with `model=` but are not yet in the automatic routing
803
+ defaults, so routing behaviour is unchanged. Claude Haiku 3.5 was removed (retired).
804
+
777
805
  ---
778
806
 
779
807
  ## Test Suite
@@ -787,7 +815,7 @@ python -m pytest tests/ -v -m "not integration"
787
815
  python -m pytest tests/ -v -m integration
788
816
  ```
789
817
 
790
- **What the 172 unit tests cover (no real API calls):**
818
+ **What the 245 unit tests cover (no real API calls):**
791
819
  - Token estimation logic
792
820
  - Model pricing calculations and cost math
793
821
  - Heuristic routing decisions and regression cases
@@ -806,6 +834,9 @@ python -m pytest tests/ -v -m integration
806
834
  - Streaming analytics — chunk recording and finalize()
807
835
  - Cost tracker arithmetic, persistence, thread safety
808
836
  - Retry and fallback logic (mocked exceptions)
837
+ - Bedrock Converse client and document parser (v0.4.1)
838
+ - Local model client
839
+ - v0.4.4 regressions: batch cache injection, usage totals, non-negative cost and savings
809
840
 
810
841
  **What unit tests do NOT cover (requires real API):**
811
842
  - Actual cache hits and cache write tokens from Anthropic
@@ -844,17 +875,20 @@ llm_optimizer/
844
875
  │
845
876
  ├── PROVIDER INTEGRATIONS
846
877
  │ ├── bedrock.py AWS Bedrock client wrapper
878
+ │ ├── bedrock_converse.py Bedrock Converse API (Claude, Nova, Mistral, Llama)
879
+ │ ├── local.py Local models via OpenAI-compatible servers
880
+ │ ├── document_parser.py PDF / DOCX / XLSX / CSV to Markdown
847
881
  │ └── streaming.py Streaming — Anthropic, OpenAI, Bedrock
848
882
  │
849
883
  ├── OBSERVABILITY
850
884
  │ ├── tracker.py Cost tracking + JSONL persistence
851
885
  │ ├── budget.py Budget enforcement
886
+ │ ├── pii.py PII masking and re-hydration
852
887
  │ └── analytics.py Streaming analytics — SSE-ready
853
888
  │
854
889
  ├── CONFIG
855
890
  │ ├── models.py Model registry — loads from pricing.json
856
- │ ├── pricing.json Externalized pricing with version stamp
857
- │ └── cli.py llm-optimizer check / pricing-info
891
+ │ └── pricing.json Externalized pricing with version stamp
858
892
 
859
893
  examples/
860
894
  ├── 01_basic_usage.py
@@ -862,16 +896,36 @@ examples/
862
896
  └── 03_batch_processing.py
863
897
 
864
898
  tests/
865
- └── test_llm_optimizer.py 172 unit tests, all mocked
899
+ ├── test_llm_optimizer.py core unit tests, all mocked
900
+ ├── test_v041.py Converse API + document parser
901
+ ├── test_local.py local model client
902
+ └── test_v044_fixes.py v0.4.4 regression tests
866
903
  ```
867
904
 
868
905
  ---
869
906
 
870
907
  ## Changelog
871
908
 
909
+ ### v0.4.5 — Packaging and docs cleanup
910
+
911
+ - **Fixed:** removed `datetime.utcnow()` deprecation warnings (Python 3.12+). Timestamps keep the same naive-UTC ISO format, so existing usage and budget files still load
912
+ - **Fixed:** `pyproject.toml` uses an SPDX license expression (`license = "MIT"`) and `setuptools>=77`, removing the build-time license deprecation warnings
913
+ - **Docs:** README now includes the full changelog and an "Enterprise Features (upcoming)" section describing the planned `llm-optimizer-enterprise` companion package (not yet released)
914
+ - Tests: 245 passing; the suite also passes with `DeprecationWarning` treated as an error
915
+
916
+ ### v0.4.4 — Bug fixes (reported by Vihaan Chowdhury, ComputeIQ)
917
+
918
+ - **Fixed:** batched requests (`queue()`) now get `cache_control` injected, so the batch and prompt-cache discounts can stack
919
+ - **Fixed:** Anthropic's `usage.input_tokens` excludes cache reads. Total input is now input + cache read + cache write, which removes negative cost and savings on real responses
920
+ - **Hardened:** `CostTracker.record()` clamps cached tokens to input tokens; `estimate_cost()`, `cache_savings()` and `summary()` can no longer return negative values
921
+ - **Changed:** the cache minimum is model-aware (Haiku 2,048 tokens; other models 1,024)
922
+ - **Updated:** `pricing.json` adds Haiku 5.5, Sonnet 5.5 and Opus 5.5 and removes the retired Haiku 3.5. Anthropic prices were checked against a third-party copy of the pricing page; other providers were not re-verified
923
+ - **Added:** a cache-key hook (`_cache_key_fn`) for the upcoming `llm-optimizer-enterprise` package; default behaviour unchanged
924
+ - Tests: 243 passing (9 new regression tests)
925
+
872
926
  ### v0.4.3
873
927
 
874
- - Bedrock Converse API (Nova, Mistral, Llama support), Document Parser (PDF/DOCX/XLSX to Markdown), tracker cost_saved fix
928
+ - Bedrock Converse API (Nova, Mistral, Llama support), Document Parser (PDF/DOCX/XLSX to Markdown), tracker cost_saved fix
875
929
 
876
930
  ### v0.4.2
877
931
 
@@ -879,10 +933,6 @@ tests/
879
933
 
880
934
  ### v0.4.1
881
935
 
882
- - BUG FIX
883
-
884
- ### v0.4.1
885
-
886
936
  - **Bedrock Converse API** — unified format for Claude, Nova, Titan, Llama, Mistral on Bedrock. `BedrockConverseClient` and `make_converse_client()` factory. Streaming supported. 11 model IDs in registry across 5 families.
887
937
  - **Document Parser** — PDF, DOCX, XLSX, CSV, TXT to structured Markdown. Page limit, token limit, multi-document formatting, bytes input. Zero lossy compression — full content extraction.
888
938
  - **Tracker fix** — `cost_saved` parameter correctly recorded for output cache hits. `Total Saved` in `print_summary()` now shows accurately.
@@ -915,15 +965,14 @@ tests/
915
965
  - Bedrock cachePoint translation — auto-translates Anthropic `cache_control` → Bedrock `cachePoint` format
916
966
  - TTL preservation on Bedrock — fixes open LiteLLM bug (GitHub #20326, Feb 2026)
917
967
  - `make_bedrock_client()` accepts `enable_caching` and `cache_ttl` parameters
918
- - Correct model IDs matching Bedrock account format (`anthropic.claude-haiku-4-5-20251001-v1:0`)
968
+ - Bedrock model IDs aligned with the account format of that release (later versions use the `global.` inference-profile IDs in `pricing.json`)
919
969
  - Negotiated discount support via `discount_pct`
920
970
 
921
971
  **Test suite: 172 tests — all unit tests, no real API calls required**
922
972
 
923
- > **Note:** PII masking, compliance hashing, multi-tenant budgets, ROI reporting,
924
- > cross-provider failover, rate limiting, corporate memory, and the enterprise proxy
925
- > are available in `llm-optimizer-enterprise` — the companion package for
926
- > corporate governance and compliance requirements.
973
+ > **Note:** Multi-tenant budgets, ROI reporting, cross-provider failover, rate limiting,
974
+ > compliance hashing, corporate memory and a central proxy are planned for the companion
975
+ > package `llm-optimizer-enterprise` (upcoming). PII masking is already in this package.
927
976
 
928
977
  ---
929
978
 
@@ -1020,7 +1069,7 @@ for chunk in client.stream(messages=[...], model_id=CONVERSE_MODELS["nova-pro"])
1020
1069
  |---|---|---|---|
1021
1070
  | `claude-haiku-4-5` | `us.anthropic.claude-haiku-4-5-20251001-v1:0` | Anthropic | Fast, cheap |
1022
1071
  | `claude-sonnet-4-5` | `us.anthropic.claude-sonnet-4-5-20250929-v1:0` | Anthropic | Best all-rounder |
1023
- | `claude-sonnet-4-6` | `us.anthropic.claude-sonnet-4-6` | Anthropic | Org standard |
1072
+ | `claude-sonnet-4-6` | `us.anthropic.claude-sonnet-4-6` | Anthropic | Latest Sonnet 4.x |
1024
1073
  | `claude-opus-4-5` | `us.anthropic.claude-opus-4-5-20251101-v1:0` | Anthropic | Expert tasks |
1025
1074
  | `nova-micro` | `us.amazon.nova-micro-v1:0` | Amazon | Cheapest — text only |
1026
1075
  | `nova-lite` | `us.amazon.nova-lite-v1:0` | Amazon | Multimodal |