revenium-python-sdk 0.15.0__tar.gz → 0.16.1__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.15.0 → revenium_python_sdk-0.16.1}/PKG-INFO +78 -9
  2. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/README.md +77 -8
  3. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/pyproject.toml +1 -1
  4. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/cache_tokens.py +103 -15
  5. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/enforcement.py +144 -46
  6. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/error_text.py +26 -9
  7. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/failed_calls.py +9 -6
  8. revenium_python_sdk-0.16.1/revenium_middleware/_core/inference_geo.py +39 -0
  9. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/metering.py +4 -1
  10. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/metering_submission.py +8 -1
  11. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/tool_event_transport.py +11 -1
  12. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/wire_guards.py +15 -5
  13. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/resources/ai.py +30 -2
  14. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/types/ai_create_completion_params.py +16 -1
  15. revenium_python_sdk-0.16.1/revenium_middleware/litellm/_failed_calls.py +40 -0
  16. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/client/middleware.py +4 -20
  17. revenium_python_sdk-0.16.1/revenium_middleware/litellm/proxy/asgi.py +17 -0
  18. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/proxy/guardrail.py +55 -7
  19. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/proxy/middleware.py +4 -3
  20. revenium_python_sdk-0.16.1/revenium_middleware/litellm/proxy/shutdown.py +104 -0
  21. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/middleware.py +141 -14
  22. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_python_sdk.egg-info/PKG-INFO +78 -9
  23. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_python_sdk.egg-info/SOURCES.txt +4 -0
  24. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/tests/test_metering.py +70 -0
  25. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/LICENSE +0 -0
  26. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/__init__.py +0 -0
  27. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/__init__.py +0 -0
  28. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/call_context.py +0 -0
  29. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/call_ownership.py +0 -0
  30. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/closable_scope.py +0 -0
  31. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/config.py +0 -0
  32. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/context.py +0 -0
  33. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/decorators.py +0 -0
  34. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/delivery_circuit.py +0 -0
  35. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/exceptions.py +0 -0
  36. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/fields.py +0 -0
  37. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/json_safe.py +0 -0
  38. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/langchain_settings.py +0 -0
  39. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/load_diagnostics.py +0 -0
  40. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/log_sanitize.py +0 -0
  41. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/metering_buffer.py +0 -0
  42. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/metering_pool.py +0 -0
  43. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/metering_status.py +0 -0
  44. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/outcomes.py +0 -0
  45. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/package_versions.py +0 -0
  46. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/parse_failures.py +0 -0
  47. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/patch_registry.py +0 -0
  48. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/perplexity_cost.py +0 -0
  49. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/perplexity_usage_metadata.py +0 -0
  50. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/prompt_extraction.py +0 -0
  51. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/responses_status.py +0 -0
  52. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/secret_shapes.py +0 -0
  53. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/selective_metering.py +0 -0
  54. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/shutdown_signals.py +0 -0
  55. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/sse_body_tap.py +0 -0
  56. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/subscriber.py +0 -0
  57. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/trace_fields.py +0 -0
  58. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/usage_iterations.py +0 -0
  59. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_core/vendor_model_aliases.py +0 -0
  60. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/LICENSE +0 -0
  61. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/__init__.py +0 -0
  62. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_base_client.py +0 -0
  63. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_client.py +0 -0
  64. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_compat.py +0 -0
  65. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_constants.py +0 -0
  66. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_exceptions.py +0 -0
  67. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_files.py +0 -0
  68. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_models.py +0 -0
  69. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_qs.py +0 -0
  70. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_resource.py +0 -0
  71. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_response.py +0 -0
  72. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_streaming.py +0 -0
  73. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_types.py +0 -0
  74. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_utils/__init__.py +0 -0
  75. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_utils/_logs.py +0 -0
  76. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_utils/_proxy.py +0 -0
  77. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_utils/_reflection.py +0 -0
  78. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_utils/_resources_proxy.py +0 -0
  79. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_utils/_streams.py +0 -0
  80. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_utils/_sync.py +0 -0
  81. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_utils/_transform.py +0 -0
  82. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_utils/_typing.py +0 -0
  83. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_utils/_utils.py +0 -0
  84. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/_version.py +0 -0
  85. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/context.py +0 -0
  86. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/decorator.py +0 -0
  87. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/py.typed +0 -0
  88. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/resources/__init__.py +0 -0
  89. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/resources/apis.py +0 -0
  90. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/resources/events.py +0 -0
  91. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/types/__init__.py +0 -0
  92. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/types/ai_create_audio_params.py +0 -0
  93. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/types/ai_create_image_params.py +0 -0
  94. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/types/ai_create_video_params.py +0 -0
  95. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/types/api_meter_request_params.py +0 -0
  96. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/types/api_meter_response_params.py +0 -0
  97. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/types/event_create_params.py +0 -0
  98. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/_metering/types/metering_response_resource.py +0 -0
  99. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/agentic_outcomes.py +0 -0
  100. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/__init__.py +0 -0
  101. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/bedrock_adapter.py +0 -0
  102. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/bedrock_model_names.py +0 -0
  103. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/bedrock_transport.py +0 -0
  104. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/config.py +0 -0
  105. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/inference_profiles.py +0 -0
  106. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/middleware.py +0 -0
  107. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/prompt_extractor.py +0 -0
  108. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/provider.py +0 -0
  109. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/raw_response.py +0 -0
  110. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/stream_create.py +0 -0
  111. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/anthropic/trace_fields.py +0 -0
  112. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/fal/__init__.py +0 -0
  113. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/fal/_call.py +0 -0
  114. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/fal/_metering.py +0 -0
  115. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/fal/_queue.py +0 -0
  116. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/fal/config.py +0 -0
  117. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/fal/middleware.py +0 -0
  118. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/fal/trace_fields.py +0 -0
  119. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/__init__.py +0 -0
  120. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/common/__init__.py +0 -0
  121. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/common/exceptions.py +0 -0
  122. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/common/protocols.py +0 -0
  123. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/common/trace_fields.py +0 -0
  124. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/common/types.py +0 -0
  125. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/common/utils.py +0 -0
  126. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/config.py +0 -0
  127. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/google_ai/__init__.py +0 -0
  128. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/google_ai/middleware.py +0 -0
  129. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/google_ai/provider.py +0 -0
  130. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/prompt_extractor.py +0 -0
  131. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/vertex_ai/__init__.py +0 -0
  132. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/vertex_ai/middleware.py +0 -0
  133. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/google/vertex_ai/provider.py +0 -0
  134. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/griptape/__init__.py +0 -0
  135. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/griptape/_metadata.py +0 -0
  136. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/griptape/_retry.py +0 -0
  137. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/griptape/anthropic_driver.py +0 -0
  138. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/griptape/budget_errors.py +0 -0
  139. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/griptape/litellm_driver.py +0 -0
  140. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/griptape/ollama_driver.py +0 -0
  141. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/griptape/openai_driver.py +0 -0
  142. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/griptape/openai_embedding_driver.py +0 -0
  143. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/griptape/universal_driver.py +0 -0
  144. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/job_context.py +0 -0
  145. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/job_history.py +0 -0
  146. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/job_type_economics.py +0 -0
  147. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/__init__.py +0 -0
  148. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/client/__init__.py +0 -0
  149. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/client/config.py +0 -0
  150. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/client/context.py +0 -0
  151. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/client/decorators.py +0 -0
  152. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/client/hooks.py +0 -0
  153. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/client/integrations/__init__.py +0 -0
  154. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/client/integrations/crewai.py +0 -0
  155. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/client/trace_fields.py +0 -0
  156. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/client/validation.py +0 -0
  157. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/proxy/__init__.py +0 -0
  158. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/proxy/_health_check.py +0 -0
  159. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/litellm/proxy/_metering_owner.py +0 -0
  160. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/ollama/__init__.py +0 -0
  161. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/ollama/middleware.py +0 -0
  162. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/ollama/trace_fields.py +0 -0
  163. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/__init__.py +0 -0
  164. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/audio.py +0 -0
  165. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/azure_config.py +0 -0
  166. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/azure_model_resolver.py +0 -0
  167. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/config.py +0 -0
  168. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/exceptions.py +0 -0
  169. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/langchain/__init__.py +0 -0
  170. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/langchain/_abandoned_runs.py +0 -0
  171. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/langchain/_model_call.py +0 -0
  172. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/langchain/_perplexity_cost_capture.py +0 -0
  173. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/langchain/_prompt_capture.py +0 -0
  174. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/langchain/_text_completion_usage.py +0 -0
  175. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/langchain/_utils.py +0 -0
  176. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/langchain/unified_handler.py +0 -0
  177. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/prompt_extractor.py +0 -0
  178. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/provider.py +0 -0
  179. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/raw_response.py +0 -0
  180. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/trace_fields.py +0 -0
  181. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/openai/xai_usage.py +0 -0
  182. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/perplexity/__init__.py +0 -0
  183. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/perplexity/_metering_scope.py +0 -0
  184. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/perplexity/middleware.py +0 -0
  185. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/perplexity/patching.py +0 -0
  186. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/perplexity/perplexity_sdk.py +0 -0
  187. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/perplexity/provider.py +0 -0
  188. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/perplexity/raw_response.py +0 -0
  189. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/perplexity/streaming.py +0 -0
  190. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/perplexity/trace_fields.py +0 -0
  191. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/webhooks/__init__.py +0 -0
  192. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_middleware/webhooks/_verify.py +0 -0
  193. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_python_sdk.egg-info/dependency_links.txt +0 -0
  194. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_python_sdk.egg-info/requires.txt +0 -0
  195. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/revenium_python_sdk.egg-info/top_level.txt +0 -0
  196. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/setup.cfg +0 -0
  197. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/tests/test_metering_dispatch_timestamps.py +0 -0
  198. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/tests/test_patch_coverage.py +0 -0
  199. {revenium_python_sdk-0.15.0 → revenium_python_sdk-0.16.1}/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.15.0
3
+ Version: 0.16.1
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
@@ -196,10 +196,10 @@ 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`, `decisions.create`, `file_search_stores.import_file`, `file_search_stores.upload_to_file_search_store`, `interactions.create`, `live.connect`, `live.music.connect`, `models.edit_image`, `models.recontext_image`, `models.segment_image`, `models.upscale_image`, `triggers.run`, `tunings.tune`
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`
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
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`
@@ -563,6 +563,8 @@ client.close()
563
563
 
564
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.
565
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
+
566
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.
567
569
 
568
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.
@@ -1180,7 +1182,7 @@ response = litellm.completion(
1180
1182
  )
1181
1183
  ```
1182
1184
 
1183
- 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.
1184
1186
 
1185
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.
1186
1188
 
@@ -1223,6 +1225,26 @@ calls: a failed call is recorded only for a request the Revenium guardrail's
1223
1225
  sends no record. Adding `pre_call` enforces no budget unless
1224
1226
  `REVENIUM_CIRCUIT_BREAKER_ENABLED=true`.
1225
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
+
1226
1248
  **Budget enforcement** reuses the SDK's own circuit breaker, so a proxy enforces
1227
1249
  exactly what every other Revenium integration enforces — including department
1228
1250
  budgets. An organization cap is checked against the organization the call names,
@@ -1495,6 +1517,44 @@ return of double counting. Your other routes never carry an identifier and are n
1495
1517
  counted or warned about, so a proxy that also serves chat completions or embeddings
1496
1518
  stays quiet.
1497
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
+
1498
1558
  ##### Migrating from the callback
1499
1559
 
1500
1560
  `revenium_middleware.litellm.proxy.middleware.MiddlewareHandler` — the
@@ -1923,7 +1983,8 @@ Add business context to a call the SDK records by passing a `usage_metadata` dic
1923
1983
  These fields are shortened with a WARNING when longer than Revenium stores, so the call is still
1924
1984
  recorded: `trace_id`, `task_type`, `agent`, `subscription_id`, `parent_transaction_id`, `environment`,
1925
1985
  `region`, `transaction_name`, `operation_subtype`, `subscriber.id` and `subscriber.email` at 255
1926
- 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.
1927
1988
 
1928
1989
  | Field | Description | Use Case |
1929
1990
  |-------|-------------|----------|
@@ -1941,7 +2002,7 @@ characters, and `product_name` at 224. Other text fields are sent as given.
1941
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 |
1942
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 |
1943
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 |
1944
- | `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 |
1945
2006
 
1946
2007
  **Example:**
1947
2008
 
@@ -1999,7 +2060,13 @@ where the provider says the inference ran. Both are values you supply per call;
1999
2060
  the SDK does not read them from the environment or from the provider response.
2000
2061
  `inference_geo` is sent exactly as given, with no lowercasing or allow-list;
2001
2062
  the backend normalizes it. It is not stored as a dimension to group spend by,
2002
- 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
2003
2070
  for `ccr_session_id`, 16 for `inference_geo`) or holds anything but letters,
2004
2071
  digits, hyphens and underscores is left off the record with a WARNING, and the
2005
2072
  call is still recorded. Both are sent on completions only; image, video and
@@ -2730,7 +2797,9 @@ or unsent at the end are dropped and logged once, as a warning with a count.
2730
2797
 
2731
2798
  A process ended by SIGTERM's default action skips `atexit`, and with it that
2732
2799
  final flush. uvicorn, and so the LiteLLM proxy, ends that way once its own
2733
- 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
2734
2803
  of its own, set `REVENIUM_INSTALL_SIGNAL_HANDLERS=1`: SIGTERM then flushes
2735
2804
  first and ends the process the same way. A SIGTERM handler your code installed
2736
2805
  before importing the SDK is called unchanged, and one installed afterwards
@@ -2782,7 +2851,7 @@ timeout raises `ValueError`.
2782
2851
  | `REVENIUM_METERING_BASE_URL` | `https://api.revenium.ai` | Revenium API endpoint |
2783
2852
  | `REVENIUM_LOG_LEVEL` | `INFO` | Log level: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL` |
2784
2853
  | `REVENIUM_CAPTURE_PROMPTS` | `false` | Enable prompt capture |
2785
- | `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 |
2786
2855
  | `REVENIUM_SELECTIVE_METERING` | `false` | Only meter `@revenium_meter` decorated functions |
2787
2856
  | `REVENIUM_TEAM_ID` | - | Team ID for cost lookups and outcome reporting (JobContext team resolution) |
2788
2857
  | `REVENIUM_ENVIRONMENT` | - | Deployment environment (auto-detects from `ENVIRONMENT`, `DEPLOYMENT_ENV`) |
@@ -80,10 +80,10 @@ 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`, `decisions.create`, `file_search_stores.import_file`, `file_search_stores.upload_to_file_search_store`, `interactions.create`, `live.connect`, `live.music.connect`, `models.edit_image`, `models.recontext_image`, `models.segment_image`, `models.upscale_image`, `triggers.run`, `tunings.tune`
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`
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
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`
@@ -447,6 +447,8 @@ client.close()
447
447
 
448
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.
449
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
+
450
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.
451
453
 
452
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.
@@ -1064,7 +1066,7 @@ response = litellm.completion(
1064
1066
  )
1065
1067
  ```
1066
1068
 
1067
- 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.
1068
1070
 
1069
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.
1070
1072
 
@@ -1107,6 +1109,26 @@ calls: a failed call is recorded only for a request the Revenium guardrail's
1107
1109
  sends no record. Adding `pre_call` enforces no budget unless
1108
1110
  `REVENIUM_CIRCUIT_BREAKER_ENABLED=true`.
1109
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
+
1110
1132
  **Budget enforcement** reuses the SDK's own circuit breaker, so a proxy enforces
1111
1133
  exactly what every other Revenium integration enforces — including department
1112
1134
  budgets. An organization cap is checked against the organization the call names,
@@ -1379,6 +1401,44 @@ return of double counting. Your other routes never carry an identifier and are n
1379
1401
  counted or warned about, so a proxy that also serves chat completions or embeddings
1380
1402
  stays quiet.
1381
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
+
1382
1442
  ##### Migrating from the callback
1383
1443
 
1384
1444
  `revenium_middleware.litellm.proxy.middleware.MiddlewareHandler` — the
@@ -1807,7 +1867,8 @@ Add business context to a call the SDK records by passing a `usage_metadata` dic
1807
1867
  These fields are shortened with a WARNING when longer than Revenium stores, so the call is still
1808
1868
  recorded: `trace_id`, `task_type`, `agent`, `subscription_id`, `parent_transaction_id`, `environment`,
1809
1869
  `region`, `transaction_name`, `operation_subtype`, `subscriber.id` and `subscriber.email` at 255
1810
- 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.
1811
1872
 
1812
1873
  | Field | Description | Use Case |
1813
1874
  |-------|-------------|----------|
@@ -1825,7 +1886,7 @@ characters, and `product_name` at 224. Other text fields are sent as given.
1825
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 |
1826
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 |
1827
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 |
1828
- | `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 |
1829
1890
 
1830
1891
  **Example:**
1831
1892
 
@@ -1883,7 +1944,13 @@ where the provider says the inference ran. Both are values you supply per call;
1883
1944
  the SDK does not read them from the environment or from the provider response.
1884
1945
  `inference_geo` is sent exactly as given, with no lowercasing or allow-list;
1885
1946
  the backend normalizes it. It is not stored as a dimension to group spend by,
1886
- 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
1887
1954
  for `ccr_session_id`, 16 for `inference_geo`) or holds anything but letters,
1888
1955
  digits, hyphens and underscores is left off the record with a WARNING, and the
1889
1956
  call is still recorded. Both are sent on completions only; image, video and
@@ -2614,7 +2681,9 @@ or unsent at the end are dropped and logged once, as a warning with a count.
2614
2681
 
2615
2682
  A process ended by SIGTERM's default action skips `atexit`, and with it that
2616
2683
  final flush. uvicorn, and so the LiteLLM proxy, ends that way once its own
2617
- 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
2618
2687
  of its own, set `REVENIUM_INSTALL_SIGNAL_HANDLERS=1`: SIGTERM then flushes
2619
2688
  first and ends the process the same way. A SIGTERM handler your code installed
2620
2689
  before importing the SDK is called unchanged, and one installed afterwards
@@ -2666,7 +2735,7 @@ timeout raises `ValueError`.
2666
2735
  | `REVENIUM_METERING_BASE_URL` | `https://api.revenium.ai` | Revenium API endpoint |
2667
2736
  | `REVENIUM_LOG_LEVEL` | `INFO` | Log level: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL` |
2668
2737
  | `REVENIUM_CAPTURE_PROMPTS` | `false` | Enable prompt capture |
2669
- | `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 |
2670
2739
  | `REVENIUM_SELECTIVE_METERING` | `false` | Only meter `@revenium_meter` decorated functions |
2671
2740
  | `REVENIUM_TEAM_ID` | - | Team ID for cost lookups and outcome reporting (JobContext team resolution) |
2672
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.15.0"
7
+ version = "0.16.1"
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"
@@ -102,7 +102,9 @@ def without_openai_cache_writes(prompt_tokens: int, usage: Any) -> int:
102
102
  """``prompt_tokens`` less the OpenAI cache write it contains, never below 0.
103
103
 
104
104
  Cache reads stay in: the platform removes them itself for OpenAI-shaped
105
- rows (see ``billable_input_tokens``).
105
+ rows (see ``billable_input_tokens``). The one exception is Bedrock's
106
+ OpenAI-compatible runtime routes, whose read ``billable_input_tokens``
107
+ removes (``_BEDROCK_OPENAI_SHAPED_ROUTES``, BACK-6110).
106
108
  """
107
109
  written = openai_cache_write_tokens(usage)
108
110
  if not prompt_tokens or not written:
@@ -141,8 +143,12 @@ def billable_input_tokens(
141
143
  and through ``prompt_folds_claude_cache`` for the OpenAI client's records
142
144
  of a gateway serving Claude. On Bedrock the cache is also removed for every
143
145
  call whose usage LiteLLM built with a conversion that counts it inside the
144
- prompt, whatever the model is called (``prompt_tokens_fold_cache``). Every
145
- other model's prompt count is reported exactly as LiteLLM built it.
146
+ prompt, whatever the model is called (``prompt_tokens_fold_cache``). That
147
+ includes the one OpenAI-shaped case removed here: GPT and Grok on Bedrock's
148
+ OpenAI-compatible runtime routes, priced from a ``bedrock_converse`` row the
149
+ platform does not net (``_BEDROCK_OPENAI_SHAPED_ROUTES``, BACK-6110). If the
150
+ platform starts netting those rows, that case must go in the same release.
151
+ Every other model's prompt count is reported exactly as LiteLLM built it.
146
152
 
147
153
  A count that comes out negative contradicts the cache counts reported
148
154
  beside it, so it is reported unchanged and said out loud rather than
@@ -167,10 +173,11 @@ ANTHROPIC_MESSAGES_CALL_TYPE = "anthropic_messages"
167
173
  # LiteLLM ``custom_llm_provider`` values whose usage conversion folds the cache
168
174
  # buckets into ``prompt_tokens`` *and* whose rows the platform stores as sent.
169
175
  # Anthropic-shaped usage is the one usage shape Revenium never normalizes
170
- # server-side (see billable_input_tokens), so it is the only overlap this row
171
- # may remove: here for direct Anthropic, and in ``_CLAUDE_HOSTING_PROVIDERS``
176
+ # server-side (see billable_input_tokens), so it is the overlap this row
177
+ # removes: here for direct Anthropic, and in ``_CLAUDE_HOSTING_PROVIDERS``
172
178
  # for Claude on Bedrock and Vertex AI, plus the Bedrock conversions that build
173
- # the same shape whatever the model is named.
179
+ # the same shape whatever the model is named. The only OpenAI-shaped overlap
180
+ # removed is the read on ``_BEDROCK_OPENAI_SHAPED_ROUTES``.
174
181
  _CACHE_FOLDING_PROVIDERS = frozenset({"anthropic", "anthropic_text"})
175
182
 
176
183
  # Providers that fold the same way when the model they serve is Claude, or, on
@@ -179,7 +186,12 @@ _CACHE_FOLDING_PROVIDERS = frozenset({"anthropic", "anthropic_text"})
179
186
  # conversions all build ``prompt_tokens`` as uncached input plus cache read plus
180
187
  # cache write. Gemini on Vertex AI is reported gross by Google and netted by the
181
188
  # platform.
182
- _CLAUDE_HOSTING_PROVIDERS = frozenset({"bedrock", "vertex_ai"})
189
+ #
190
+ # ``bedrock_mantle`` is LiteLLM's second name for Bedrock's Mantle endpoint
191
+ # (``bedrock/mantle/<model>`` reports ``bedrock``). Only Claude is netted there:
192
+ # the platform nets the OpenAI-shaped Mantle rows itself, so netting them here
193
+ # as well would take the read out twice (BACK-6110, BACK-6099).
194
+ _CLAUDE_HOSTING_PROVIDERS = frozenset({"bedrock", "bedrock_mantle", "vertex_ai"})
183
195
 
184
196
  # Only the top-level fields LiteLLM fills with the deployment it called.
185
197
  _MODEL_FIELDS = ("model", "litellm_model_name")
@@ -284,8 +296,8 @@ def prompt_tokens_fold_cache(*sources):
284
296
  arithmetic that sets their billed input count (see BACK-3190 for the same
285
297
  rule on headers).
286
298
  Measured against a live litellm 1.102.0 proxy: the logging event's
287
- ``kwargs`` and its ``litellm_params`` both carry it (also on the 1.93.0
288
- floor), while on the non-streamed ``/v1/messages`` route the post-call hook
299
+ ``kwargs`` and its ``litellm_params`` both carry it (also on 1.93.0),
300
+ while on the non-streamed ``/v1/messages`` route the post-call hook
289
301
  is handed a raw provider body with no ``_hidden_params`` and a request dict
290
302
  that names no provider -- there it is ``data["litellm_logging_obj"]``'s
291
303
  ``model_call_details`` that carries both the provider and the call type.
@@ -297,12 +309,14 @@ def prompt_tokens_fold_cache(*sources):
297
309
  Anthropic (BACK-4162), anything else is not. On ``bedrock`` Claude is folded
298
310
  by name, and any other model is folded when LiteLLM's own routing for it
299
311
  builds usage with a conversion that counts the cache inside the prompt
300
- (BACK-5780): an application inference profile ARN, Nova. The model is the
312
+ (BACK-5780): an application inference profile ARN, Nova, and the
313
+ OpenAI-compatible runtime routes unless the id is an in-Region ``openai.*``
314
+ one (BACK-6110). On ``bedrock_mantle`` only Claude is folded. The model is the
301
315
  first top-level ``model`` or ``litellm_model_name`` on any source, both
302
316
  filled by LiteLLM with the deployment it called. The caller's alias, in the
303
317
  request body, its metadata or a gateway's non-streamed ``response.model``,
304
318
  is never handed in by a gateway hook, so it cannot turn a Gemini
305
- or Bedrock ``chat_completions`` deployment's count into a netted one.
319
+ or Bedrock Mantle GPT deployment's count into a netted one.
306
320
 
307
321
  With nothing to read, the prompt count stays as LiteLLM built it: reporting
308
322
  a gross count costs the cache overlap twice for Anthropic only, while
@@ -329,6 +343,25 @@ _CONVERSE_READ_ONLY_FOLD_RELEASES = ((1, 66, 0), (1, 78, 0))
329
343
 
330
344
  _BEDROCK_CONVERSE_ROUTES = frozenset({"converse", "converse_like"})
331
345
 
346
+ # LiteLLM's OpenAI-compatible routes to Bedrock's runtime endpoint: its default
347
+ # for GPT 5.6 and, from 1.110, Grok, and the ``chat_completions/`` and
348
+ # ``openai/`` prefixes. They report the cache read inside ``prompt_tokens`` the
349
+ # way OpenAI does, but the platform prices these models from the same catalog
350
+ # row as their Converse calls, which arrive net, so it cannot net one and not
351
+ # the other: the read comes out here (BACK-6110).
352
+ _BEDROCK_OPENAI_SHAPED_ROUTES = frozenset({"chat_completions", "openai"})
353
+ _OPENAI_SHAPED = "openai"
354
+
355
+ # An in-Region OpenAI id (``openai.gpt-5.6-luna``, no ``us.`` or ``global.``
356
+ # profile) has no catalog row of its own: the platform prices it from the
357
+ # ``bedrock_mantle/openai.*`` row and nets the read there (hypercurrent's
358
+ # ``CachePoolShape.isOpenAiOnMantle``), so it stays gross here.
359
+ _IN_REGION_OPENAI_ID_PREFIX = "openai."
360
+
361
+
362
+ def _platform_nets_the_read(model: str) -> bool:
363
+ return model.rsplit("/", 1)[-1].lower().startswith(_IN_REGION_OPENAI_ID_PREFIX)
364
+
332
365
 
333
366
  def _installed_litellm_version() -> Optional[str]:
334
367
  return installed_version("litellm")
@@ -360,7 +393,9 @@ def _bedrock_usage_family(model: str) -> Tuple[Any, Optional[BaseException]]:
360
393
 
361
394
  Returns ``(family, error)``. ``family`` is ``"converse"`` or ``"anthropic"``,
362
395
  both of which count the cache inside ``prompt_tokens`` and differ in when
363
- LiteLLM started counting the write; ``None`` for any other route or
396
+ LiteLLM started counting the write; ``_OPENAI_SHAPED`` for a route that
397
+ counts the read inside it and whose write ``without_openai_cache_writes``
398
+ has already removed; ``None`` for any other route or
364
399
  provider; ``_UNKNOWN`` when LiteLLM cannot route at all; or
365
400
  ``_INVOKE_PROVIDER_UNKNOWN`` for an invoke route whose provider it could not
366
401
  name. ``error`` is the exception LiteLLM raised for the last two, else
@@ -375,6 +410,8 @@ def _bedrock_usage_family(model: str) -> Tuple[Any, Optional[BaseException]]:
375
410
  return _UNKNOWN, error
376
411
  if route in _BEDROCK_CONVERSE_ROUTES:
377
412
  return "converse", None
413
+ if route in _BEDROCK_OPENAI_SHAPED_ROUTES:
414
+ return _OPENAI_SHAPED, None
378
415
  if route != "invoke":
379
416
  return None, None
380
417
  try:
@@ -408,6 +445,8 @@ def _bedrock_usage_folds_cache(model: str) -> bool:
408
445
  if family is _UNKNOWN or family is _INVOKE_PROVIDER_UNKNOWN:
409
446
  _warn_bedrock_routing_unavailable_once(error)
410
447
  return False
448
+ if family == _OPENAI_SHAPED:
449
+ return not _platform_nets_the_read(model)
411
450
  return family is not None
412
451
 
413
452
 
@@ -429,17 +468,34 @@ def routes_via_bedrock_converse(*sources) -> bool:
429
468
 
430
469
 
431
470
  def cache_creation_inside_litellm_prompt(cache_creation_tokens: int, *sources) -> int:
432
- """The part of a cache write that LiteLLM's ``prompt_tokens`` contains.
471
+ """The part of a cache write still inside a LiteLLM prompt count that has
472
+ been through ``without_openai_cache_writes``.
433
473
 
434
474
  What ``billable_input_tokens`` may take out of a folded LiteLLM prompt
435
475
  count; the write itself is still reported in full beside it. ``sources``
436
476
  are the ones handed to ``prompt_tokens_fold_cache`` for the same call.
477
+
478
+ Callers apply ``without_openai_cache_writes`` to ``prompt_tokens`` first.
479
+ On Bedrock's OpenAI-compatible routes (``_BEDROCK_OPENAI_SHAPED_ROUTES``)
480
+ that step has already removed the write, so the answer there is 0.
437
481
  """
482
+ if _write_left_the_prompt_as_an_openai_write(sources):
483
+ return 0
438
484
  if litellm_folds_cache_write(converse=routes_via_bedrock_converse(*sources)):
439
485
  return cache_creation_tokens
440
486
  return 0
441
487
 
442
488
 
489
+ def _write_left_the_prompt_as_an_openai_write(sources) -> bool:
490
+ if _upstream_provider(sources) != "bedrock":
491
+ return False
492
+ model = _first_named_model(sources)
493
+ if not model or names_claude_model(model):
494
+ return False
495
+ family, _ = _bedrock_usage_family(str(model))
496
+ return family == _OPENAI_SHAPED
497
+
498
+
443
499
  def total_priced_tokens(
444
500
  input_tokens: int, output_tokens: int, cache_read_tokens: int, cache_creation_tokens: int
445
501
  ) -> int:
@@ -476,6 +532,7 @@ _CONVERSE_TTL_PARAMETERS = {
476
532
  "5m": "cache_creation5m_token_count",
477
533
  "1h": "cache_creation1h_token_count",
478
534
  }
535
+ _TWELVE_HOUR_PARAMETER = "cache_creation12h_token_count"
479
536
 
480
537
 
481
538
  def _reported_split(split: Any) -> Dict[str, int]:
@@ -509,10 +566,32 @@ def _converse_split(usage: Any) -> Dict[str, int]:
509
566
  return counts
510
567
 
511
568
 
569
+ def _openai_responses_split(usage: Any) -> Dict[str, int]:
570
+ """The 12-hour share of an OpenAI Responses write, kept only when it fits inside the write.
571
+
572
+ Only ``ttl_12h_tokens`` has a bucket: ``ttl_30m_tokens`` stays in the
573
+ write's unattributed remainder, which the platform prices at the
574
+ five-minute column, where it keeps OpenAI's 30-minute write price. So the
575
+ share need not add up to the write, but it must lie within the aggregate
576
+ ``openai_cache_write_tokens`` reads from the same usage. A share with no
577
+ write to belong to, a negative one or one larger than the write is dropped
578
+ and the aggregate is sent alone, as ``_converse_split`` does: the platform
579
+ rejects such a bucket and bills the write flat, or at nothing for a model
580
+ priced at the input rate. Anthropic-shaped usage reports no OpenAI write
581
+ (see ``openai_cache_write_tokens``), so it never yields this bucket.
582
+ """
583
+ details = _get(_get(usage, "input_tokens_details"), "cache_write_tokens_details")
584
+ tokens = _optional_token_count(details, "ttl_12h_tokens")
585
+ written = openai_cache_write_tokens(usage)
586
+ if not written or tokens is None or not 0 <= tokens <= written:
587
+ return {}
588
+ return {_TWELVE_HOUR_PARAMETER: tokens}
589
+
590
+
512
591
  def extract_cache_creation_ttl_counts(usage: Any) -> Dict[str, int]:
513
592
  """Extract the per-TTL cache-creation breakdown as metering parameters.
514
593
 
515
- Three usage shapes carry the split, and this reads whichever is present:
594
+ Four usage shapes carry the split, and this reads whichever is present:
516
595
 
517
596
  - Anthropic, natively and on Bedrock InvokeModel: ``usage.cache_creation``
518
597
  (``ephemeral_5m_input_tokens`` / ``ephemeral_1h_input_tokens``).
@@ -520,6 +599,9 @@ def extract_cache_creation_ttl_counts(usage: Any) -> Dict[str, int]:
520
599
  ``usage.prompt_tokens_details.cache_creation_token_details``.
521
600
  - Bedrock Converse: ``usage.cacheDetails``, one ``{ttl, inputTokens}``
522
601
  entry per TTL.
602
+ - OpenAI Responses: ``usage.input_tokens_details.cache_write_tokens_details``
603
+ (``ttl_12h_tokens`` / ``ttl_30m_tokens``), of which only the 12-hour
604
+ share becomes a bucket.
523
605
 
524
606
  The split is absent on older responses and whenever the extended cache-TTL
525
607
  beta is not in play, so it is read defensively.
@@ -530,10 +612,16 @@ def extract_cache_creation_ttl_counts(usage: Any) -> Dict[str, int]:
530
612
  zero: the aggregate ``cache_creation_token_count`` stays authoritative and
531
613
  the backend prices the flat fallback from it when no split is present,
532
614
  whereas an explicit zero would assert a split that never happened. A
533
- bucket the provider does report as 0 is forwarded as 0.
615
+ split that does not fit the aggregate write the same usage reports is
616
+ dropped as a whole and the aggregate is sent alone: a Converse list that
617
+ does not add up to the write or names a TTL Revenium has no price for, and
618
+ an OpenAI 12-hour share that is negative, larger than the write, or
619
+ reported with no write (a reported 0 included). Any other bucket the
620
+ provider reports as 0 is forwarded as 0.
534
621
  """
535
622
  return (
536
623
  _reported_split(_get(usage, "cache_creation"))
537
624
  or _reported_split(_get(_get(usage, "prompt_tokens_details"), "cache_creation_token_details"))
538
625
  or _converse_split(usage)
626
+ or _openai_responses_split(usage)
539
627
  )