revenium-python-sdk 0.14.0__tar.gz → 0.16.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 (199) hide show
  1. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/PKG-INFO +97 -17
  2. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/README.md +95 -15
  3. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/pyproject.toml +5 -2
  4. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/__init__.py +4 -1
  5. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/cache_tokens.py +137 -31
  6. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/enforcement.py +631 -193
  7. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/error_text.py +26 -9
  8. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/failed_calls.py +9 -6
  9. revenium_python_sdk-0.16.0/revenium_middleware/_core/inference_geo.py +39 -0
  10. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/metering.py +4 -1
  11. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/metering_submission.py +8 -1
  12. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/tool_event_transport.py +11 -1
  13. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/wire_guards.py +15 -5
  14. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/resources/ai.py +30 -2
  15. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/types/ai_create_completion_params.py +16 -1
  16. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/job_type_economics.py +20 -0
  17. revenium_python_sdk-0.16.0/revenium_middleware/litellm/_failed_calls.py +40 -0
  18. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/client/middleware.py +46 -21
  19. revenium_python_sdk-0.16.0/revenium_middleware/litellm/proxy/_health_check.py +50 -0
  20. revenium_python_sdk-0.16.0/revenium_middleware/litellm/proxy/asgi.py +17 -0
  21. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/proxy/guardrail.py +60 -8
  22. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/proxy/middleware.py +11 -3
  23. revenium_python_sdk-0.16.0/revenium_middleware/litellm/proxy/shutdown.py +104 -0
  24. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/middleware.py +141 -14
  25. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_python_sdk.egg-info/PKG-INFO +97 -17
  26. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_python_sdk.egg-info/SOURCES.txt +5 -0
  27. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_python_sdk.egg-info/requires.txt +1 -1
  28. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/tests/test_metering.py +70 -0
  29. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/LICENSE +0 -0
  30. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/__init__.py +0 -0
  31. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/call_context.py +0 -0
  32. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/call_ownership.py +0 -0
  33. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/closable_scope.py +0 -0
  34. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/config.py +0 -0
  35. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/context.py +0 -0
  36. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/decorators.py +0 -0
  37. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/delivery_circuit.py +0 -0
  38. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/exceptions.py +0 -0
  39. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/fields.py +0 -0
  40. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/json_safe.py +0 -0
  41. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/langchain_settings.py +0 -0
  42. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/load_diagnostics.py +0 -0
  43. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/log_sanitize.py +0 -0
  44. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/metering_buffer.py +0 -0
  45. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/metering_pool.py +0 -0
  46. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/metering_status.py +0 -0
  47. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/outcomes.py +0 -0
  48. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/package_versions.py +0 -0
  49. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/parse_failures.py +0 -0
  50. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/patch_registry.py +0 -0
  51. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/perplexity_cost.py +0 -0
  52. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/perplexity_usage_metadata.py +0 -0
  53. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/prompt_extraction.py +0 -0
  54. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/responses_status.py +0 -0
  55. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/secret_shapes.py +0 -0
  56. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/selective_metering.py +0 -0
  57. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/shutdown_signals.py +0 -0
  58. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/sse_body_tap.py +0 -0
  59. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/subscriber.py +0 -0
  60. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/trace_fields.py +0 -0
  61. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/usage_iterations.py +0 -0
  62. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_core/vendor_model_aliases.py +0 -0
  63. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/LICENSE +0 -0
  64. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/__init__.py +0 -0
  65. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_base_client.py +0 -0
  66. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_client.py +0 -0
  67. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_compat.py +0 -0
  68. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_constants.py +0 -0
  69. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_exceptions.py +0 -0
  70. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_files.py +0 -0
  71. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_models.py +0 -0
  72. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_qs.py +0 -0
  73. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_resource.py +0 -0
  74. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_response.py +0 -0
  75. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_streaming.py +0 -0
  76. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_types.py +0 -0
  77. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_utils/__init__.py +0 -0
  78. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_utils/_logs.py +0 -0
  79. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_utils/_proxy.py +0 -0
  80. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_utils/_reflection.py +0 -0
  81. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_utils/_resources_proxy.py +0 -0
  82. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_utils/_streams.py +0 -0
  83. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_utils/_sync.py +0 -0
  84. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_utils/_transform.py +0 -0
  85. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_utils/_typing.py +0 -0
  86. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_utils/_utils.py +0 -0
  87. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/_version.py +0 -0
  88. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/context.py +0 -0
  89. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/decorator.py +0 -0
  90. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/py.typed +0 -0
  91. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/resources/__init__.py +0 -0
  92. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/resources/apis.py +0 -0
  93. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/resources/events.py +0 -0
  94. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/types/__init__.py +0 -0
  95. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/types/ai_create_audio_params.py +0 -0
  96. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/types/ai_create_image_params.py +0 -0
  97. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/types/ai_create_video_params.py +0 -0
  98. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/types/api_meter_request_params.py +0 -0
  99. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/types/api_meter_response_params.py +0 -0
  100. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/types/event_create_params.py +0 -0
  101. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/_metering/types/metering_response_resource.py +0 -0
  102. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/agentic_outcomes.py +0 -0
  103. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/__init__.py +0 -0
  104. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/bedrock_adapter.py +0 -0
  105. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/bedrock_model_names.py +0 -0
  106. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/bedrock_transport.py +0 -0
  107. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/config.py +0 -0
  108. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/inference_profiles.py +0 -0
  109. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/middleware.py +0 -0
  110. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/prompt_extractor.py +0 -0
  111. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/provider.py +0 -0
  112. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/raw_response.py +0 -0
  113. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/stream_create.py +0 -0
  114. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/anthropic/trace_fields.py +0 -0
  115. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/fal/__init__.py +0 -0
  116. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/fal/_call.py +0 -0
  117. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/fal/_metering.py +0 -0
  118. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/fal/_queue.py +0 -0
  119. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/fal/config.py +0 -0
  120. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/fal/middleware.py +0 -0
  121. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/fal/trace_fields.py +0 -0
  122. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/__init__.py +0 -0
  123. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/common/__init__.py +0 -0
  124. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/common/exceptions.py +0 -0
  125. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/common/protocols.py +0 -0
  126. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/common/trace_fields.py +0 -0
  127. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/common/types.py +0 -0
  128. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/common/utils.py +0 -0
  129. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/config.py +0 -0
  130. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/google_ai/__init__.py +0 -0
  131. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/google_ai/middleware.py +0 -0
  132. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/google_ai/provider.py +0 -0
  133. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/prompt_extractor.py +0 -0
  134. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/vertex_ai/__init__.py +0 -0
  135. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/vertex_ai/middleware.py +0 -0
  136. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/google/vertex_ai/provider.py +0 -0
  137. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/griptape/__init__.py +0 -0
  138. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/griptape/_metadata.py +0 -0
  139. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/griptape/_retry.py +0 -0
  140. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/griptape/anthropic_driver.py +0 -0
  141. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/griptape/budget_errors.py +0 -0
  142. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/griptape/litellm_driver.py +0 -0
  143. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/griptape/ollama_driver.py +0 -0
  144. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/griptape/openai_driver.py +0 -0
  145. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/griptape/openai_embedding_driver.py +0 -0
  146. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/griptape/universal_driver.py +0 -0
  147. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/job_context.py +0 -0
  148. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/job_history.py +0 -0
  149. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/__init__.py +0 -0
  150. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/client/__init__.py +0 -0
  151. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/client/config.py +0 -0
  152. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/client/context.py +0 -0
  153. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/client/decorators.py +0 -0
  154. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/client/hooks.py +0 -0
  155. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/client/integrations/__init__.py +0 -0
  156. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/client/integrations/crewai.py +0 -0
  157. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/client/trace_fields.py +0 -0
  158. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/client/validation.py +0 -0
  159. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/proxy/__init__.py +0 -0
  160. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/litellm/proxy/_metering_owner.py +0 -0
  161. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/ollama/__init__.py +0 -0
  162. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/ollama/middleware.py +0 -0
  163. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/ollama/trace_fields.py +0 -0
  164. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/__init__.py +0 -0
  165. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/audio.py +0 -0
  166. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/azure_config.py +0 -0
  167. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/azure_model_resolver.py +0 -0
  168. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/config.py +0 -0
  169. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/exceptions.py +0 -0
  170. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/langchain/__init__.py +0 -0
  171. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/langchain/_abandoned_runs.py +0 -0
  172. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/langchain/_model_call.py +0 -0
  173. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/langchain/_perplexity_cost_capture.py +0 -0
  174. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/langchain/_prompt_capture.py +0 -0
  175. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/langchain/_text_completion_usage.py +0 -0
  176. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/langchain/_utils.py +0 -0
  177. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/langchain/unified_handler.py +0 -0
  178. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/prompt_extractor.py +0 -0
  179. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/provider.py +0 -0
  180. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/raw_response.py +0 -0
  181. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/trace_fields.py +0 -0
  182. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/openai/xai_usage.py +0 -0
  183. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/perplexity/__init__.py +0 -0
  184. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/perplexity/_metering_scope.py +0 -0
  185. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/perplexity/middleware.py +0 -0
  186. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/perplexity/patching.py +0 -0
  187. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/perplexity/perplexity_sdk.py +0 -0
  188. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/perplexity/provider.py +0 -0
  189. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/perplexity/raw_response.py +0 -0
  190. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/perplexity/streaming.py +0 -0
  191. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/perplexity/trace_fields.py +0 -0
  192. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/webhooks/__init__.py +0 -0
  193. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_middleware/webhooks/_verify.py +0 -0
  194. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_python_sdk.egg-info/dependency_links.txt +0 -0
  195. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/revenium_python_sdk.egg-info/top_level.txt +0 -0
  196. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/setup.cfg +0 -0
  197. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/tests/test_metering_dispatch_timestamps.py +0 -0
  198. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.0}/tests/test_patch_coverage.py +0 -0
  199. {revenium_python_sdk-0.14.0 → revenium_python_sdk-0.16.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.16.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.connect`, `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
- - **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`
202
+ - **Perplexity** (`Perplexity` and `AsyncPerplexity` clients): `async_.chat.completions.create`, `batches.create`, `browser.sessions.create`, `context.create`, `contextualized_embeddings.create`, `decisions.create`, `embeddings.create`, `monitors.create`, `monitors.run`, `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`, `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.
@@ -556,6 +563,8 @@ client.close()
556
563
 
557
564
  In an `emit_completion` payload the agent is named by `agent`. `agentName` and `currency` are not sent (Revenium does not store them); `emit_completion` names them in its one-time warning about unsent keys.
558
565
 
566
+ `cacheCreationTokenCount` is the whole cache write. When the provider reports how that write splits by cache lifetime, send the split beside it as `cacheCreation5mTokenCount`, `cacheCreation1hTokenCount` and `cacheCreation12hTokenCount` so each part is priced at its own rate; leave a bucket out when the provider does not report it rather than sending 0. `get_client().ai.create_completion` takes the same buckets as `cache_creation5m_token_count`, `cache_creation1h_token_count` and `cache_creation12h_token_count`.
567
+
559
568
  `emit_completion` and `emit_tool_event` queue the record and return at once, like every automatic record: the SDK's background threads send it with the same timeouts and retries (see [Metering Delivery and Timeouts](#metering-delivery-and-timeouts)), and a record that fails with a timeout, a refused connection or a 5xx goes to the store-and-forward buffer and is sent when Revenium is reachable again. Delivery errors are logged, not raised; `emit_completion` still raises `ValueError` before anything is queued when the payload is missing a required key. Both calls return the payload you passed.
560
569
 
561
570
  Records go to the address set in code with `initialize_metering(base_url=...)` or a `metering_key(..., base_url=...)` block when one is set, else `REVENIUM_METERING_BASE_URL`; pass `meter_base_url=` to `AgenticOutcomeSettings` to pin another address. They are always sent under the settings' `api_key`, never a `metering_key()` key. `http_client=` serves jobs and outcomes only.
@@ -1173,7 +1182,7 @@ response = litellm.completion(
1173
1182
  )
1174
1183
  ```
1175
1184
 
1176
- Client mode meters `completion`, `acompletion`, `text_completion`, `atext_completion`, `completion_with_retries` and `acompletion_with_retries`, streamed or not, and `embedding` / `aembedding` as embedding calls. When you stream without `stream_options={"include_usage": True}`, the middleware asks LiteLLM for the usage chunk itself and keeps it out of your stream. LiteLLM adds that chunk for every provider, including ones it does not send `stream_options` to. `litellm.responses` and `litellm.aresponses` are not metered, except on providers LiteLLM serves through `completion`. A completion that fails, or a stream that breaks off, sends one record with stop reason `ERROR`, zero tokens for a call that never started, and the error's class and HTTP status as its error reason (plus the provider's redacted error message when both `REVENIUM_CAPTURE_ERROR_MESSAGES` and `REVENIUM_CAPTURE_PROMPTS` are `true`; a provider's error can quote the request, so it is never sent with prompt capture off); your code still gets the original exception. The HTTP status is also sent as the record's error code; a call that got no HTTP error answer (a connection error, a timeout, or a stream that broke off) has none. LiteLLM gives a connection error a 500 and a timeout a 408 that no server answered, so those get no error code and no HTTP status in their error reason, including the `InternalServerError` LiteLLM raises for a refused connection on its `openai/` and `anthropic/` providers. LiteLLM also raises a few real provider answers, such as a Vertex AI 502, as connection errors, and those get no error code either. Failure records sent by the LiteLLM gateway (proxy) do not carry the error code yet.
1185
+ Client mode meters `completion`, `acompletion`, `text_completion`, `atext_completion`, `completion_with_retries` and `acompletion_with_retries`, streamed or not, and `embedding` / `aembedding` as embedding calls. When you stream without `stream_options={"include_usage": True}`, the middleware asks LiteLLM for the usage chunk itself and keeps it out of your stream. LiteLLM adds that chunk for every provider, including ones it does not send `stream_options` to. `litellm.responses` and `litellm.aresponses` are not metered, except on providers LiteLLM serves through `completion`. A completion that fails, or a stream that breaks off, sends one record with stop reason `ERROR`, zero tokens for a call that never started, and the error's class and HTTP status as its error reason (plus the provider's redacted error message when both `REVENIUM_CAPTURE_ERROR_MESSAGES` and `REVENIUM_CAPTURE_PROMPTS` are `true`; a provider's error can quote the request, so it is never sent with prompt capture off); your code still gets the original exception. The HTTP status is also sent as the record's error code; a call that got no HTTP error answer (a connection error, a timeout, or a stream that broke off) has none. LiteLLM gives a connection error a 500 and a timeout a 408 that no server answered, so those get no error code and no HTTP status in their error reason, including the `InternalServerError` LiteLLM raises for a refused connection on its `openai/` and `anthropic/` providers. LiteLLM also raises a few real provider answers, such as a Vertex AI 502, as connection errors, and those get no error code either. Failure records sent by the LiteLLM gateway (proxy) are described under Proxy Mode below.
1177
1186
 
1178
1187
  Inside a LiteLLM proxy running `ReveniumGuardrail` with `default_on: true` and `post_call` among its modes, client mode leaves each proxied request to the guardrail, so the request is recorded once, with the guardrail's subscriber. The row names the deployment's model (the `litellm_params.model` behind the `model_name` your callers use, without its provider prefix), so a call to an alias is priced as the model it reached. The guardrail also meters streamed `/v1/responses` calls (Codex CLI, the OpenAI Agents SDK) for every provider. Client mode still records the proxied calls the guardrail does not meter, which today are streamed `/v1/completions` calls, and every call your own code in the proxy's process makes to LiteLLM directly.
1179
1188
 
@@ -1188,6 +1197,10 @@ except calls a spending cap refuses.
1188
1197
  pip install "revenium-python-sdk[litellm-proxy]" # requires Python 3.10+
1189
1198
  ```
1190
1199
 
1200
+ The extra requires **LiteLLM 1.94.0 or newer**. On LiteLLM 1.93.x the proxy cannot
1201
+ load the guardrail from the config below: it only looks for a module file beside
1202
+ `config.yaml` and stops with `Could not find module file`.
1203
+
1191
1204
  ```yaml
1192
1205
  guardrails:
1193
1206
  - guardrail_name: "revenium"
@@ -1212,6 +1225,26 @@ calls: a failed call is recorded only for a request the Revenium guardrail's
1212
1225
  sends no record. Adding `pre_call` enforces no budget unless
1213
1226
  `REVENIUM_CIRCUIT_BREAKER_ENABLED=true`.
1214
1227
 
1228
+ **A failed call** sends one record with stop reason `ERROR`, zero tokens (or the
1229
+ tokens the error reports), and the error's class as its error reason, followed by
1230
+ its HTTP status when the call got an HTTP error answer: `RateLimitError (HTTP 429)`
1231
+ for a provider's rate limit, `HTTPException (HTTP 400)` for a request another
1232
+ guardrail refused. That status is also the record's error code. A timeout, a
1233
+ refused connection and a failure with no HTTP status (`RuntimeError`, say) carry
1234
+ no error code. The message is added only as for the other integrations: with
1235
+ `REVENIUM_CAPTURE_ERROR_MESSAGES=true`, redacted, at most 255 characters, and for
1236
+ a provider's error or a guardrail's refusal, which can quote the request, only with
1237
+ `REVENIUM_CAPTURE_PROMPTS=true` as well. The duration runs from when LiteLLM
1238
+ started on the request (LiteLLM 1.102.0 and later; on older releases, from when
1239
+ it first handed the call to a provider) to the failure, and is 0 when LiteLLM
1240
+ recorded neither: before 1.102.0 for a call refused before it reached a provider,
1241
+ and on the moderation and audio routes. The time to first token is 0 and the
1242
+ completion start time is the moment of failure, as on the other integrations'
1243
+ failed records. A content block, whether a guardrail's or a provider's
1244
+ content-policy refusal, is recorded as `ERROR` with its class as the reason, not
1245
+ as `CONTENT_FILTER`. The deprecated callback's failure record carries the same
1246
+ error reason and error code.
1247
+
1215
1248
  **Budget enforcement** reuses the SDK's own circuit breaker, so a proxy enforces
1216
1249
  exactly what every other Revenium integration enforces — including department
1217
1250
  budgets. An organization cap is checked against the organization the call names,
@@ -1235,7 +1268,7 @@ the call proceeds, and it proceeds without waiting. The pre-call check reads the
1235
1268
  rules the SDK already has cached and refreshes them on a background thread, so a
1236
1269
  Revenium endpoint that hangs, refuses connections, returns errors or rejects your
1237
1270
  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
1271
+ per `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s), not once per request. Right after the
1239
1272
  proxy starts, before the first rules fetch completes, no rules are cached and
1240
1273
  calls go through; see [Fail-Open vs Fail-Closed](#fail-open-vs-fail-closed).
1241
1274
  Metering is likewise non-disruptive — nothing in the post-call path can turn a
@@ -1433,7 +1466,7 @@ Blank or unset means on; `true`, `1`, `yes`, `on` mean on; any other value turns
1433
1466
  New calls go straight back to two records when you do; records already merged stay
1434
1467
  merged. Four things have to be true for it to work:
1435
1468
 
1436
- * **LiteLLM 1.93.0 or newer.** That is the floor of the `litellm-proxy` extra, which
1469
+ * **LiteLLM 1.94.0 or newer.** That is the floor of the `litellm-proxy` extra, which
1437
1470
  is what installs the guardrail. On an older LiteLLM the guardrail logs one warning
1438
1471
  at startup and behaves exactly as it does when opted out: no header is added,
1439
1472
  the provider's response id is reported, and you get two records rather than none.
@@ -1484,6 +1517,44 @@ return of double counting. Your other routes never carry an identifier and are n
1484
1517
  counted or warned about, so a proxy that also serves chat completions or embeddings
1485
1518
  stays quiet.
1486
1519
 
1520
+ ##### Restarts and shutdown
1521
+
1522
+ A proxy stopped by SIGTERM (a rolling restart, a scale-down) loses the usage
1523
+ records the SDK still holds for its last calls unless you serve it as shown here.
1524
+ uvicorn, which the `litellm` command starts, ends the process by re-raising SIGTERM
1525
+ once its own graceful shutdown is over, before the SDK's exit flush can run (see
1526
+ [Shutdown](#shutdown)), and LiteLLM calls no shutdown method on a guardrail or
1527
+ callback (checked on LiteLLM 1.94.0, 1.105.7 and 1.109.1), so the `guardrails`
1528
+ block cannot add one.
1529
+
1530
+ Serve the proxy with uvicorn, through the SDK's wrapper of LiteLLM's app, instead of
1531
+ the `litellm` command:
1532
+
1533
+ ```bash
1534
+ CONFIG_FILE_PATH=config.yaml uvicorn revenium_middleware.litellm.proxy.asgi:app --host 0.0.0.0 --port 4000
1535
+ ```
1536
+
1537
+ It is LiteLLM's own app with one addition: once LiteLLM has finished its shutdown,
1538
+ spend-log flush included, the SDK sends the records it still holds, queued or held
1539
+ back while Revenium was not answering, before uvicorn ends the process. Requests
1540
+ pass through untouched. The flush takes at most `REVENIUM_SHUTDOWN_TIMEOUT_SECONDS`
1541
+ (5 seconds by default), so a Revenium that is slow or down delays the stop by that
1542
+ much at most; records still unsent then are dropped and counted in one warning, as
1543
+ at any other exit. An `on_metering_error` callback still running when that time is up
1544
+ does not hold the stop either: the proxy stops without waiting for it and logs a
1545
+ warning that says so. Leave room for it in the time your platform gives the proxy to
1546
+ stop (Kubernetes `terminationGracePeriodSeconds`, 30 seconds by default), on top of
1547
+ LiteLLM's own wait for in-flight requests. The flush ends metering in that process,
1548
+ and each uvicorn worker process flushes its own records.
1549
+
1550
+ What the `litellm` command did before it started uvicorn is then yours to do. Its
1551
+ options become uvicorn options or environment variables (`--num_workers` is
1552
+ uvicorn's `--workers`), and a proxy with a database needs its schema set up first:
1553
+ `litellm --config config.yaml --skip_server_startup` does that and exits, on
1554
+ LiteLLM releases that have that option. An ASGI app you build around LiteLLM's
1555
+ yourself gets the same flush from `DrainMeteringOnShutdown(app)` in
1556
+ `revenium_middleware.litellm.proxy.shutdown`.
1557
+
1487
1558
  ##### Migrating from the callback
1488
1559
 
1489
1560
  `revenium_middleware.litellm.proxy.middleware.MiddlewareHandler` — the
@@ -1912,7 +1983,8 @@ Add business context to a call the SDK records by passing a `usage_metadata` dic
1912
1983
  These fields are shortened with a WARNING when longer than Revenium stores, so the call is still
1913
1984
  recorded: `trace_id`, `task_type`, `agent`, `subscription_id`, `parent_transaction_id`, `environment`,
1914
1985
  `region`, `transaction_name`, `operation_subtype`, `subscriber.id` and `subscriber.email` at 255
1915
- characters, and `product_name` at 224. Other text fields are sent as given.
1986
+ characters, and `product_name` at 224. Other text fields are sent as given. A spending cap filtered
1987
+ on agent, task type or product judges the call by the shortened value, the one its record carries.
1916
1988
 
1917
1989
  | Field | Description | Use Case |
1918
1990
  |-------|-------------|----------|
@@ -1930,7 +2002,7 @@ characters, and `product_name` at 224. Other text fields are sent as given.
1930
2002
  | `effort` | Reasoning effort level requested of the model (free-form string, max 16 chars, `^[A-Za-z0-9_-]+$`) | Report what share of AI spend is high-effort reasoning, and compare cost per effort level |
1931
2003
  | `entrypoint` | How the coding assistant that made the call was launched, such as `cli`, `sdk-py` or `claude-vscode` (completions only, 1 to 64 chars, `^[A-Za-z0-9._-]+$`) | Split coding-assistant spend between the terminal, the SDKs and the editor or chat integrations |
1932
2004
  | `ccr_session_id` | The Claude Code cloud session the call ran in; `ccrSessionId` also accepted (completions only, 1 to 128 chars, `^[A-Za-z0-9_-]+$`) | Group the spend of one Claude Code cloud session |
1933
- | `inference_geo` | Where the provider reports the inference ran, such as `us`; `inferenceGeo` also accepted (completions only, 1 to 16 chars, `^[A-Za-z0-9_-]+$`) | Passed to Revenium with the call; it is not stored as a dimension to group spend by |
2005
+ | `inference_geo` | Where the provider reports the inference ran, such as `us`; `inferenceGeo` also accepted (completions only, 1 to 16 chars, `^[A-Za-z0-9_-]+$`) | Passed to Revenium with the call, except on a Claude call recorded under a provider other than `ANTHROPIC`, since only Anthropic's own API applies a US-inference rate. It is not stored as a dimension to group spend by |
1934
2006
 
1935
2007
  **Example:**
1936
2008
 
@@ -1988,7 +2060,13 @@ where the provider says the inference ran. Both are values you supply per call;
1988
2060
  the SDK does not read them from the environment or from the provider response.
1989
2061
  `inference_geo` is sent exactly as given, with no lowercasing or allow-list;
1990
2062
  the backend normalizes it. It is not stored as a dimension to group spend by,
1991
- so it cannot break spend down by geography. A value that is empty, too long (128 characters
2063
+ so it cannot break spend down by geography. Only Anthropic's own API applies a
2064
+ US-inference rate, so on a Claude call `inference_geo` is sent only when the call
2065
+ is recorded with provider `ANTHROPIC`. On a Claude call recorded under any other provider, such as
2066
+ `Bedrock`, `Foundry`, `Google` or `LITELLM`, it is left off. Claude through the
2067
+ older `AnthropicVertex` client is recorded as `ANTHROPIC` and still sends it.
2068
+ Calls to other vendors' models, and a direct `client.ai.create_completion`
2069
+ call, send it as given. A value that is empty, too long (128 characters
1992
2070
  for `ccr_session_id`, 16 for `inference_geo`) or holds anything but letters,
1993
2071
  digits, hyphens and underscores is left off the record with a WARNING, and the
1994
2072
  call is still recorded. Both are sent on completions only; image, video and
@@ -2390,7 +2468,7 @@ REVENIUM_ENFORCEMENT_BASE_URL=https://api.revenium.ai/profitstream # optional:
2390
2468
  | `REVENIUM_BYPASS` | `false` | When `true`, every `check_enforcement` call short-circuits to a no-op. Useful for incident response. |
2391
2469
  | `REVENIUM_TEAM_ID` | — | Hashed team ID. Path component on rule fetches; required when the breaker is enabled. |
2392
2470
  | `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. |
2471
+ | `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
2472
  | `REVENIUM_CB_FAIL_MODE` | `open` | `open` (default) lets calls through when no cache exists; `closed` raises `BudgetExceededError` until rules are loaded. |
2395
2473
  | `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
2474
 
@@ -2423,9 +2501,9 @@ LangChain embeddings models run no callbacks: `OpenAIEmbeddings` and `AzureOpenA
2423
2501
  When the circuit breaker is disabled, it is a no-op. When enabled:
2424
2502
 
2425
2503
  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.
2504
+ 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
2505
  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.
2506
+ 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
2507
  5. `204 No Content` is treated as "no rules configured" — the cache is cleared.
2430
2508
 
2431
2509
  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 +2611,7 @@ for budget in budgets or []:
2533
2611
 
2534
2612
  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
2613
 
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.
2614
+ 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
2615
 
2538
2616
  ### End-to-End Example
2539
2617
 
@@ -2719,7 +2797,9 @@ or unsent at the end are dropped and logged once, as a warning with a count.
2719
2797
 
2720
2798
  A process ended by SIGTERM's default action skips `atexit`, and with it that
2721
2799
  final flush. uvicorn, and so the LiteLLM proxy, ends that way once its own
2722
- graceful shutdown has finished. For a script or worker with no SIGTERM handling
2800
+ graceful shutdown has finished; serve the proxy as described in
2801
+ [Restarts and shutdown](#restarts-and-shutdown) to flush within that shutdown
2802
+ instead. For a script or worker with no SIGTERM handling
2723
2803
  of its own, set `REVENIUM_INSTALL_SIGNAL_HANDLERS=1`: SIGTERM then flushes
2724
2804
  first and ends the process the same way. A SIGTERM handler your code installed
2725
2805
  before importing the SDK is called unchanged, and one installed afterwards
@@ -2771,7 +2851,7 @@ timeout raises `ValueError`.
2771
2851
  | `REVENIUM_METERING_BASE_URL` | `https://api.revenium.ai` | Revenium API endpoint |
2772
2852
  | `REVENIUM_LOG_LEVEL` | `INFO` | Log level: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL` |
2773
2853
  | `REVENIUM_CAPTURE_PROMPTS` | `false` | Enable prompt capture |
2774
- | `REVENIUM_CAPTURE_ERROR_MESSAGES` | `false` | Send the exception message, redacted and capped at 2048 characters, with failed `@meter_tool` events and auto-failed `JobContext` outcomes, and cut to 255 characters (keeping its "(HTTP <status>)" ending) on the record of a failed OpenAI, Anthropic, LiteLLM, Google, Perplexity or Ollama call; off sends the exception class only (with the HTTP status for a failed call). A provider HTTP error's message, which can quote the request, is sent only when `REVENIUM_CAPTURE_PROMPTS` is also on |
2854
+ | `REVENIUM_CAPTURE_ERROR_MESSAGES` | `false` | Send the exception message, redacted and capped at 2048 characters, with failed `@meter_tool` events and auto-failed `JobContext` outcomes, and cut to 255 characters (keeping its "(HTTP <status>)" ending) on the record of a failed OpenAI, Anthropic, LiteLLM, Google, Perplexity or Ollama call; off sends the exception class only (with the HTTP status for a failed call). A provider HTTP error's message, or on a failed LiteLLM proxy call's record the `HTTPException` a guardrail refused it with, which can quote the request, is sent only when `REVENIUM_CAPTURE_PROMPTS` is also on |
2775
2855
  | `REVENIUM_SELECTIVE_METERING` | `false` | Only meter `@revenium_meter` decorated functions |
2776
2856
  | `REVENIUM_TEAM_ID` | - | Team ID for cost lookups and outcome reporting (JobContext team resolution) |
2777
2857
  | `REVENIUM_ENVIRONMENT` | - | Deployment environment (auto-detects from `ENVIRONMENT`, `DEPLOYMENT_ENV`) |
@@ -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.connect`, `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
- - **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`
86
+ - **Perplexity** (`Perplexity` and `AsyncPerplexity` clients): `async_.chat.completions.create`, `batches.create`, `browser.sessions.create`, `context.create`, `contextualized_embeddings.create`, `decisions.create`, `embeddings.create`, `monitors.create`, `monitors.run`, `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`, `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.
@@ -440,6 +447,8 @@ client.close()
440
447
 
441
448
  In an `emit_completion` payload the agent is named by `agent`. `agentName` and `currency` are not sent (Revenium does not store them); `emit_completion` names them in its one-time warning about unsent keys.
442
449
 
450
+ `cacheCreationTokenCount` is the whole cache write. When the provider reports how that write splits by cache lifetime, send the split beside it as `cacheCreation5mTokenCount`, `cacheCreation1hTokenCount` and `cacheCreation12hTokenCount` so each part is priced at its own rate; leave a bucket out when the provider does not report it rather than sending 0. `get_client().ai.create_completion` takes the same buckets as `cache_creation5m_token_count`, `cache_creation1h_token_count` and `cache_creation12h_token_count`.
451
+
443
452
  `emit_completion` and `emit_tool_event` queue the record and return at once, like every automatic record: the SDK's background threads send it with the same timeouts and retries (see [Metering Delivery and Timeouts](#metering-delivery-and-timeouts)), and a record that fails with a timeout, a refused connection or a 5xx goes to the store-and-forward buffer and is sent when Revenium is reachable again. Delivery errors are logged, not raised; `emit_completion` still raises `ValueError` before anything is queued when the payload is missing a required key. Both calls return the payload you passed.
444
453
 
445
454
  Records go to the address set in code with `initialize_metering(base_url=...)` or a `metering_key(..., base_url=...)` block when one is set, else `REVENIUM_METERING_BASE_URL`; pass `meter_base_url=` to `AgenticOutcomeSettings` to pin another address. They are always sent under the settings' `api_key`, never a `metering_key()` key. `http_client=` serves jobs and outcomes only.
@@ -1057,7 +1066,7 @@ response = litellm.completion(
1057
1066
  )
1058
1067
  ```
1059
1068
 
1060
- Client mode meters `completion`, `acompletion`, `text_completion`, `atext_completion`, `completion_with_retries` and `acompletion_with_retries`, streamed or not, and `embedding` / `aembedding` as embedding calls. When you stream without `stream_options={"include_usage": True}`, the middleware asks LiteLLM for the usage chunk itself and keeps it out of your stream. LiteLLM adds that chunk for every provider, including ones it does not send `stream_options` to. `litellm.responses` and `litellm.aresponses` are not metered, except on providers LiteLLM serves through `completion`. A completion that fails, or a stream that breaks off, sends one record with stop reason `ERROR`, zero tokens for a call that never started, and the error's class and HTTP status as its error reason (plus the provider's redacted error message when both `REVENIUM_CAPTURE_ERROR_MESSAGES` and `REVENIUM_CAPTURE_PROMPTS` are `true`; a provider's error can quote the request, so it is never sent with prompt capture off); your code still gets the original exception. The HTTP status is also sent as the record's error code; a call that got no HTTP error answer (a connection error, a timeout, or a stream that broke off) has none. LiteLLM gives a connection error a 500 and a timeout a 408 that no server answered, so those get no error code and no HTTP status in their error reason, including the `InternalServerError` LiteLLM raises for a refused connection on its `openai/` and `anthropic/` providers. LiteLLM also raises a few real provider answers, such as a Vertex AI 502, as connection errors, and those get no error code either. Failure records sent by the LiteLLM gateway (proxy) do not carry the error code yet.
1069
+ Client mode meters `completion`, `acompletion`, `text_completion`, `atext_completion`, `completion_with_retries` and `acompletion_with_retries`, streamed or not, and `embedding` / `aembedding` as embedding calls. When you stream without `stream_options={"include_usage": True}`, the middleware asks LiteLLM for the usage chunk itself and keeps it out of your stream. LiteLLM adds that chunk for every provider, including ones it does not send `stream_options` to. `litellm.responses` and `litellm.aresponses` are not metered, except on providers LiteLLM serves through `completion`. A completion that fails, or a stream that breaks off, sends one record with stop reason `ERROR`, zero tokens for a call that never started, and the error's class and HTTP status as its error reason (plus the provider's redacted error message when both `REVENIUM_CAPTURE_ERROR_MESSAGES` and `REVENIUM_CAPTURE_PROMPTS` are `true`; a provider's error can quote the request, so it is never sent with prompt capture off); your code still gets the original exception. The HTTP status is also sent as the record's error code; a call that got no HTTP error answer (a connection error, a timeout, or a stream that broke off) has none. LiteLLM gives a connection error a 500 and a timeout a 408 that no server answered, so those get no error code and no HTTP status in their error reason, including the `InternalServerError` LiteLLM raises for a refused connection on its `openai/` and `anthropic/` providers. LiteLLM also raises a few real provider answers, such as a Vertex AI 502, as connection errors, and those get no error code either. Failure records sent by the LiteLLM gateway (proxy) are described under Proxy Mode below.
1061
1070
 
1062
1071
  Inside a LiteLLM proxy running `ReveniumGuardrail` with `default_on: true` and `post_call` among its modes, client mode leaves each proxied request to the guardrail, so the request is recorded once, with the guardrail's subscriber. The row names the deployment's model (the `litellm_params.model` behind the `model_name` your callers use, without its provider prefix), so a call to an alias is priced as the model it reached. The guardrail also meters streamed `/v1/responses` calls (Codex CLI, the OpenAI Agents SDK) for every provider. Client mode still records the proxied calls the guardrail does not meter, which today are streamed `/v1/completions` calls, and every call your own code in the proxy's process makes to LiteLLM directly.
1063
1072
 
@@ -1072,6 +1081,10 @@ except calls a spending cap refuses.
1072
1081
  pip install "revenium-python-sdk[litellm-proxy]" # requires Python 3.10+
1073
1082
  ```
1074
1083
 
1084
+ The extra requires **LiteLLM 1.94.0 or newer**. On LiteLLM 1.93.x the proxy cannot
1085
+ load the guardrail from the config below: it only looks for a module file beside
1086
+ `config.yaml` and stops with `Could not find module file`.
1087
+
1075
1088
  ```yaml
1076
1089
  guardrails:
1077
1090
  - guardrail_name: "revenium"
@@ -1096,6 +1109,26 @@ calls: a failed call is recorded only for a request the Revenium guardrail's
1096
1109
  sends no record. Adding `pre_call` enforces no budget unless
1097
1110
  `REVENIUM_CIRCUIT_BREAKER_ENABLED=true`.
1098
1111
 
1112
+ **A failed call** sends one record with stop reason `ERROR`, zero tokens (or the
1113
+ tokens the error reports), and the error's class as its error reason, followed by
1114
+ its HTTP status when the call got an HTTP error answer: `RateLimitError (HTTP 429)`
1115
+ for a provider's rate limit, `HTTPException (HTTP 400)` for a request another
1116
+ guardrail refused. That status is also the record's error code. A timeout, a
1117
+ refused connection and a failure with no HTTP status (`RuntimeError`, say) carry
1118
+ no error code. The message is added only as for the other integrations: with
1119
+ `REVENIUM_CAPTURE_ERROR_MESSAGES=true`, redacted, at most 255 characters, and for
1120
+ a provider's error or a guardrail's refusal, which can quote the request, only with
1121
+ `REVENIUM_CAPTURE_PROMPTS=true` as well. The duration runs from when LiteLLM
1122
+ started on the request (LiteLLM 1.102.0 and later; on older releases, from when
1123
+ it first handed the call to a provider) to the failure, and is 0 when LiteLLM
1124
+ recorded neither: before 1.102.0 for a call refused before it reached a provider,
1125
+ and on the moderation and audio routes. The time to first token is 0 and the
1126
+ completion start time is the moment of failure, as on the other integrations'
1127
+ failed records. A content block, whether a guardrail's or a provider's
1128
+ content-policy refusal, is recorded as `ERROR` with its class as the reason, not
1129
+ as `CONTENT_FILTER`. The deprecated callback's failure record carries the same
1130
+ error reason and error code.
1131
+
1099
1132
  **Budget enforcement** reuses the SDK's own circuit breaker, so a proxy enforces
1100
1133
  exactly what every other Revenium integration enforces — including department
1101
1134
  budgets. An organization cap is checked against the organization the call names,
@@ -1119,7 +1152,7 @@ the call proceeds, and it proceeds without waiting. The pre-call check reads the
1119
1152
  rules the SDK already has cached and refreshes them on a background thread, so a
1120
1153
  Revenium endpoint that hangs, refuses connections, returns errors or rejects your
1121
1154
  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
1155
+ per `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s), not once per request. Right after the
1123
1156
  proxy starts, before the first rules fetch completes, no rules are cached and
1124
1157
  calls go through; see [Fail-Open vs Fail-Closed](#fail-open-vs-fail-closed).
1125
1158
  Metering is likewise non-disruptive — nothing in the post-call path can turn a
@@ -1317,7 +1350,7 @@ Blank or unset means on; `true`, `1`, `yes`, `on` mean on; any other value turns
1317
1350
  New calls go straight back to two records when you do; records already merged stay
1318
1351
  merged. Four things have to be true for it to work:
1319
1352
 
1320
- * **LiteLLM 1.93.0 or newer.** That is the floor of the `litellm-proxy` extra, which
1353
+ * **LiteLLM 1.94.0 or newer.** That is the floor of the `litellm-proxy` extra, which
1321
1354
  is what installs the guardrail. On an older LiteLLM the guardrail logs one warning
1322
1355
  at startup and behaves exactly as it does when opted out: no header is added,
1323
1356
  the provider's response id is reported, and you get two records rather than none.
@@ -1368,6 +1401,44 @@ return of double counting. Your other routes never carry an identifier and are n
1368
1401
  counted or warned about, so a proxy that also serves chat completions or embeddings
1369
1402
  stays quiet.
1370
1403
 
1404
+ ##### Restarts and shutdown
1405
+
1406
+ A proxy stopped by SIGTERM (a rolling restart, a scale-down) loses the usage
1407
+ records the SDK still holds for its last calls unless you serve it as shown here.
1408
+ uvicorn, which the `litellm` command starts, ends the process by re-raising SIGTERM
1409
+ once its own graceful shutdown is over, before the SDK's exit flush can run (see
1410
+ [Shutdown](#shutdown)), and LiteLLM calls no shutdown method on a guardrail or
1411
+ callback (checked on LiteLLM 1.94.0, 1.105.7 and 1.109.1), so the `guardrails`
1412
+ block cannot add one.
1413
+
1414
+ Serve the proxy with uvicorn, through the SDK's wrapper of LiteLLM's app, instead of
1415
+ the `litellm` command:
1416
+
1417
+ ```bash
1418
+ CONFIG_FILE_PATH=config.yaml uvicorn revenium_middleware.litellm.proxy.asgi:app --host 0.0.0.0 --port 4000
1419
+ ```
1420
+
1421
+ It is LiteLLM's own app with one addition: once LiteLLM has finished its shutdown,
1422
+ spend-log flush included, the SDK sends the records it still holds, queued or held
1423
+ back while Revenium was not answering, before uvicorn ends the process. Requests
1424
+ pass through untouched. The flush takes at most `REVENIUM_SHUTDOWN_TIMEOUT_SECONDS`
1425
+ (5 seconds by default), so a Revenium that is slow or down delays the stop by that
1426
+ much at most; records still unsent then are dropped and counted in one warning, as
1427
+ at any other exit. An `on_metering_error` callback still running when that time is up
1428
+ does not hold the stop either: the proxy stops without waiting for it and logs a
1429
+ warning that says so. Leave room for it in the time your platform gives the proxy to
1430
+ stop (Kubernetes `terminationGracePeriodSeconds`, 30 seconds by default), on top of
1431
+ LiteLLM's own wait for in-flight requests. The flush ends metering in that process,
1432
+ and each uvicorn worker process flushes its own records.
1433
+
1434
+ What the `litellm` command did before it started uvicorn is then yours to do. Its
1435
+ options become uvicorn options or environment variables (`--num_workers` is
1436
+ uvicorn's `--workers`), and a proxy with a database needs its schema set up first:
1437
+ `litellm --config config.yaml --skip_server_startup` does that and exits, on
1438
+ LiteLLM releases that have that option. An ASGI app you build around LiteLLM's
1439
+ yourself gets the same flush from `DrainMeteringOnShutdown(app)` in
1440
+ `revenium_middleware.litellm.proxy.shutdown`.
1441
+
1371
1442
  ##### Migrating from the callback
1372
1443
 
1373
1444
  `revenium_middleware.litellm.proxy.middleware.MiddlewareHandler` — the
@@ -1796,7 +1867,8 @@ Add business context to a call the SDK records by passing a `usage_metadata` dic
1796
1867
  These fields are shortened with a WARNING when longer than Revenium stores, so the call is still
1797
1868
  recorded: `trace_id`, `task_type`, `agent`, `subscription_id`, `parent_transaction_id`, `environment`,
1798
1869
  `region`, `transaction_name`, `operation_subtype`, `subscriber.id` and `subscriber.email` at 255
1799
- characters, and `product_name` at 224. Other text fields are sent as given.
1870
+ characters, and `product_name` at 224. Other text fields are sent as given. A spending cap filtered
1871
+ on agent, task type or product judges the call by the shortened value, the one its record carries.
1800
1872
 
1801
1873
  | Field | Description | Use Case |
1802
1874
  |-------|-------------|----------|
@@ -1814,7 +1886,7 @@ characters, and `product_name` at 224. Other text fields are sent as given.
1814
1886
  | `effort` | Reasoning effort level requested of the model (free-form string, max 16 chars, `^[A-Za-z0-9_-]+$`) | Report what share of AI spend is high-effort reasoning, and compare cost per effort level |
1815
1887
  | `entrypoint` | How the coding assistant that made the call was launched, such as `cli`, `sdk-py` or `claude-vscode` (completions only, 1 to 64 chars, `^[A-Za-z0-9._-]+$`) | Split coding-assistant spend between the terminal, the SDKs and the editor or chat integrations |
1816
1888
  | `ccr_session_id` | The Claude Code cloud session the call ran in; `ccrSessionId` also accepted (completions only, 1 to 128 chars, `^[A-Za-z0-9_-]+$`) | Group the spend of one Claude Code cloud session |
1817
- | `inference_geo` | Where the provider reports the inference ran, such as `us`; `inferenceGeo` also accepted (completions only, 1 to 16 chars, `^[A-Za-z0-9_-]+$`) | Passed to Revenium with the call; it is not stored as a dimension to group spend by |
1889
+ | `inference_geo` | Where the provider reports the inference ran, such as `us`; `inferenceGeo` also accepted (completions only, 1 to 16 chars, `^[A-Za-z0-9_-]+$`) | Passed to Revenium with the call, except on a Claude call recorded under a provider other than `ANTHROPIC`, since only Anthropic's own API applies a US-inference rate. It is not stored as a dimension to group spend by |
1818
1890
 
1819
1891
  **Example:**
1820
1892
 
@@ -1872,7 +1944,13 @@ where the provider says the inference ran. Both are values you supply per call;
1872
1944
  the SDK does not read them from the environment or from the provider response.
1873
1945
  `inference_geo` is sent exactly as given, with no lowercasing or allow-list;
1874
1946
  the backend normalizes it. It is not stored as a dimension to group spend by,
1875
- so it cannot break spend down by geography. A value that is empty, too long (128 characters
1947
+ so it cannot break spend down by geography. Only Anthropic's own API applies a
1948
+ US-inference rate, so on a Claude call `inference_geo` is sent only when the call
1949
+ is recorded with provider `ANTHROPIC`. On a Claude call recorded under any other provider, such as
1950
+ `Bedrock`, `Foundry`, `Google` or `LITELLM`, it is left off. Claude through the
1951
+ older `AnthropicVertex` client is recorded as `ANTHROPIC` and still sends it.
1952
+ Calls to other vendors' models, and a direct `client.ai.create_completion`
1953
+ call, send it as given. A value that is empty, too long (128 characters
1876
1954
  for `ccr_session_id`, 16 for `inference_geo`) or holds anything but letters,
1877
1955
  digits, hyphens and underscores is left off the record with a WARNING, and the
1878
1956
  call is still recorded. Both are sent on completions only; image, video and
@@ -2274,7 +2352,7 @@ REVENIUM_ENFORCEMENT_BASE_URL=https://api.revenium.ai/profitstream # optional:
2274
2352
  | `REVENIUM_BYPASS` | `false` | When `true`, every `check_enforcement` call short-circuits to a no-op. Useful for incident response. |
2275
2353
  | `REVENIUM_TEAM_ID` | — | Hashed team ID. Path component on rule fetches; required when the breaker is enabled. |
2276
2354
  | `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. |
2355
+ | `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
2356
  | `REVENIUM_CB_FAIL_MODE` | `open` | `open` (default) lets calls through when no cache exists; `closed` raises `BudgetExceededError` until rules are loaded. |
2279
2357
  | `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
2358
 
@@ -2307,9 +2385,9 @@ LangChain embeddings models run no callbacks: `OpenAIEmbeddings` and `AzureOpenA
2307
2385
  When the circuit breaker is disabled, it is a no-op. When enabled:
2308
2386
 
2309
2387
  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.
2388
+ 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
2389
  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.
2390
+ 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
2391
  5. `204 No Content` is treated as "no rules configured" — the cache is cleared.
2314
2392
 
2315
2393
  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 +2495,7 @@ for budget in budgets or []:
2417
2495
 
2418
2496
  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
2497
 
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.
2498
+ 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
2499
 
2422
2500
  ### End-to-End Example
2423
2501
 
@@ -2603,7 +2681,9 @@ or unsent at the end are dropped and logged once, as a warning with a count.
2603
2681
 
2604
2682
  A process ended by SIGTERM's default action skips `atexit`, and with it that
2605
2683
  final flush. uvicorn, and so the LiteLLM proxy, ends that way once its own
2606
- graceful shutdown has finished. For a script or worker with no SIGTERM handling
2684
+ graceful shutdown has finished; serve the proxy as described in
2685
+ [Restarts and shutdown](#restarts-and-shutdown) to flush within that shutdown
2686
+ instead. For a script or worker with no SIGTERM handling
2607
2687
  of its own, set `REVENIUM_INSTALL_SIGNAL_HANDLERS=1`: SIGTERM then flushes
2608
2688
  first and ends the process the same way. A SIGTERM handler your code installed
2609
2689
  before importing the SDK is called unchanged, and one installed afterwards
@@ -2655,7 +2735,7 @@ timeout raises `ValueError`.
2655
2735
  | `REVENIUM_METERING_BASE_URL` | `https://api.revenium.ai` | Revenium API endpoint |
2656
2736
  | `REVENIUM_LOG_LEVEL` | `INFO` | Log level: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL` |
2657
2737
  | `REVENIUM_CAPTURE_PROMPTS` | `false` | Enable prompt capture |
2658
- | `REVENIUM_CAPTURE_ERROR_MESSAGES` | `false` | Send the exception message, redacted and capped at 2048 characters, with failed `@meter_tool` events and auto-failed `JobContext` outcomes, and cut to 255 characters (keeping its "(HTTP <status>)" ending) on the record of a failed OpenAI, Anthropic, LiteLLM, Google, Perplexity or Ollama call; off sends the exception class only (with the HTTP status for a failed call). A provider HTTP error's message, which can quote the request, is sent only when `REVENIUM_CAPTURE_PROMPTS` is also on |
2738
+ | `REVENIUM_CAPTURE_ERROR_MESSAGES` | `false` | Send the exception message, redacted and capped at 2048 characters, with failed `@meter_tool` events and auto-failed `JobContext` outcomes, and cut to 255 characters (keeping its "(HTTP <status>)" ending) on the record of a failed OpenAI, Anthropic, LiteLLM, Google, Perplexity or Ollama call; off sends the exception class only (with the HTTP status for a failed call). A provider HTTP error's message, or on a failed LiteLLM proxy call's record the `HTTPException` a guardrail refused it with, which can quote the request, is sent only when `REVENIUM_CAPTURE_PROMPTS` is also on |
2659
2739
  | `REVENIUM_SELECTIVE_METERING` | `false` | Only meter `@revenium_meter` decorated functions |
2660
2740
  | `REVENIUM_TEAM_ID` | - | Team ID for cost lookups and outcome reporting (JobContext team resolution) |
2661
2741
  | `REVENIUM_ENVIRONMENT` | - | Deployment environment (auto-detects from `ENVIRONMENT`, `DEPLOYMENT_ENV`) |
@@ -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.16.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",