llm-cost-guard 0.1.1__tar.gz → 0.2.0__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 (58) hide show
  1. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/PKG-INFO +79 -3
  2. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/README.md +77 -2
  3. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/__init__.py +16 -1
  4. llm_cost_guard-0.2.0/llm_cost_guard/audit.py +480 -0
  5. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/backends/__init__.py +1 -1
  6. llm_cost_guard-0.2.0/llm_cost_guard/backends/redis_backend.py +557 -0
  7. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/tracker.py +114 -3
  8. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/pyproject.toml +2 -1
  9. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/.github/workflows/ci.yml +0 -0
  10. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/.github/workflows/publish.yml +0 -0
  11. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/.gitignore +0 -0
  12. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/LICENSE +0 -0
  13. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/examples/bedrock_example.py +0 -0
  14. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/examples/budget_alerts.py +0 -0
  15. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/examples/distributed_tracking.py +0 -0
  16. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/examples/langchain_rag.py +0 -0
  17. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/examples/quickstart.py +0 -0
  18. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/examples/streaming_example.py +0 -0
  19. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/backends/base.py +0 -0
  20. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/backends/memory.py +0 -0
  21. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/backends/sqlite.py +0 -0
  22. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/budget.py +0 -0
  23. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/cli.py +0 -0
  24. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/clients/__init__.py +0 -0
  25. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/clients/anthropic.py +0 -0
  26. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/clients/openai.py +0 -0
  27. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/exceptions.py +0 -0
  28. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/integrations/__init__.py +0 -0
  29. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/integrations/cache.py +0 -0
  30. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/integrations/langchain.py +0 -0
  31. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/models.py +0 -0
  32. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/pricing/__init__.py +0 -0
  33. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/pricing/anthropic.yaml +0 -0
  34. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/pricing/bedrock.yaml +0 -0
  35. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/pricing/loader.py +0 -0
  36. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/pricing/openai.yaml +0 -0
  37. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/pricing/vertex.yaml +0 -0
  38. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/providers/__init__.py +0 -0
  39. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/providers/anthropic.py +0 -0
  40. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/providers/base.py +0 -0
  41. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/providers/bedrock.py +0 -0
  42. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/providers/openai.py +0 -0
  43. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/rate_limit.py +0 -0
  44. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/span.py +0 -0
  45. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/tokenizers/__init__.py +0 -0
  46. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/llm_cost_guard/tokenizers/base.py +0 -0
  47. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/__init__.py +0 -0
  48. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/conftest.py +0 -0
  49. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/integration/__init__.py +0 -0
  50. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/integration/test_e2e.py +0 -0
  51. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/unit/__init__.py +0 -0
  52. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/unit/test_backends.py +0 -0
  53. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/unit/test_budget.py +0 -0
  54. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/unit/test_pricing.py +0 -0
  55. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/unit/test_providers.py +0 -0
  56. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/unit/test_rate_limit.py +0 -0
  57. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/unit/test_span.py +0 -0
  58. {llm_cost_guard-0.1.1 → llm_cost_guard-0.2.0}/tests/unit/test_tracker.py +0 -0
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: llm-cost-guard
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Real-time cost tracking, budget enforcement, and usage analytics for LLM applications
5
5
  Project-URL: Homepage, https://github.com/prashantdudami/llm-cost-guard
6
6
  Project-URL: Documentation, https://github.com/prashantdudami/llm-cost-guard#readme
7
7
  Project-URL: Repository, https://github.com/prashantdudami/llm-cost-guard
8
8
  Project-URL: Issues, https://github.com/prashantdudami/llm-cost-guard/issues
9
+ Project-URL: Author, https://www.prashantdudami.com/
9
10
  Author-email: Prashant Dudami <prashant.dudami@gmail.com>
10
11
  License-Expression: MIT
11
12
  License-File: LICENSE
@@ -333,6 +334,57 @@ tracker = CostTracker(
333
334
  )
334
335
  ```
335
336
 
337
+ ## Audit Logging (v0.2.0+)
338
+
339
+ Enterprise-ready audit trails for compliance:
340
+
341
+ ```python
342
+ from llm_cost_guard import CostTracker, FileAuditBackend
343
+
344
+ # Enable audit logging
345
+ tracker = CostTracker(
346
+ audit_enabled=True,
347
+ audit_backend=FileAuditBackend("audit.log"),
348
+ )
349
+
350
+ # Query audit history
351
+ events = tracker.audit.query(
352
+ event_type=AuditEventType.BUDGET_EXCEEDED,
353
+ start_date="2024-01-01",
354
+ )
355
+
356
+ # Get budget-specific history
357
+ history = tracker.audit.get_budget_history("daily")
358
+ ```
359
+
360
+ Audit events include:
361
+ - Budget created/modified/deleted
362
+ - Budget warnings and exceeded events
363
+ - Rate limit exceeded events
364
+ - Tracking failures and fallback activations
365
+
366
+ ## Observability Metrics (v0.2.0+)
367
+
368
+ Track health and degradation:
369
+
370
+ ```python
371
+ # Get tracker metrics
372
+ metrics = tracker.get_metrics()
373
+ print(metrics)
374
+ # {
375
+ # "backend_failures": 0,
376
+ # "fallback_activations": 0,
377
+ # "budget_exceeded_count": 3,
378
+ # "tracking_errors": 0,
379
+ # "using_fallback": False,
380
+ # }
381
+
382
+ # Health check
383
+ health = tracker.health_check()
384
+ print(health.healthy) # True/False
385
+ print(health.errors) # List of issues
386
+ ```
387
+
336
388
  ## Custom Pricing
337
389
 
338
390
  For negotiated enterprise rates:
@@ -348,6 +400,30 @@ tracker = CostTracker(
348
400
  )
349
401
  ```
350
402
 
403
+ ## Current Limitations
404
+
405
+ Being transparent about what's not yet production-ready:
406
+
407
+ | Feature | Status | Notes |
408
+ |---------|--------|-------|
409
+ | Distributed budgets (Redis) | ✅ v0.2.0 | Atomic operations with Lua scripts |
410
+ | Audit logging | ✅ v0.2.0 | File and logging backends |
411
+ | Graceful degradation metrics | ✅ v0.2.0 | Track failures and fallbacks |
412
+ | PostgreSQL backend | 🚧 Planned | Use SQLite or Redis for now |
413
+ | DynamoDB backend | 🚧 Planned | Use SQLite or Redis for now |
414
+ | Encryption at rest | 🚧 Planned | Use encrypted volumes as workaround |
415
+ | Multi-tenancy optimization | 🚧 Planned | Use tag-scoped budgets for now |
416
+ | Streaming cost estimation | ⚠️ Limited | Actual cost tracked on completion |
417
+ | Fine-tuning cost tracking | ❌ Not supported | |
418
+
419
+ ### Recommended for Production
420
+
421
+ | Deployment Size | Backend | Notes |
422
+ |-----------------|---------|-------|
423
+ | Single instance | SQLite | Simple, no setup |
424
+ | Multiple instances | Redis | Distributed budget enforcement |
425
+ | High-volume (>1k req/s) | Redis | With sampling (coming soon) |
426
+
351
427
  ## Contributing
352
428
 
353
429
  Contributions are welcome! Please read our contributing guidelines and submit pull requests.
@@ -358,7 +434,7 @@ MIT License - see [LICENSE](LICENSE) for details.
358
434
 
359
435
  ## Author
360
436
 
361
- **Prashant Dudami**
437
+ **Prashant Dudami** - AI/ML Architect & LLM Infrastructure Expert
438
+ - Website: [prashantdudami.com](https://www.prashantdudami.com/)
362
439
  - LinkedIn: [linkedin.com/in/prashantdudami](https://www.linkedin.com/in/prashantdudami/)
363
440
  - GitHub: [github.com/prashantdudami](https://github.com/prashantdudami)
364
- - Email: prashant.dudami@gmail.com
@@ -271,6 +271,57 @@ tracker = CostTracker(
271
271
  )
272
272
  ```
273
273
 
274
+ ## Audit Logging (v0.2.0+)
275
+
276
+ Enterprise-ready audit trails for compliance:
277
+
278
+ ```python
279
+ from llm_cost_guard import CostTracker, FileAuditBackend
280
+
281
+ # Enable audit logging
282
+ tracker = CostTracker(
283
+ audit_enabled=True,
284
+ audit_backend=FileAuditBackend("audit.log"),
285
+ )
286
+
287
+ # Query audit history
288
+ events = tracker.audit.query(
289
+ event_type=AuditEventType.BUDGET_EXCEEDED,
290
+ start_date="2024-01-01",
291
+ )
292
+
293
+ # Get budget-specific history
294
+ history = tracker.audit.get_budget_history("daily")
295
+ ```
296
+
297
+ Audit events include:
298
+ - Budget created/modified/deleted
299
+ - Budget warnings and exceeded events
300
+ - Rate limit exceeded events
301
+ - Tracking failures and fallback activations
302
+
303
+ ## Observability Metrics (v0.2.0+)
304
+
305
+ Track health and degradation:
306
+
307
+ ```python
308
+ # Get tracker metrics
309
+ metrics = tracker.get_metrics()
310
+ print(metrics)
311
+ # {
312
+ # "backend_failures": 0,
313
+ # "fallback_activations": 0,
314
+ # "budget_exceeded_count": 3,
315
+ # "tracking_errors": 0,
316
+ # "using_fallback": False,
317
+ # }
318
+
319
+ # Health check
320
+ health = tracker.health_check()
321
+ print(health.healthy) # True/False
322
+ print(health.errors) # List of issues
323
+ ```
324
+
274
325
  ## Custom Pricing
275
326
 
276
327
  For negotiated enterprise rates:
@@ -286,6 +337,30 @@ tracker = CostTracker(
286
337
  )
287
338
  ```
288
339
 
340
+ ## Current Limitations
341
+
342
+ Being transparent about what's not yet production-ready:
343
+
344
+ | Feature | Status | Notes |
345
+ |---------|--------|-------|
346
+ | Distributed budgets (Redis) | ✅ v0.2.0 | Atomic operations with Lua scripts |
347
+ | Audit logging | ✅ v0.2.0 | File and logging backends |
348
+ | Graceful degradation metrics | ✅ v0.2.0 | Track failures and fallbacks |
349
+ | PostgreSQL backend | 🚧 Planned | Use SQLite or Redis for now |
350
+ | DynamoDB backend | 🚧 Planned | Use SQLite or Redis for now |
351
+ | Encryption at rest | 🚧 Planned | Use encrypted volumes as workaround |
352
+ | Multi-tenancy optimization | 🚧 Planned | Use tag-scoped budgets for now |
353
+ | Streaming cost estimation | ⚠️ Limited | Actual cost tracked on completion |
354
+ | Fine-tuning cost tracking | ❌ Not supported | |
355
+
356
+ ### Recommended for Production
357
+
358
+ | Deployment Size | Backend | Notes |
359
+ |-----------------|---------|-------|
360
+ | Single instance | SQLite | Simple, no setup |
361
+ | Multiple instances | Redis | Distributed budget enforcement |
362
+ | High-volume (>1k req/s) | Redis | With sampling (coming soon) |
363
+
289
364
  ## Contributing
290
365
 
291
366
  Contributions are welcome! Please read our contributing guidelines and submit pull requests.
@@ -296,7 +371,7 @@ MIT License - see [LICENSE](LICENSE) for details.
296
371
 
297
372
  ## Author
298
373
 
299
- **Prashant Dudami**
374
+ **Prashant Dudami** - AI/ML Architect & LLM Infrastructure Expert
375
+ - Website: [prashantdudami.com](https://www.prashantdudami.com/)
300
376
  - LinkedIn: [linkedin.com/in/prashantdudami](https://www.linkedin.com/in/prashantdudami/)
301
377
  - GitHub: [github.com/prashantdudami](https://github.com/prashantdudami)
302
- - Email: prashant.dudami@gmail.com
@@ -15,8 +15,16 @@ from llm_cost_guard.exceptions import (
15
15
  TrackingUnavailableError,
16
16
  RateLimitExceededError,
17
17
  )
18
+ from llm_cost_guard.audit import (
19
+ AuditLogger,
20
+ AuditBackend,
21
+ AuditEvent,
22
+ AuditEventType,
23
+ LoggingAuditBackend,
24
+ FileAuditBackend,
25
+ )
18
26
 
19
- __version__ = "0.1.0"
27
+ __version__ = "0.2.0"
20
28
 
21
29
  __all__ = [
22
30
  # Core
@@ -29,6 +37,13 @@ __all__ = [
29
37
  "CostRecord",
30
38
  "CostReport",
31
39
  "HealthStatus",
40
+ # Audit
41
+ "AuditLogger",
42
+ "AuditBackend",
43
+ "AuditEvent",
44
+ "AuditEventType",
45
+ "LoggingAuditBackend",
46
+ "FileAuditBackend",
32
47
  # Exceptions
33
48
  "LLMCostGuardError",
34
49
  "BudgetExceededError",