revenium-python-sdk 0.14.0__tar.gz → 0.15.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 (195) hide show
  1. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/PKG-INFO +21 -10
  2. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/README.md +19 -8
  3. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/pyproject.toml +5 -2
  4. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/__init__.py +4 -1
  5. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/cache_tokens.py +101 -27
  6. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/enforcement.py +502 -162
  7. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/job_type_economics.py +20 -0
  8. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/middleware.py +42 -1
  9. revenium_python_sdk-0.15.0/revenium_middleware/litellm/proxy/_health_check.py +50 -0
  10. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/proxy/guardrail.py +5 -1
  11. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/proxy/middleware.py +7 -0
  12. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_python_sdk.egg-info/PKG-INFO +21 -10
  13. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_python_sdk.egg-info/SOURCES.txt +1 -0
  14. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_python_sdk.egg-info/requires.txt +1 -1
  15. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/LICENSE +0 -0
  16. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/__init__.py +0 -0
  17. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/call_context.py +0 -0
  18. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/call_ownership.py +0 -0
  19. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/closable_scope.py +0 -0
  20. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/config.py +0 -0
  21. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/context.py +0 -0
  22. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/decorators.py +0 -0
  23. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/delivery_circuit.py +0 -0
  24. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/error_text.py +0 -0
  25. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/exceptions.py +0 -0
  26. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/failed_calls.py +0 -0
  27. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/fields.py +0 -0
  28. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/json_safe.py +0 -0
  29. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/langchain_settings.py +0 -0
  30. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/load_diagnostics.py +0 -0
  31. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/log_sanitize.py +0 -0
  32. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/metering.py +0 -0
  33. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/metering_buffer.py +0 -0
  34. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/metering_pool.py +0 -0
  35. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/metering_status.py +0 -0
  36. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/metering_submission.py +0 -0
  37. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/outcomes.py +0 -0
  38. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/package_versions.py +0 -0
  39. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/parse_failures.py +0 -0
  40. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/patch_registry.py +0 -0
  41. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/perplexity_cost.py +0 -0
  42. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/perplexity_usage_metadata.py +0 -0
  43. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/prompt_extraction.py +0 -0
  44. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/responses_status.py +0 -0
  45. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/secret_shapes.py +0 -0
  46. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/selective_metering.py +0 -0
  47. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/shutdown_signals.py +0 -0
  48. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/sse_body_tap.py +0 -0
  49. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/subscriber.py +0 -0
  50. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/tool_event_transport.py +0 -0
  51. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/trace_fields.py +0 -0
  52. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/usage_iterations.py +0 -0
  53. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/vendor_model_aliases.py +0 -0
  54. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/wire_guards.py +0 -0
  55. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/LICENSE +0 -0
  56. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/__init__.py +0 -0
  57. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_base_client.py +0 -0
  58. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_client.py +0 -0
  59. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_compat.py +0 -0
  60. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_constants.py +0 -0
  61. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_exceptions.py +0 -0
  62. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_files.py +0 -0
  63. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_models.py +0 -0
  64. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_qs.py +0 -0
  65. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_resource.py +0 -0
  66. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_response.py +0 -0
  67. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_streaming.py +0 -0
  68. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_types.py +0 -0
  69. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/__init__.py +0 -0
  70. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_logs.py +0 -0
  71. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_proxy.py +0 -0
  72. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_reflection.py +0 -0
  73. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_resources_proxy.py +0 -0
  74. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_streams.py +0 -0
  75. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_sync.py +0 -0
  76. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_transform.py +0 -0
  77. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_typing.py +0 -0
  78. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_utils.py +0 -0
  79. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_version.py +0 -0
  80. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/context.py +0 -0
  81. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/decorator.py +0 -0
  82. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/py.typed +0 -0
  83. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/resources/__init__.py +0 -0
  84. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/resources/ai.py +0 -0
  85. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/resources/apis.py +0 -0
  86. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/resources/events.py +0 -0
  87. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/__init__.py +0 -0
  88. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/ai_create_audio_params.py +0 -0
  89. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/ai_create_completion_params.py +0 -0
  90. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/ai_create_image_params.py +0 -0
  91. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/ai_create_video_params.py +0 -0
  92. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/api_meter_request_params.py +0 -0
  93. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/api_meter_response_params.py +0 -0
  94. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/event_create_params.py +0 -0
  95. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/metering_response_resource.py +0 -0
  96. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/agentic_outcomes.py +0 -0
  97. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/__init__.py +0 -0
  98. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/bedrock_adapter.py +0 -0
  99. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/bedrock_model_names.py +0 -0
  100. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/bedrock_transport.py +0 -0
  101. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/config.py +0 -0
  102. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/inference_profiles.py +0 -0
  103. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/middleware.py +0 -0
  104. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/prompt_extractor.py +0 -0
  105. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/provider.py +0 -0
  106. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/raw_response.py +0 -0
  107. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/stream_create.py +0 -0
  108. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/trace_fields.py +0 -0
  109. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/__init__.py +0 -0
  110. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/_call.py +0 -0
  111. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/_metering.py +0 -0
  112. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/_queue.py +0 -0
  113. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/config.py +0 -0
  114. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/middleware.py +0 -0
  115. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/trace_fields.py +0 -0
  116. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/__init__.py +0 -0
  117. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/__init__.py +0 -0
  118. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/exceptions.py +0 -0
  119. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/protocols.py +0 -0
  120. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/trace_fields.py +0 -0
  121. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/types.py +0 -0
  122. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/utils.py +0 -0
  123. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/config.py +0 -0
  124. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/google_ai/__init__.py +0 -0
  125. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/google_ai/middleware.py +0 -0
  126. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/google_ai/provider.py +0 -0
  127. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/prompt_extractor.py +0 -0
  128. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/vertex_ai/__init__.py +0 -0
  129. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/vertex_ai/middleware.py +0 -0
  130. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/vertex_ai/provider.py +0 -0
  131. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/__init__.py +0 -0
  132. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/_metadata.py +0 -0
  133. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/_retry.py +0 -0
  134. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/anthropic_driver.py +0 -0
  135. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/budget_errors.py +0 -0
  136. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/litellm_driver.py +0 -0
  137. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/ollama_driver.py +0 -0
  138. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/openai_driver.py +0 -0
  139. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/openai_embedding_driver.py +0 -0
  140. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/universal_driver.py +0 -0
  141. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/job_context.py +0 -0
  142. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/job_history.py +0 -0
  143. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/__init__.py +0 -0
  144. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/__init__.py +0 -0
  145. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/config.py +0 -0
  146. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/context.py +0 -0
  147. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/decorators.py +0 -0
  148. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/hooks.py +0 -0
  149. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/integrations/__init__.py +0 -0
  150. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/integrations/crewai.py +0 -0
  151. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/trace_fields.py +0 -0
  152. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/validation.py +0 -0
  153. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/proxy/__init__.py +0 -0
  154. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/proxy/_metering_owner.py +0 -0
  155. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/ollama/__init__.py +0 -0
  156. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/ollama/middleware.py +0 -0
  157. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/ollama/trace_fields.py +0 -0
  158. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/__init__.py +0 -0
  159. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/audio.py +0 -0
  160. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/azure_config.py +0 -0
  161. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/azure_model_resolver.py +0 -0
  162. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/config.py +0 -0
  163. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/exceptions.py +0 -0
  164. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/__init__.py +0 -0
  165. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_abandoned_runs.py +0 -0
  166. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_model_call.py +0 -0
  167. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_perplexity_cost_capture.py +0 -0
  168. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_prompt_capture.py +0 -0
  169. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_text_completion_usage.py +0 -0
  170. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_utils.py +0 -0
  171. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/unified_handler.py +0 -0
  172. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/middleware.py +0 -0
  173. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/prompt_extractor.py +0 -0
  174. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/provider.py +0 -0
  175. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/raw_response.py +0 -0
  176. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/trace_fields.py +0 -0
  177. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/xai_usage.py +0 -0
  178. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/__init__.py +0 -0
  179. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/_metering_scope.py +0 -0
  180. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/middleware.py +0 -0
  181. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/patching.py +0 -0
  182. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/perplexity_sdk.py +0 -0
  183. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/provider.py +0 -0
  184. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/raw_response.py +0 -0
  185. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/streaming.py +0 -0
  186. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/trace_fields.py +0 -0
  187. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/webhooks/__init__.py +0 -0
  188. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_middleware/webhooks/_verify.py +0 -0
  189. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_python_sdk.egg-info/dependency_links.txt +0 -0
  190. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/revenium_python_sdk.egg-info/top_level.txt +0 -0
  191. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/setup.cfg +0 -0
  192. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/tests/test_metering.py +0 -0
  193. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/tests/test_metering_dispatch_timestamps.py +0 -0
  194. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/tests/test_patch_coverage.py +0 -0
  195. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.15.0}/tests/test_release_verify_ticket.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: revenium-python-sdk
3
- Version: 0.14.0
3
+ Version: 0.15.0
4
4
  Summary: The official Revenium Python SDK — unified AI metering middleware for OpenAI, Anthropic, Google, Ollama, LiteLLM, Perplexity, and fal.ai.
5
5
  Author-email: Revenium <support@revenium.io>
6
6
  License: MIT
@@ -80,7 +80,7 @@ Requires-Dist: litellm>=1.40.0; extra == "litellm"
80
80
  Requires-Dist: python-dotenv>=0.19.0; extra == "litellm"
81
81
  Provides-Extra: litellm-proxy
82
82
  Requires-Dist: wrapt>=1.14.0; extra == "litellm-proxy"
83
- Requires-Dist: litellm[proxy]>=1.93.0; extra == "litellm-proxy"
83
+ Requires-Dist: litellm[proxy]>=1.94.0; extra == "litellm-proxy"
84
84
  Provides-Extra: dev
85
85
  Requires-Dist: pytest>=7.0.0; extra == "dev"
86
86
  Requires-Dist: pytest-asyncio; extra == "dev"
@@ -196,11 +196,11 @@ The calls below are billed by the provider (some, such as batch and fine-tuning
196
196
  <!-- not-metered:start -->
197
197
  - **OpenAI** (`OpenAI` and `AsyncOpenAI` clients): `batches.create`, `beta.agents.automations.create`, `beta.agents.automations.invocations.create`, `beta.agents.sessions.create`, `beta.agents.sessions.events.create`, `beta.agents.sessions.events.stream`, `beta.agents.sessions.stream`, `beta.agents.sessions.update`, `beta.chatkit.sessions.create`, `beta.realtime.connect`, `beta.responses.compact`, `beta.responses.connect`, `beta.responses.create`, `beta.threads.create_and_run`, `beta.threads.create_and_run_poll`, `beta.threads.create_and_run_stream`, `beta.threads.runs.create`, `beta.threads.runs.create_and_poll`, `beta.threads.runs.create_and_stream`, `beta.threads.runs.stream`, `beta.threads.runs.submit_tool_outputs`, `beta.threads.runs.submit_tool_outputs_and_poll`, `beta.threads.runs.submit_tool_outputs_stream`, `completions.create`, `decisions.create`, `evals.runs.create`, `fine_tuning.alpha.graders.run`, `fine_tuning.jobs.create`, `images.create_variation`, `images.edit`, `images.generate`, `live.connect`, `live.create`, `live.forks.connect`, `live.sessions.accept`, `live.sessions.fork`, `live.sideband.connect`, `realtime.calls.accept`, `realtime.calls.create`, `realtime.connect`, `realtime.translations.connect`, `responses.compact`, `responses.connect`, `videos.create`, `videos.create_and_poll`, `videos.create_character`, `videos.edit`, `videos.extend`, `videos.remix`
198
198
  - **Anthropic** (`Anthropic` and `AsyncAnthropic` clients): `beta.deployments.run`, `beta.dreams.create`, `beta.environments.work.poller`, `beta.environments.work.worker`, `beta.messages.batches.create`, `beta.sessions.create`, `beta.sessions.events.send`, `beta.sessions.events.stream`, `beta.sessions.events.tool_runner`, `beta.sessions.threads.events.stream`, `messages.batches.create`
199
- - **Google Gemini** (`google.genai` `Client` and `Client.aio`): `batches.create`, `batches.create_embeddings`, `caches.create`, `caches.update`, `file_search_stores.import_file`, `file_search_stores.upload_to_file_search_store`, `interactions.create`, `live.connect`, `live.music.connect`, `models.edit_image`, `models.recontext_image`, `models.segment_image`, `models.upscale_image`, `triggers.run`, `tunings.tune`
199
+ - **Google Gemini** (`google.genai` `Client` and `Client.aio`): `batches.create`, `batches.create_embeddings`, `caches.create`, `caches.update`, `decisions.create`, `file_search_stores.import_file`, `file_search_stores.upload_to_file_search_store`, `interactions.create`, `live.connect`, `live.music.connect`, `models.edit_image`, `models.recontext_image`, `models.segment_image`, `models.upscale_image`, `triggers.run`, `tunings.tune`
200
200
  - **Google Vertex AI** (`vertexai` classes): `batch_prediction.BatchPredictionJob.submit`, `caching.CachedContent.create`, `caching.CachedContent.update`, `language_models.ChatModel.tune_model`, `language_models.ChatModel.tune_model_rlhf`, `language_models.ChatSession.send_message`, `language_models.ChatSession.send_message_async`, `language_models.ChatSession.send_message_streaming`, `language_models.ChatSession.send_message_streaming_async`, `language_models.CodeChatModel.tune_model`, `language_models.CodeChatSession.send_message`, `language_models.CodeChatSession.send_message_async`, `language_models.CodeChatSession.send_message_streaming`, `language_models.CodeChatSession.send_message_streaming_async`, `language_models.CodeGenerationModel.batch_predict`, `language_models.CodeGenerationModel.predict`, `language_models.CodeGenerationModel.predict_async`, `language_models.CodeGenerationModel.predict_streaming`, `language_models.CodeGenerationModel.predict_streaming_async`, `language_models.CodeGenerationModel.tune_model`, `language_models.TextEmbeddingModel.batch_predict`, `language_models.TextEmbeddingModel.deploy_tuned_model`, `language_models.TextEmbeddingModel.tune_model`, `language_models.TextGenerationModel.batch_predict`, `language_models.TextGenerationModel.predict`, `language_models.TextGenerationModel.predict_async`, `language_models.TextGenerationModel.predict_streaming`, `language_models.TextGenerationModel.predict_streaming_async`, `language_models.TextGenerationModel.tune_model`, `language_models.TextGenerationModel.tune_model_rlhf`, `preview.caching.CachedContent.create`, `preview.caching.CachedContent.update`, `preview.vision_models.ImageCaptioningModel.get_captions`, `preview.vision_models.ImageGenerationModel.upscale_image`, `preview.vision_models.ImageQnAModel.ask_question`, `preview.vision_models.ImageSegmentationModel.segment_image`, `preview.vision_models.ImageTextModel.ask_question`, `preview.vision_models.ImageTextModel.get_captions`, `preview.vision_models.MultiModalEmbeddingModel.get_embeddings`, `preview.vision_models.WatermarkVerificationModel.verify_image`, `tuning.sft.train`, `vision_models.ImageCaptioningModel.get_captions`, `vision_models.ImageGenerationModel.upscale_image`, `vision_models.ImageQnAModel.ask_question`, `vision_models.ImageTextModel.ask_question`, `vision_models.ImageTextModel.get_captions`, `vision_models.MultiModalEmbeddingModel.get_embeddings`
201
201
  - **AWS Bedrock** (boto3 bedrock-runtime client; Claude models are metered when REVENIUM_BEDROCK_TRANSPORT is on): `apply_guardrail`, `converse`, `converse_stream`, `invoke_guardrail_checks`, `invoke_model`, `invoke_model_with_response_stream`, `start_async_invoke`
202
202
  - **Perplexity** (`Perplexity` and `AsyncPerplexity` clients): `async_.chat.completions.create`, `batches.create`, `browser.sessions.create`, `contextualized_embeddings.create`, `decisions.create`, `embeddings.create`, `responses.create`, `search.create`
203
- - **LiteLLM** (the `litellm` module): `aadapter_completion`, `aadapter_generate_content`, `acode_interpreter_tool`, `acompact_responses`, `acreate_batch`, `acreate_fine_tuning_job`, `acreate_run`, `acreate_sandbox`, `adapter_completion`, `adecisions`, `agenerate_content`, `aimage_edit`, `aimage_generation`, `aimage_variation`, `aingest`, `anthropic_interface.messages.acreate`, `anthropic_interface.messages.create`, `anthropic_messages`, `anthropic_messages_handler`, `aocr`, `aquery`, `arealtime_calls`, `arerank`, `aresponses`, `aresponses_api_with_mcp`, `aresponses_with_retries`, `arun_code`, `arun_thread`, `arun_thread_stream`, `asearch`, `aspeech`, `asystemone`, `atranscription`, `avideo_create_character`, `avideo_edit`, `avideo_extension`, `avideo_generation`, `avideo_remix`, `compact_responses`, `config_completion`, `create_batch`, `create_fine_tuning_job`, `create_run`, `decisions`, `image_edit`, `image_generation`, `image_variation`, `ingest`, `nlp_cloud_chat_completion`, `ocr`, `query`, `replicate_chat_completion`, `rerank`, `responses`, `responses_with_retries`, `run_thread`, `run_thread_stream`, `search`, `speech`, `systemone`, `transcription`, `video_create_character`, `video_edit`, `video_extension`, `video_generation`, `video_remix`
203
+ - **LiteLLM** (the `litellm` module): `aadapter_completion`, `aadapter_generate_content`, `acode_interpreter_tool`, `acompact_responses`, `acreate_batch`, `acreate_fine_tuning_job`, `acreate_run`, `acreate_sandbox`, `adapter_completion`, `adecisions`, `aextraction`, `agenerate_content`, `aimage_edit`, `aimage_generation`, `aimage_variation`, `aingest`, `anthropic_interface.messages.acreate`, `anthropic_interface.messages.create`, `anthropic_messages`, `anthropic_messages_handler`, `aocr`, `aquery`, `arealtime_calls`, `arerank`, `aresponses`, `aresponses_api_with_mcp`, `aresponses_with_retries`, `arun_code`, `arun_thread`, `arun_thread_stream`, `asearch`, `aspeech`, `asystemone`, `atranscription`, `avideo_create_character`, `avideo_edit`, `avideo_extension`, `avideo_generation`, `avideo_remix`, `compact_responses`, `config_completion`, `create_batch`, `create_fine_tuning_job`, `create_run`, `decisions`, `extraction`, `image_edit`, `image_generation`, `image_variation`, `ingest`, `nlp_cloud_chat_completion`, `ocr`, `query`, `replicate_chat_completion`, `rerank`, `responses`, `responses_with_retries`, `run_thread`, `run_thread_stream`, `search`, `speech`, `systemone`, `transcription`, `video_create_character`, `video_edit`, `video_extension`, `video_generation`, `video_remix`
204
204
  - **Ollama** (`Client`, `AsyncClient` and the `ollama` module): `systemone`, `web_fetch`, `web_search`
205
205
  - **fal.ai** (`SyncClient`, `AsyncClient` and the `fal_client` module): `realtime`, `realtime_async`, `ws_connect`, `ws_connect_async`
206
206
  - **LangChain** (embeddings models from vendors other than OpenAI, Azure OpenAI and Ollama, such as `MistralAIEmbeddings`): `Embeddings.aembed_documents`, `Embeddings.aembed_query`, `Embeddings.embed_documents`, `Embeddings.embed_query`
@@ -382,6 +382,13 @@ explicit override. Economics metric directions are
382
382
  Use `CUSTOMER_DECLARED` or `MEASURED` for a baseline override. Use `MEASURED`,
383
383
  `SELF_REPORTED`, or `DERIVED` for a period fact override.
384
384
 
385
+ A baseline can also record the work's throughput and headcount before AI:
386
+ `throughput_value` with a `throughput_period` of `HOUR`, `DAY`, `WEEK`, or
387
+ `MONTH`, an optional `throughput_scope` of `TEAM` (the default) or
388
+ `PER_PERSON`, and `headcount`. Send `throughput_period` whenever
389
+ `throughput_value` is set; the server rejects a period or scope without a
390
+ value.
391
+
385
392
  Facts are append-only and keyed on the period, dimension and metric key
386
393
  together. Re-appending that tuple supersedes the active fact, and the server
387
394
  requires `reason=` on the entry when it does.
@@ -1188,6 +1195,10 @@ except calls a spending cap refuses.
1188
1195
  pip install "revenium-python-sdk[litellm-proxy]" # requires Python 3.10+
1189
1196
  ```
1190
1197
 
1198
+ The extra requires **LiteLLM 1.94.0 or newer**. On LiteLLM 1.93.x the proxy cannot
1199
+ load the guardrail from the config below: it only looks for a module file beside
1200
+ `config.yaml` and stops with `Could not find module file`.
1201
+
1191
1202
  ```yaml
1192
1203
  guardrails:
1193
1204
  - guardrail_name: "revenium"
@@ -1235,7 +1246,7 @@ the call proceeds, and it proceeds without waiting. The pre-call check reads the
1235
1246
  rules the SDK already has cached and refreshes them on a background thread, so a
1236
1247
  Revenium endpoint that hangs, refuses connections, returns errors or rejects your
1237
1248
  key (403) neither blocks nor slows the proxy. A failed refresh is retried once
1238
- per `REVENIUM_CB_POLL_INTERVAL_SECONDS`, not once per request. Right after the
1249
+ per `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s), not once per request. Right after the
1239
1250
  proxy starts, before the first rules fetch completes, no rules are cached and
1240
1251
  calls go through; see [Fail-Open vs Fail-Closed](#fail-open-vs-fail-closed).
1241
1252
  Metering is likewise non-disruptive — nothing in the post-call path can turn a
@@ -1433,7 +1444,7 @@ Blank or unset means on; `true`, `1`, `yes`, `on` mean on; any other value turns
1433
1444
  New calls go straight back to two records when you do; records already merged stay
1434
1445
  merged. Four things have to be true for it to work:
1435
1446
 
1436
- * **LiteLLM 1.93.0 or newer.** That is the floor of the `litellm-proxy` extra, which
1447
+ * **LiteLLM 1.94.0 or newer.** That is the floor of the `litellm-proxy` extra, which
1437
1448
  is what installs the guardrail. On an older LiteLLM the guardrail logs one warning
1438
1449
  at startup and behaves exactly as it does when opted out: no header is added,
1439
1450
  the provider's response id is reported, and you get two records rather than none.
@@ -2390,7 +2401,7 @@ REVENIUM_ENFORCEMENT_BASE_URL=https://api.revenium.ai/profitstream # optional:
2390
2401
  | `REVENIUM_BYPASS` | `false` | When `true`, every `check_enforcement` call short-circuits to a no-op. Useful for incident response. |
2391
2402
  | `REVENIUM_TEAM_ID` | — | Hashed team ID. Path component on rule fetches; required when the breaker is enabled. |
2392
2403
  | `REVENIUM_ENFORCEMENT_BASE_URL` | `https://api.revenium.ai/profitstream` | Base URL for the enforcement API, taken as given. When unset it is the address outcomes and jobs use (`REVENIUM_PROFITSTREAM_BASE_URL`, else the Revenium address `REVENIUM_METERING_BASE_URL` or `initialize_metering(base_url=...)` sits under, without its `/meter` segment) plus `/profitstream`. A rules fetch that answers 404 is retried once at the same address with `/profitstream` removed, or added if it was missing, and the address that answers with rules is used from then on, so a self-hosted server that serves the API at the root, or a value set without `/profitstream`, still reaches the rules. |
2393
- | `REVENIUM_CB_POLL_INTERVAL_SECONDS` | `60` | Background poll interval for rule refreshes. |
2404
+ | `REVENIUM_CB_POLL_INTERVAL_SECONDS` | `30` | Seconds between background rule refreshes, and the wait before a failed refresh is retried. Whole seconds from a minimum of `5` to a maximum of `3600`: a lower value is raised to `5` with one warning per process start, and a higher one is capped at `3600`. Anything other than plain digits after trimming spaces (a sign, a decimal point, other text), an empty value and `0` use the default. Read once when polling starts, so a change takes effect when the process restarts. While calls are arriving, rules older than 120 seconds are refreshed on the next call whatever the interval, so a value above `120` only spaces out refreshes on an idle process and the retry after a failed refresh. |
2394
2405
  | `REVENIUM_CB_FAIL_MODE` | `open` | `open` (default) lets calls through when no cache exists; `closed` raises `BudgetExceededError` until rules are loaded. |
2395
2406
  | `REVENIUM_CACHE_DIR` | unset | When set, the rule cache is mirrored to `<dir>/revenium_enforcement_rules.<scope>.json` so a restarted process doesn't fail-closed on the very first call. `<scope>` is a short hash of the enforcement base URL and `REVENIUM_TEAM_ID`, so services for different teams can share one folder and each loads only its own rules. Nothing is saved without `REVENIUM_TEAM_ID`. |
2396
2407
 
@@ -2423,9 +2434,9 @@ LangChain embeddings models run no callbacks: `OpenAIEmbeddings` and `AzureOpenA
2423
2434
  When the circuit breaker is disabled, it is a no-op. When enabled:
2424
2435
 
2425
2436
  1. A daemon thread (`revenium-enforcement-poll`) starts on first use.
2426
- 2. It polls `GET {REVENIUM_ENFORCEMENT_BASE_URL}/v2/api/ai/enforcement-rules/{REVENIUM_TEAM_ID}` every `REVENIUM_CB_POLL_INTERVAL_SECONDS` with the `x-api-key` header.
2437
+ 2. It polls `GET {REVENIUM_ENFORCEMENT_BASE_URL}/v2/api/ai/enforcement-rules/{REVENIUM_TEAM_ID}` every `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s) with the `x-api-key` header.
2427
2438
  3. Rules are cached in-process. The pre-call check only reads that cache: it never makes a network request and never sleeps, so it is safe on an event loop (LiteLLM proxy, `AsyncOpenAI`). When the cache is more than 120 s old the check wakes the poller to refresh it early and carries on with the rules it has. Only one refresh runs at a time per process.
2428
- 4. A refresh that fails (timeout, refused connection, 5xx, or any 4xx such as a 403 for a wrong key or team id) keeps the cached rules, logs a warning, and is not retried for one `REVENIUM_CB_POLL_INTERVAL_SECONDS`, however much traffic arrives meanwhile. A 4xx answer the SDK does not retry (any but 408 and 429) is logged at WARNING with the URL and the status, so a wrong address (404) or a wrong key or team id (401, 403) is visible without debug logging.
2439
+ 4. A refresh that fails (timeout, refused connection, 5xx, or any 4xx such as a 403 for a wrong key or team id) keeps the cached rules, logs a warning, and is not retried for one `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s), however much traffic arrives meanwhile. A 4xx answer the SDK does not retry (any but 408 and 429) is logged at WARNING with the URL and the status, so a wrong address (404) or a wrong key or team id (401, 403) is visible without debug logging.
2429
2440
  5. `204 No Content` is treated as "no rules configured" — the cache is cleared.
2430
2441
 
2431
2442
  A rule with filters (a cap scoped to an agent, model, provider, subscriber, credential, task type, product or organization) blocks or warns only the calls that match all of them; a filter the SDK cannot evaluate, such as the model of a LiteLLM proxy request, keeps the rule applying.
@@ -2533,7 +2544,7 @@ for budget in budgets or []:
2533
2544
 
2534
2545
  Each row has `source` `ANOMALY` and `action` `NOTIFY`, groups by `SUBSCRIBER` with a per-person `groupBreakdown`, and carries `readingAt` when the current window has a reading. The call returns `[]` when the team has no advisory budgets and `None` when the enforcement API cannot be reached.
2535
2546
 
2536
- The background poller is unaffected: it keeps reading the **whole team's** rules every `REVENIUM_CB_POLL_INTERVAL_SECONDS`. That is deliberate. The server computes the department-budget maps team-wide and attaches them to the team-wide read, so a poll narrowed to a single rule would stop receiving them and department budgets would quietly stop blocking anyone. Narrowing is an explicit, opt-in inspection call and never the refresh.
2547
+ The background poller is unaffected: it keeps reading the **whole team's** rules every `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s). That is deliberate. The server computes the department-budget maps team-wide and attaches them to the team-wide read, so a poll narrowed to a single rule would stop receiving them and department budgets would quietly stop blocking anyone. Narrowing is an explicit, opt-in inspection call and never the refresh.
2537
2548
 
2538
2549
  ### End-to-End Example
2539
2550
 
@@ -80,11 +80,11 @@ The calls below are billed by the provider (some, such as batch and fine-tuning
80
80
  <!-- not-metered:start -->
81
81
  - **OpenAI** (`OpenAI` and `AsyncOpenAI` clients): `batches.create`, `beta.agents.automations.create`, `beta.agents.automations.invocations.create`, `beta.agents.sessions.create`, `beta.agents.sessions.events.create`, `beta.agents.sessions.events.stream`, `beta.agents.sessions.stream`, `beta.agents.sessions.update`, `beta.chatkit.sessions.create`, `beta.realtime.connect`, `beta.responses.compact`, `beta.responses.connect`, `beta.responses.create`, `beta.threads.create_and_run`, `beta.threads.create_and_run_poll`, `beta.threads.create_and_run_stream`, `beta.threads.runs.create`, `beta.threads.runs.create_and_poll`, `beta.threads.runs.create_and_stream`, `beta.threads.runs.stream`, `beta.threads.runs.submit_tool_outputs`, `beta.threads.runs.submit_tool_outputs_and_poll`, `beta.threads.runs.submit_tool_outputs_stream`, `completions.create`, `decisions.create`, `evals.runs.create`, `fine_tuning.alpha.graders.run`, `fine_tuning.jobs.create`, `images.create_variation`, `images.edit`, `images.generate`, `live.connect`, `live.create`, `live.forks.connect`, `live.sessions.accept`, `live.sessions.fork`, `live.sideband.connect`, `realtime.calls.accept`, `realtime.calls.create`, `realtime.connect`, `realtime.translations.connect`, `responses.compact`, `responses.connect`, `videos.create`, `videos.create_and_poll`, `videos.create_character`, `videos.edit`, `videos.extend`, `videos.remix`
82
82
  - **Anthropic** (`Anthropic` and `AsyncAnthropic` clients): `beta.deployments.run`, `beta.dreams.create`, `beta.environments.work.poller`, `beta.environments.work.worker`, `beta.messages.batches.create`, `beta.sessions.create`, `beta.sessions.events.send`, `beta.sessions.events.stream`, `beta.sessions.events.tool_runner`, `beta.sessions.threads.events.stream`, `messages.batches.create`
83
- - **Google Gemini** (`google.genai` `Client` and `Client.aio`): `batches.create`, `batches.create_embeddings`, `caches.create`, `caches.update`, `file_search_stores.import_file`, `file_search_stores.upload_to_file_search_store`, `interactions.create`, `live.connect`, `live.music.connect`, `models.edit_image`, `models.recontext_image`, `models.segment_image`, `models.upscale_image`, `triggers.run`, `tunings.tune`
83
+ - **Google Gemini** (`google.genai` `Client` and `Client.aio`): `batches.create`, `batches.create_embeddings`, `caches.create`, `caches.update`, `decisions.create`, `file_search_stores.import_file`, `file_search_stores.upload_to_file_search_store`, `interactions.create`, `live.connect`, `live.music.connect`, `models.edit_image`, `models.recontext_image`, `models.segment_image`, `models.upscale_image`, `triggers.run`, `tunings.tune`
84
84
  - **Google Vertex AI** (`vertexai` classes): `batch_prediction.BatchPredictionJob.submit`, `caching.CachedContent.create`, `caching.CachedContent.update`, `language_models.ChatModel.tune_model`, `language_models.ChatModel.tune_model_rlhf`, `language_models.ChatSession.send_message`, `language_models.ChatSession.send_message_async`, `language_models.ChatSession.send_message_streaming`, `language_models.ChatSession.send_message_streaming_async`, `language_models.CodeChatModel.tune_model`, `language_models.CodeChatSession.send_message`, `language_models.CodeChatSession.send_message_async`, `language_models.CodeChatSession.send_message_streaming`, `language_models.CodeChatSession.send_message_streaming_async`, `language_models.CodeGenerationModel.batch_predict`, `language_models.CodeGenerationModel.predict`, `language_models.CodeGenerationModel.predict_async`, `language_models.CodeGenerationModel.predict_streaming`, `language_models.CodeGenerationModel.predict_streaming_async`, `language_models.CodeGenerationModel.tune_model`, `language_models.TextEmbeddingModel.batch_predict`, `language_models.TextEmbeddingModel.deploy_tuned_model`, `language_models.TextEmbeddingModel.tune_model`, `language_models.TextGenerationModel.batch_predict`, `language_models.TextGenerationModel.predict`, `language_models.TextGenerationModel.predict_async`, `language_models.TextGenerationModel.predict_streaming`, `language_models.TextGenerationModel.predict_streaming_async`, `language_models.TextGenerationModel.tune_model`, `language_models.TextGenerationModel.tune_model_rlhf`, `preview.caching.CachedContent.create`, `preview.caching.CachedContent.update`, `preview.vision_models.ImageCaptioningModel.get_captions`, `preview.vision_models.ImageGenerationModel.upscale_image`, `preview.vision_models.ImageQnAModel.ask_question`, `preview.vision_models.ImageSegmentationModel.segment_image`, `preview.vision_models.ImageTextModel.ask_question`, `preview.vision_models.ImageTextModel.get_captions`, `preview.vision_models.MultiModalEmbeddingModel.get_embeddings`, `preview.vision_models.WatermarkVerificationModel.verify_image`, `tuning.sft.train`, `vision_models.ImageCaptioningModel.get_captions`, `vision_models.ImageGenerationModel.upscale_image`, `vision_models.ImageQnAModel.ask_question`, `vision_models.ImageTextModel.ask_question`, `vision_models.ImageTextModel.get_captions`, `vision_models.MultiModalEmbeddingModel.get_embeddings`
85
85
  - **AWS Bedrock** (boto3 bedrock-runtime client; Claude models are metered when REVENIUM_BEDROCK_TRANSPORT is on): `apply_guardrail`, `converse`, `converse_stream`, `invoke_guardrail_checks`, `invoke_model`, `invoke_model_with_response_stream`, `start_async_invoke`
86
86
  - **Perplexity** (`Perplexity` and `AsyncPerplexity` clients): `async_.chat.completions.create`, `batches.create`, `browser.sessions.create`, `contextualized_embeddings.create`, `decisions.create`, `embeddings.create`, `responses.create`, `search.create`
87
- - **LiteLLM** (the `litellm` module): `aadapter_completion`, `aadapter_generate_content`, `acode_interpreter_tool`, `acompact_responses`, `acreate_batch`, `acreate_fine_tuning_job`, `acreate_run`, `acreate_sandbox`, `adapter_completion`, `adecisions`, `agenerate_content`, `aimage_edit`, `aimage_generation`, `aimage_variation`, `aingest`, `anthropic_interface.messages.acreate`, `anthropic_interface.messages.create`, `anthropic_messages`, `anthropic_messages_handler`, `aocr`, `aquery`, `arealtime_calls`, `arerank`, `aresponses`, `aresponses_api_with_mcp`, `aresponses_with_retries`, `arun_code`, `arun_thread`, `arun_thread_stream`, `asearch`, `aspeech`, `asystemone`, `atranscription`, `avideo_create_character`, `avideo_edit`, `avideo_extension`, `avideo_generation`, `avideo_remix`, `compact_responses`, `config_completion`, `create_batch`, `create_fine_tuning_job`, `create_run`, `decisions`, `image_edit`, `image_generation`, `image_variation`, `ingest`, `nlp_cloud_chat_completion`, `ocr`, `query`, `replicate_chat_completion`, `rerank`, `responses`, `responses_with_retries`, `run_thread`, `run_thread_stream`, `search`, `speech`, `systemone`, `transcription`, `video_create_character`, `video_edit`, `video_extension`, `video_generation`, `video_remix`
87
+ - **LiteLLM** (the `litellm` module): `aadapter_completion`, `aadapter_generate_content`, `acode_interpreter_tool`, `acompact_responses`, `acreate_batch`, `acreate_fine_tuning_job`, `acreate_run`, `acreate_sandbox`, `adapter_completion`, `adecisions`, `aextraction`, `agenerate_content`, `aimage_edit`, `aimage_generation`, `aimage_variation`, `aingest`, `anthropic_interface.messages.acreate`, `anthropic_interface.messages.create`, `anthropic_messages`, `anthropic_messages_handler`, `aocr`, `aquery`, `arealtime_calls`, `arerank`, `aresponses`, `aresponses_api_with_mcp`, `aresponses_with_retries`, `arun_code`, `arun_thread`, `arun_thread_stream`, `asearch`, `aspeech`, `asystemone`, `atranscription`, `avideo_create_character`, `avideo_edit`, `avideo_extension`, `avideo_generation`, `avideo_remix`, `compact_responses`, `config_completion`, `create_batch`, `create_fine_tuning_job`, `create_run`, `decisions`, `extraction`, `image_edit`, `image_generation`, `image_variation`, `ingest`, `nlp_cloud_chat_completion`, `ocr`, `query`, `replicate_chat_completion`, `rerank`, `responses`, `responses_with_retries`, `run_thread`, `run_thread_stream`, `search`, `speech`, `systemone`, `transcription`, `video_create_character`, `video_edit`, `video_extension`, `video_generation`, `video_remix`
88
88
  - **Ollama** (`Client`, `AsyncClient` and the `ollama` module): `systemone`, `web_fetch`, `web_search`
89
89
  - **fal.ai** (`SyncClient`, `AsyncClient` and the `fal_client` module): `realtime`, `realtime_async`, `ws_connect`, `ws_connect_async`
90
90
  - **LangChain** (embeddings models from vendors other than OpenAI, Azure OpenAI and Ollama, such as `MistralAIEmbeddings`): `Embeddings.aembed_documents`, `Embeddings.aembed_query`, `Embeddings.embed_documents`, `Embeddings.embed_query`
@@ -266,6 +266,13 @@ explicit override. Economics metric directions are
266
266
  Use `CUSTOMER_DECLARED` or `MEASURED` for a baseline override. Use `MEASURED`,
267
267
  `SELF_REPORTED`, or `DERIVED` for a period fact override.
268
268
 
269
+ A baseline can also record the work's throughput and headcount before AI:
270
+ `throughput_value` with a `throughput_period` of `HOUR`, `DAY`, `WEEK`, or
271
+ `MONTH`, an optional `throughput_scope` of `TEAM` (the default) or
272
+ `PER_PERSON`, and `headcount`. Send `throughput_period` whenever
273
+ `throughput_value` is set; the server rejects a period or scope without a
274
+ value.
275
+
269
276
  Facts are append-only and keyed on the period, dimension and metric key
270
277
  together. Re-appending that tuple supersedes the active fact, and the server
271
278
  requires `reason=` on the entry when it does.
@@ -1072,6 +1079,10 @@ except calls a spending cap refuses.
1072
1079
  pip install "revenium-python-sdk[litellm-proxy]" # requires Python 3.10+
1073
1080
  ```
1074
1081
 
1082
+ The extra requires **LiteLLM 1.94.0 or newer**. On LiteLLM 1.93.x the proxy cannot
1083
+ load the guardrail from the config below: it only looks for a module file beside
1084
+ `config.yaml` and stops with `Could not find module file`.
1085
+
1075
1086
  ```yaml
1076
1087
  guardrails:
1077
1088
  - guardrail_name: "revenium"
@@ -1119,7 +1130,7 @@ the call proceeds, and it proceeds without waiting. The pre-call check reads the
1119
1130
  rules the SDK already has cached and refreshes them on a background thread, so a
1120
1131
  Revenium endpoint that hangs, refuses connections, returns errors or rejects your
1121
1132
  key (403) neither blocks nor slows the proxy. A failed refresh is retried once
1122
- per `REVENIUM_CB_POLL_INTERVAL_SECONDS`, not once per request. Right after the
1133
+ per `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s), not once per request. Right after the
1123
1134
  proxy starts, before the first rules fetch completes, no rules are cached and
1124
1135
  calls go through; see [Fail-Open vs Fail-Closed](#fail-open-vs-fail-closed).
1125
1136
  Metering is likewise non-disruptive — nothing in the post-call path can turn a
@@ -1317,7 +1328,7 @@ Blank or unset means on; `true`, `1`, `yes`, `on` mean on; any other value turns
1317
1328
  New calls go straight back to two records when you do; records already merged stay
1318
1329
  merged. Four things have to be true for it to work:
1319
1330
 
1320
- * **LiteLLM 1.93.0 or newer.** That is the floor of the `litellm-proxy` extra, which
1331
+ * **LiteLLM 1.94.0 or newer.** That is the floor of the `litellm-proxy` extra, which
1321
1332
  is what installs the guardrail. On an older LiteLLM the guardrail logs one warning
1322
1333
  at startup and behaves exactly as it does when opted out: no header is added,
1323
1334
  the provider's response id is reported, and you get two records rather than none.
@@ -2274,7 +2285,7 @@ REVENIUM_ENFORCEMENT_BASE_URL=https://api.revenium.ai/profitstream # optional:
2274
2285
  | `REVENIUM_BYPASS` | `false` | When `true`, every `check_enforcement` call short-circuits to a no-op. Useful for incident response. |
2275
2286
  | `REVENIUM_TEAM_ID` | — | Hashed team ID. Path component on rule fetches; required when the breaker is enabled. |
2276
2287
  | `REVENIUM_ENFORCEMENT_BASE_URL` | `https://api.revenium.ai/profitstream` | Base URL for the enforcement API, taken as given. When unset it is the address outcomes and jobs use (`REVENIUM_PROFITSTREAM_BASE_URL`, else the Revenium address `REVENIUM_METERING_BASE_URL` or `initialize_metering(base_url=...)` sits under, without its `/meter` segment) plus `/profitstream`. A rules fetch that answers 404 is retried once at the same address with `/profitstream` removed, or added if it was missing, and the address that answers with rules is used from then on, so a self-hosted server that serves the API at the root, or a value set without `/profitstream`, still reaches the rules. |
2277
- | `REVENIUM_CB_POLL_INTERVAL_SECONDS` | `60` | Background poll interval for rule refreshes. |
2288
+ | `REVENIUM_CB_POLL_INTERVAL_SECONDS` | `30` | Seconds between background rule refreshes, and the wait before a failed refresh is retried. Whole seconds from a minimum of `5` to a maximum of `3600`: a lower value is raised to `5` with one warning per process start, and a higher one is capped at `3600`. Anything other than plain digits after trimming spaces (a sign, a decimal point, other text), an empty value and `0` use the default. Read once when polling starts, so a change takes effect when the process restarts. While calls are arriving, rules older than 120 seconds are refreshed on the next call whatever the interval, so a value above `120` only spaces out refreshes on an idle process and the retry after a failed refresh. |
2278
2289
  | `REVENIUM_CB_FAIL_MODE` | `open` | `open` (default) lets calls through when no cache exists; `closed` raises `BudgetExceededError` until rules are loaded. |
2279
2290
  | `REVENIUM_CACHE_DIR` | unset | When set, the rule cache is mirrored to `<dir>/revenium_enforcement_rules.<scope>.json` so a restarted process doesn't fail-closed on the very first call. `<scope>` is a short hash of the enforcement base URL and `REVENIUM_TEAM_ID`, so services for different teams can share one folder and each loads only its own rules. Nothing is saved without `REVENIUM_TEAM_ID`. |
2280
2291
 
@@ -2307,9 +2318,9 @@ LangChain embeddings models run no callbacks: `OpenAIEmbeddings` and `AzureOpenA
2307
2318
  When the circuit breaker is disabled, it is a no-op. When enabled:
2308
2319
 
2309
2320
  1. A daemon thread (`revenium-enforcement-poll`) starts on first use.
2310
- 2. It polls `GET {REVENIUM_ENFORCEMENT_BASE_URL}/v2/api/ai/enforcement-rules/{REVENIUM_TEAM_ID}` every `REVENIUM_CB_POLL_INTERVAL_SECONDS` with the `x-api-key` header.
2321
+ 2. It polls `GET {REVENIUM_ENFORCEMENT_BASE_URL}/v2/api/ai/enforcement-rules/{REVENIUM_TEAM_ID}` every `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s) with the `x-api-key` header.
2311
2322
  3. Rules are cached in-process. The pre-call check only reads that cache: it never makes a network request and never sleeps, so it is safe on an event loop (LiteLLM proxy, `AsyncOpenAI`). When the cache is more than 120 s old the check wakes the poller to refresh it early and carries on with the rules it has. Only one refresh runs at a time per process.
2312
- 4. A refresh that fails (timeout, refused connection, 5xx, or any 4xx such as a 403 for a wrong key or team id) keeps the cached rules, logs a warning, and is not retried for one `REVENIUM_CB_POLL_INTERVAL_SECONDS`, however much traffic arrives meanwhile. A 4xx answer the SDK does not retry (any but 408 and 429) is logged at WARNING with the URL and the status, so a wrong address (404) or a wrong key or team id (401, 403) is visible without debug logging.
2323
+ 4. A refresh that fails (timeout, refused connection, 5xx, or any 4xx such as a 403 for a wrong key or team id) keeps the cached rules, logs a warning, and is not retried for one `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s), however much traffic arrives meanwhile. A 4xx answer the SDK does not retry (any but 408 and 429) is logged at WARNING with the URL and the status, so a wrong address (404) or a wrong key or team id (401, 403) is visible without debug logging.
2313
2324
  5. `204 No Content` is treated as "no rules configured" — the cache is cleared.
2314
2325
 
2315
2326
  A rule with filters (a cap scoped to an agent, model, provider, subscriber, credential, task type, product or organization) blocks or warns only the calls that match all of them; a filter the SDK cannot evaluate, such as the model of a LiteLLM proxy request, keeps the rule applying.
@@ -2417,7 +2428,7 @@ for budget in budgets or []:
2417
2428
 
2418
2429
  Each row has `source` `ANOMALY` and `action` `NOTIFY`, groups by `SUBSCRIBER` with a per-person `groupBreakdown`, and carries `readingAt` when the current window has a reading. The call returns `[]` when the team has no advisory budgets and `None` when the enforcement API cannot be reached.
2419
2430
 
2420
- The background poller is unaffected: it keeps reading the **whole team's** rules every `REVENIUM_CB_POLL_INTERVAL_SECONDS`. That is deliberate. The server computes the department-budget maps team-wide and attaches them to the team-wide read, so a poll narrowed to a single rule would stop receiving them and department budgets would quietly stop blocking anyone. Narrowing is an explicit, opt-in inspection call and never the refresh.
2431
+ The background poller is unaffected: it keeps reading the **whole team's** rules every `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s). That is deliberate. The server computes the department-budget maps team-wide and attaches them to the team-wide read, so a poll narrowed to a single rule would stop receiving them and department budgets would quietly stop blocking anyone. Narrowing is an explicit, opt-in inspection call and never the refresh.
2421
2432
 
2422
2433
  ### End-to-End Example
2423
2434
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "revenium-python-sdk"
7
- version = "0.14.0"
7
+ version = "0.15.0"
8
8
  description = "The official Revenium Python SDK — unified AI metering middleware for OpenAI, Anthropic, Google, Ollama, LiteLLM, Perplexity, and fal.ai."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -110,9 +110,12 @@ litellm = [
110
110
  # dispatch that meters streamed calls. litellm[proxy] itself requires Python
111
111
  # 3.10+, which is why revenium_middleware.litellm.proxy.guardrail carries an
112
112
  # import guard for it while the rest of the SDK stays on requires-python >=3.8.
113
+ # 1.94.0 is the first LiteLLM whose config loader (get_instance_fn) imports an
114
+ # installed package: 1.93.x only loads a module file sitting beside config.yaml,
115
+ # so the README's guardrail entry cannot load there.
113
116
  litellm-proxy = [
114
117
  "wrapt>=1.14.0",
115
- "litellm[proxy]>=1.93.0",
118
+ "litellm[proxy]>=1.94.0",
116
119
  ]
117
120
 
118
121
  dev = [
@@ -213,7 +213,8 @@ from .job_history import ( # noqa: E402
213
213
  get_job_transactions, get_job_types, get_outcome_history, list_jobs,
214
214
  )
215
215
  from .job_type_economics import ( # noqa: E402
216
- Baseline, BaselineProvenance, JobTypeEconomics, JobTypeMetricDirection,
216
+ Baseline, BaselineProvenance, BaselineThroughputPeriod,
217
+ BaselineThroughputScope, JobTypeEconomics, JobTypeMetricDirection,
217
218
  JobTypeMonetizationBasis, JobTypeMonetizationCategory,
218
219
  OutcomeMetricProvenance, PeriodFactEntry,
219
220
  create_baseline, get_job_type_economics, list_baselines,
@@ -293,6 +294,8 @@ __all__ = [
293
294
  "PeriodFactEntry",
294
295
  "Baseline",
295
296
  "BaselineProvenance",
297
+ "BaselineThroughputPeriod",
298
+ "BaselineThroughputScope",
296
299
  "JobTypeEconomics",
297
300
  "JobTypeMetricDirection",
298
301
  "JobTypeMonetizationBasis",
@@ -13,8 +13,9 @@ fields recurring across multiple emitters) and BACK-1925 for the LiteLLM
13
13
  client's cache-token contract, which this module's defaults must not break.
14
14
  """
15
15
  import logging
16
+ import threading
16
17
  from numbers import Number
17
- from typing import Any, Dict, NamedTuple, Optional
18
+ from typing import Any, Dict, NamedTuple, Optional, Tuple
18
19
 
19
20
  from revenium_middleware._core.package_versions import installed_version, release_of
20
21
 
@@ -123,8 +124,8 @@ def billable_input_tokens(
123
124
  (Anthropic's own ``input_tokens`` spelling reports the cache buckets beside
124
125
  it and never reaches this function.)
125
126
 
126
- Getting that scope wrong costs money in both directions. Left folded for an
127
- Anthropic response, the cache tokens are priced once at the input rate and
127
+ Getting that scope wrong costs money in both directions. Left folded for a
128
+ response whose cache LiteLLM counted inside the prompt, the cache tokens are priced once at the input rate and
128
129
  again in ``cache_read_token_count`` / ``cache_creation_token_count``, which
129
130
  is the 4.5x this fix exists for (BACK-3334). Taken out for an OpenAI-shaped
130
131
  provider, they are taken out twice: hypercurrent's
@@ -138,8 +139,10 @@ def billable_input_tokens(
138
139
  overlap itself, exactly once per record: here for the LiteLLM rows (client
139
140
  and gateway), for direct Anthropic and for Claude on Bedrock or Vertex AI,
140
141
  and through ``prompt_folds_claude_cache`` for the OpenAI client's records
141
- of a gateway serving Claude. Every other model's prompt count is reported
142
- exactly as LiteLLM built it.
142
+ of a gateway serving Claude. On Bedrock the cache is also removed for every
143
+ call whose usage LiteLLM built with a conversion that counts it inside the
144
+ prompt, whatever the model is called (``prompt_tokens_fold_cache``). Every
145
+ other model's prompt count is reported exactly as LiteLLM built it.
143
146
 
144
147
  A count that comes out negative contradicts the cache counts reported
145
148
  beside it, so it is reported unchanged and said out loud rather than
@@ -163,17 +166,19 @@ ANTHROPIC_MESSAGES_CALL_TYPE = "anthropic_messages"
163
166
 
164
167
  # LiteLLM ``custom_llm_provider`` values whose usage conversion folds the cache
165
168
  # buckets into ``prompt_tokens`` *and* whose rows the platform stores as sent.
166
- # Claude's Anthropic-shaped usage is the one usage shape Revenium never
167
- # normalizes server-side (see billable_input_tokens), so it is the only overlap
168
- # this row may remove: here for direct Anthropic, and in
169
- # ``_CLAUDE_HOSTING_PROVIDERS`` for Claude on Bedrock and Vertex AI.
169
+ # Anthropic-shaped usage is the one usage shape Revenium never normalizes
170
+ # server-side (see billable_input_tokens), so it is the only overlap this row
171
+ # may remove: here for direct Anthropic, and in ``_CLAUDE_HOSTING_PROVIDERS``
172
+ # for Claude on Bedrock and Vertex AI, plus the Bedrock conversions that build
173
+ # the same shape whatever the model is named.
170
174
  _CACHE_FOLDING_PROVIDERS = frozenset({"anthropic", "anthropic_text"})
171
175
 
172
- # Providers that fold the same way when the model they serve is Claude:
173
- # LiteLLM's Bedrock Converse, invoke and mantle routes and its Vertex AI Claude
174
- # route all build ``prompt_tokens`` as uncached input plus cache read plus cache
175
- # write. Gemini on Vertex AI is reported gross by Google and netted by the
176
- # platform, and Nova on Bedrock is left as LiteLLM built it.
176
+ # Providers that fold the same way when the model they serve is Claude, or, on
177
+ # Bedrock, when LiteLLM's own routing picked a conversion that folds: its Vertex
178
+ # AI Claude route and its Bedrock Converse, invoke-Nova and invoke-Anthropic
179
+ # conversions all build ``prompt_tokens`` as uncached input plus cache read plus
180
+ # cache write. Gemini on Vertex AI is reported gross by Google and netted by the
181
+ # platform.
177
182
  _CLAUDE_HOSTING_PROVIDERS = frozenset({"bedrock", "vertex_ai"})
178
183
 
179
184
  # Only the top-level fields LiteLLM fills with the deployment it called.
@@ -250,7 +255,14 @@ def upstream_provider(*sources) -> Optional[str]:
250
255
  def _provider_folds_cache(provider: str, sources) -> bool:
251
256
  if provider in _CACHE_FOLDING_PROVIDERS:
252
257
  return True
253
- return provider in _CLAUDE_HOSTING_PROVIDERS and names_claude_model(_first_named_model(sources))
258
+ if provider not in _CLAUDE_HOSTING_PROVIDERS:
259
+ return False
260
+ model = _first_named_model(sources)
261
+ if names_claude_model(model):
262
+ return True
263
+ if provider == "bedrock" and model:
264
+ return _bedrock_usage_folds_cache(str(model))
265
+ return False
254
266
 
255
267
 
256
268
  def prompt_tokens_fold_cache(*sources):
@@ -281,13 +293,16 @@ def prompt_tokens_fold_cache(*sources):
281
293
  LiteLLM only ever serves from an Anthropic-shaped upstream, and covers a
282
294
  surface carrying the call type but no provider.
283
295
 
284
- On ``bedrock`` and ``vertex_ai`` the model decides as well: Claude there is
285
- folded like Anthropic (BACK-4162), anything else is not. The model is the
296
+ On ``vertex_ai`` the model decides as well: Claude there is folded like
297
+ Anthropic (BACK-4162), anything else is not. On ``bedrock`` Claude is folded
298
+ by name, and any other model is folded when LiteLLM's own routing for it
299
+ builds usage with a conversion that counts the cache inside the prompt
300
+ (BACK-5780): an application inference profile ARN, Nova. The model is the
286
301
  first top-level ``model`` or ``litellm_model_name`` on any source, both
287
302
  filled by LiteLLM with the deployment it called. The caller's alias, in the
288
303
  request body, its metadata or a gateway's non-streamed ``response.model``,
289
- is never handed in by a gateway hook, so it cannot turn a Nova
290
- deployment's count into a Claude one.
304
+ is never handed in by a gateway hook, so it cannot turn a Gemini
305
+ or Bedrock ``chat_completions`` deployment's count into a netted one.
291
306
 
292
307
  With nothing to read, the prompt count stays as LiteLLM built it: reporting
293
308
  a gross count costs the cache overlap twice for Anthropic only, while
@@ -333,25 +348,84 @@ def litellm_folds_cache_write(converse: bool) -> bool:
333
348
  return not first <= release < end
334
349
 
335
350
 
336
- def _bedrock_model_routes_via_converse(model: str) -> bool:
351
+ _UNKNOWN = object()
352
+ _INVOKE_PROVIDER_UNKNOWN = object()
353
+
354
+ _BEDROCK_ROUTING_WARNED = False
355
+ _BEDROCK_ROUTING_WARNED_LOCK = threading.Lock()
356
+
357
+
358
+ def _bedrock_usage_family(model: str) -> Tuple[Any, Optional[BaseException]]:
359
+ """Which usage conversion LiteLLM's own dispatch applies to a Bedrock model.
360
+
361
+ Returns ``(family, error)``. ``family`` is ``"converse"`` or ``"anthropic"``,
362
+ both of which count the cache inside ``prompt_tokens`` and differ in when
363
+ LiteLLM started counting the write; ``None`` for any other route or
364
+ provider; ``_UNKNOWN`` when LiteLLM cannot route at all; or
365
+ ``_INVOKE_PROVIDER_UNKNOWN`` for an invoke route whose provider it could not
366
+ name. ``error`` is the exception LiteLLM raised for the last two, else
367
+ ``None``. The answer is never cached, so a later call sees LiteLLM as it is
368
+ then.
369
+ """
337
370
  try:
338
371
  from litellm.llms.bedrock.common_utils import BedrockModelInfo
339
372
 
340
- return BedrockModelInfo.get_bedrock_route(model) in _BEDROCK_CONVERSE_ROUTES
341
- except Exception:
342
- # LiteLLM routes Claude on Bedrock through Converse unless the model names invoke.
343
- return "invoke/" not in model
373
+ route = BedrockModelInfo.get_bedrock_route(model)
374
+ except Exception as error:
375
+ return _UNKNOWN, error
376
+ if route in _BEDROCK_CONVERSE_ROUTES:
377
+ return "converse", None
378
+ if route != "invoke":
379
+ return None, None
380
+ try:
381
+ from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM
382
+
383
+ provider = BaseAWSLLM.get_bedrock_invoke_provider(model)
384
+ except Exception as error:
385
+ return _INVOKE_PROVIDER_UNKNOWN, error
386
+ if provider == "nova":
387
+ return "converse", None
388
+ if provider == "anthropic":
389
+ return "anthropic", None
390
+ return None, None
391
+
392
+
393
+ def _warn_bedrock_routing_unavailable_once(error: BaseException) -> None:
394
+ global _BEDROCK_ROUTING_WARNED
395
+ with _BEDROCK_ROUTING_WARNED_LOCK:
396
+ should_log = not _BEDROCK_ROUTING_WARNED
397
+ _BEDROCK_ROUTING_WARNED = True
398
+ if should_log:
399
+ logger.warning(
400
+ "LiteLLM Bedrock routing unavailable (%s); non-Claude Bedrock rows are "
401
+ "reported with cache tokens inside the input count",
402
+ type(error).__name__,
403
+ )
404
+
405
+
406
+ def _bedrock_usage_folds_cache(model: str) -> bool:
407
+ family, error = _bedrock_usage_family(model)
408
+ if family is _UNKNOWN or family is _INVOKE_PROVIDER_UNKNOWN:
409
+ _warn_bedrock_routing_unavailable_once(error)
410
+ return False
411
+ return family is not None
344
412
 
345
413
 
346
414
  def routes_via_bedrock_converse(*sources) -> bool:
347
- """Whether LiteLLM served this call through Bedrock Converse.
415
+ """Whether the cache write window of this call is Bedrock Converse's.
348
416
 
349
417
  Read from the same sources, in the same order, as ``prompt_tokens_fold_cache``,
350
- and decided by LiteLLM's own Bedrock routing for the deployment's model.
418
+ and decided by LiteLLM's own Bedrock routing for the deployment's model: Nova
419
+ on invoke is built by LiteLLM's Converse conversion, so it counts as Converse.
420
+ When LiteLLM cannot route, Converse is assumed unless the model names invoke.
351
421
  """
352
422
  if _upstream_provider(sources) != "bedrock":
353
423
  return False
354
- return _bedrock_model_routes_via_converse(str(_first_named_model(sources) or ""))
424
+ model = str(_first_named_model(sources) or "")
425
+ family, _ = _bedrock_usage_family(model)
426
+ if family is _UNKNOWN:
427
+ return "invoke/" not in model
428
+ return family == "converse"
355
429
 
356
430
 
357
431
  def cache_creation_inside_litellm_prompt(cache_creation_tokens: int, *sources) -> int: