revenium-python-sdk 0.13.0__tar.gz → 0.15.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/PKG-INFO +95 -16
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/README.md +93 -14
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/pyproject.toml +5 -2
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/__init__.py +4 -1
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/cache_tokens.py +101 -27
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/enforcement.py +511 -165
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/fields.py +3 -1
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/wire_guards.py +2 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/resources/ai.py +22 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/ai_create_completion_params.py +12 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/bedrock_transport.py +5 -3
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/middleware.py +2 -2
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/provider.py +100 -67
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/job_type_economics.py +20 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/middleware.py +62 -5
- revenium_python_sdk-0.15.0/revenium_middleware/litellm/proxy/_health_check.py +50 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/proxy/guardrail.py +5 -1
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/proxy/middleware.py +7 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_model_call.py +2 -2
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/provider.py +12 -3
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/trace_fields.py +2 -2
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_python_sdk.egg-info/PKG-INFO +95 -16
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_python_sdk.egg-info/SOURCES.txt +1 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_python_sdk.egg-info/requires.txt +1 -1
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/LICENSE +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/call_context.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/call_ownership.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/closable_scope.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/config.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/context.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/decorators.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/delivery_circuit.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/error_text.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/exceptions.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/failed_calls.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/json_safe.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/langchain_settings.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/load_diagnostics.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/log_sanitize.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/metering.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/metering_buffer.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/metering_pool.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/metering_status.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/metering_submission.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/outcomes.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/package_versions.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/parse_failures.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/patch_registry.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/perplexity_cost.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/perplexity_usage_metadata.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/prompt_extraction.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/responses_status.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/secret_shapes.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/selective_metering.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/shutdown_signals.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/sse_body_tap.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/subscriber.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/tool_event_transport.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/trace_fields.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/usage_iterations.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_core/vendor_model_aliases.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/LICENSE +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_base_client.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_client.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_compat.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_constants.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_exceptions.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_files.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_models.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_qs.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_resource.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_response.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_streaming.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_types.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_logs.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_proxy.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_reflection.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_resources_proxy.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_streams.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_sync.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_transform.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_typing.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_utils/_utils.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/_version.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/context.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/decorator.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/py.typed +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/resources/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/resources/apis.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/resources/events.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/ai_create_audio_params.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/ai_create_image_params.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/ai_create_video_params.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/api_meter_request_params.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/api_meter_response_params.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/event_create_params.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/_metering/types/metering_response_resource.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/agentic_outcomes.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/bedrock_adapter.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/bedrock_model_names.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/config.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/inference_profiles.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/prompt_extractor.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/raw_response.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/stream_create.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/anthropic/trace_fields.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/_call.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/_metering.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/_queue.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/config.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/middleware.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/fal/trace_fields.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/exceptions.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/protocols.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/trace_fields.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/types.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/common/utils.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/config.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/google_ai/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/google_ai/middleware.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/google_ai/provider.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/prompt_extractor.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/vertex_ai/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/vertex_ai/middleware.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/google/vertex_ai/provider.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/_metadata.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/_retry.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/anthropic_driver.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/budget_errors.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/litellm_driver.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/ollama_driver.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/openai_driver.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/openai_embedding_driver.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/griptape/universal_driver.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/job_context.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/job_history.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/config.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/context.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/decorators.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/hooks.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/integrations/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/integrations/crewai.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/trace_fields.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/client/validation.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/proxy/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/litellm/proxy/_metering_owner.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/ollama/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/ollama/middleware.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/ollama/trace_fields.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/audio.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/azure_config.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/azure_model_resolver.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/config.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/exceptions.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_abandoned_runs.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_perplexity_cost_capture.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_prompt_capture.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_text_completion_usage.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/_utils.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/langchain/unified_handler.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/middleware.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/prompt_extractor.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/raw_response.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/openai/xai_usage.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/_metering_scope.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/middleware.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/patching.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/perplexity_sdk.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/provider.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/raw_response.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/streaming.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/perplexity/trace_fields.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/webhooks/__init__.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_middleware/webhooks/_verify.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_python_sdk.egg-info/dependency_links.txt +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/revenium_python_sdk.egg-info/top_level.txt +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/setup.cfg +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/tests/test_metering.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/tests/test_metering_dispatch_timestamps.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/tests/test_patch_coverage.py +0 -0
- {revenium_python_sdk-0.13.0 → revenium_python_sdk-0.15.0}/tests/test_release_verify_ticket.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: revenium-python-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.15.0
|
|
4
4
|
Summary: The official Revenium Python SDK — unified AI metering middleware for OpenAI, Anthropic, Google, Ollama, LiteLLM, Perplexity, and fal.ai.
|
|
5
5
|
Author-email: Revenium <support@revenium.io>
|
|
6
6
|
License: MIT
|
|
@@ -80,7 +80,7 @@ Requires-Dist: litellm>=1.40.0; extra == "litellm"
|
|
|
80
80
|
Requires-Dist: python-dotenv>=0.19.0; extra == "litellm"
|
|
81
81
|
Provides-Extra: litellm-proxy
|
|
82
82
|
Requires-Dist: wrapt>=1.14.0; extra == "litellm-proxy"
|
|
83
|
-
Requires-Dist: litellm[proxy]>=1.
|
|
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"
|
|
@@ -144,8 +144,10 @@ The official Revenium Python SDK — unified AI metering middleware for deeply a
|
|
|
144
144
|
| OpenAI | `openai` | `pip install revenium-python-sdk[openai]` |
|
|
145
145
|
| Azure OpenAI | `openai` | `pip install revenium-python-sdk[openai]` |
|
|
146
146
|
| xAI (Grok, via OpenAI SDK) | `openai` | `pip install revenium-python-sdk[openai]` |
|
|
147
|
+
| OpenRouter (via OpenAI SDK) | `openai` | `pip install revenium-python-sdk[openai]` |
|
|
147
148
|
| Anthropic | `anthropic` | `pip install revenium-python-sdk[anthropic]` |
|
|
148
149
|
| AWS Bedrock (Anthropic) | `anthropic` | `pip install revenium-python-sdk[anthropic]` |
|
|
150
|
+
| Google Cloud (Anthropic managed) | `anthropic` | `pip install revenium-python-sdk[anthropic]` |
|
|
149
151
|
| Google Gemini | `google-genai` | `pip install revenium-python-sdk[google-genai]` |
|
|
150
152
|
| Google Vertex AI | `google-vertex` | `pip install revenium-python-sdk[google-vertex]` |
|
|
151
153
|
| Ollama | `ollama` | `pip install revenium-python-sdk[ollama]` |
|
|
@@ -194,11 +196,11 @@ The calls below are billed by the provider (some, such as batch and fine-tuning
|
|
|
194
196
|
<!-- not-metered:start -->
|
|
195
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`
|
|
196
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`
|
|
197
|
-
- **Google Gemini** (`google.genai` `Client` and `Client.aio`): `batches.create`, `batches.create_embeddings`, `caches.create`, `caches.update`, `file_search_stores.import_file`, `file_search_stores.upload_to_file_search_store`, `interactions.create`, `live.connect`, `live.music.connect`, `models.edit_image`, `models.recontext_image`, `models.segment_image`, `models.upscale_image`, `triggers.run`, `tunings.tune`
|
|
199
|
+
- **Google Gemini** (`google.genai` `Client` and `Client.aio`): `batches.create`, `batches.create_embeddings`, `caches.create`, `caches.update`, `decisions.create`, `file_search_stores.import_file`, `file_search_stores.upload_to_file_search_store`, `interactions.create`, `live.connect`, `live.music.connect`, `models.edit_image`, `models.recontext_image`, `models.segment_image`, `models.upscale_image`, `triggers.run`, `tunings.tune`
|
|
198
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`
|
|
199
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`
|
|
200
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`
|
|
201
|
-
- **LiteLLM** (the `litellm` module): `aadapter_completion`, `aadapter_generate_content`, `acode_interpreter_tool`, `acompact_responses`, `acreate_batch`, `acreate_fine_tuning_job`, `acreate_run`, `acreate_sandbox`, `adapter_completion`, `adecisions`, `agenerate_content`, `aimage_edit`, `aimage_generation`, `aimage_variation`, `aingest`, `anthropic_interface.messages.acreate`, `anthropic_interface.messages.create`, `anthropic_messages`, `anthropic_messages_handler`, `aocr`, `aquery`, `arealtime_calls`, `arerank`, `aresponses`, `aresponses_api_with_mcp`, `aresponses_with_retries`, `arun_code`, `arun_thread`, `arun_thread_stream`, `asearch`, `aspeech`, `asystemone`, `atranscription`, `avideo_create_character`, `avideo_edit`, `avideo_extension`, `avideo_generation`, `avideo_remix`, `compact_responses`, `config_completion`, `create_batch`, `create_fine_tuning_job`, `create_run`, `decisions`, `image_edit`, `image_generation`, `image_variation`, `ingest`, `nlp_cloud_chat_completion`, `ocr`, `query`, `replicate_chat_completion`, `rerank`, `responses`, `responses_with_retries`, `run_thread`, `run_thread_stream`, `search`, `speech`, `systemone`, `transcription`, `video_create_character`, `video_edit`, `video_extension`, `video_generation`, `video_remix`
|
|
203
|
+
- **LiteLLM** (the `litellm` module): `aadapter_completion`, `aadapter_generate_content`, `acode_interpreter_tool`, `acompact_responses`, `acreate_batch`, `acreate_fine_tuning_job`, `acreate_run`, `acreate_sandbox`, `adapter_completion`, `adecisions`, `aextraction`, `agenerate_content`, `aimage_edit`, `aimage_generation`, `aimage_variation`, `aingest`, `anthropic_interface.messages.acreate`, `anthropic_interface.messages.create`, `anthropic_messages`, `anthropic_messages_handler`, `aocr`, `aquery`, `arealtime_calls`, `arerank`, `aresponses`, `aresponses_api_with_mcp`, `aresponses_with_retries`, `arun_code`, `arun_thread`, `arun_thread_stream`, `asearch`, `aspeech`, `asystemone`, `atranscription`, `avideo_create_character`, `avideo_edit`, `avideo_extension`, `avideo_generation`, `avideo_remix`, `compact_responses`, `config_completion`, `create_batch`, `create_fine_tuning_job`, `create_run`, `decisions`, `extraction`, `image_edit`, `image_generation`, `image_variation`, `ingest`, `nlp_cloud_chat_completion`, `ocr`, `query`, `replicate_chat_completion`, `rerank`, `responses`, `responses_with_retries`, `run_thread`, `run_thread_stream`, `search`, `speech`, `systemone`, `transcription`, `video_create_character`, `video_edit`, `video_extension`, `video_generation`, `video_remix`
|
|
202
204
|
- **Ollama** (`Client`, `AsyncClient` and the `ollama` module): `systemone`, `web_fetch`, `web_search`
|
|
203
205
|
- **fal.ai** (`SyncClient`, `AsyncClient` and the `fal_client` module): `realtime`, `realtime_async`, `ws_connect`, `ws_connect_async`
|
|
204
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`
|
|
@@ -380,6 +382,13 @@ explicit override. Economics metric directions are
|
|
|
380
382
|
Use `CUSTOMER_DECLARED` or `MEASURED` for a baseline override. Use `MEASURED`,
|
|
381
383
|
`SELF_REPORTED`, or `DERIVED` for a period fact override.
|
|
382
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
|
+
|
|
383
392
|
Facts are append-only and keyed on the period, dimension and metric key
|
|
384
393
|
together. Re-appending that tuple supersedes the active fact, and the server
|
|
385
394
|
requires `reason=` on the entry when it does.
|
|
@@ -787,6 +796,26 @@ response = client.chat.completions.create(
|
|
|
787
796
|
)
|
|
788
797
|
```
|
|
789
798
|
|
|
799
|
+
#### OpenRouter
|
|
800
|
+
|
|
801
|
+
Point the OpenAI client at OpenRouter and calls are recorded with provider and model source `OPENROUTER`, so OpenRouter spend is reported as OpenRouter rather than OpenAI and a spending cap scoped to OpenRouter applies to it. This covers chat, Responses and embeddings calls, sync and async, streamed or not, on any base URL whose host is `openrouter.ai` or one of its subdomains; a proxy or gateway on your own domain is recorded as the OpenAI-compatible call it appears to be.
|
|
802
|
+
|
|
803
|
+
```python
|
|
804
|
+
import os
|
|
805
|
+
from openai import OpenAI
|
|
806
|
+
import revenium_middleware.openai
|
|
807
|
+
|
|
808
|
+
client = OpenAI(
|
|
809
|
+
api_key=os.getenv("OPENROUTER_API_KEY"),
|
|
810
|
+
base_url="https://openrouter.ai/api/v1"
|
|
811
|
+
)
|
|
812
|
+
|
|
813
|
+
response = client.chat.completions.create(
|
|
814
|
+
model="openai/gpt-4o-mini",
|
|
815
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
816
|
+
)
|
|
817
|
+
```
|
|
818
|
+
|
|
790
819
|
---
|
|
791
820
|
|
|
792
821
|
### Anthropic
|
|
@@ -876,7 +905,7 @@ message = client.messages.create(
|
|
|
876
905
|
|
|
877
906
|
**Provider detection** automatically routes between Bedrock and direct Anthropic API based on:
|
|
878
907
|
- AWS credentials availability (`aws configure`, IAM roles, environment variables)
|
|
879
|
-
- Base URL detection (when `base_url` contains `amazonaws.com`)
|
|
908
|
+
- Base URL detection (when `base_url` contains `amazonaws.com`). The Anthropic SDK's Foundry and Google Cloud clients are labelled by their class first, so one behind an AWS-hosted gateway stays `Foundry` or `Google`
|
|
880
909
|
- Defaults to direct Anthropic API - Bedrock only used when explicitly configured
|
|
881
910
|
|
|
882
911
|
**Bedrock environment variables:**
|
|
@@ -884,7 +913,7 @@ message = client.messages.create(
|
|
|
884
913
|
| Variable | Description | Default |
|
|
885
914
|
|----------|-------------|---------|
|
|
886
915
|
| `AWS_REGION` | AWS region for Bedrock | `us-east-1` |
|
|
887
|
-
| `REVENIUM_BEDROCK_DISABLE` | Set to `1` to disable Bedrock support for Anthropic clients (Bedrock detection only - Foundry detection
|
|
916
|
+
| `REVENIUM_BEDROCK_DISABLE` | Set to `1` to disable Bedrock support for Anthropic clients (Bedrock detection only - Foundry and Google Cloud detection are unaffected). Raw boto3 calls metered with `REVENIUM_BEDROCK_TRANSPORT`, and LangChain's `ChatBedrock` and `ChatBedrockConverse`, are recorded as Bedrock | Not set |
|
|
888
917
|
| `REVENIUM_BEDROCK_TRANSPORT` | Set to `1` or `true` to meter Claude models called through a raw `boto3.client("bedrock-runtime")` (`invoke_model`, `invoke_model_with_response_stream`, `converse`, `converse_stream`); other Bedrock models are never metered this way | Not set |
|
|
889
918
|
|
|
890
919
|
**AWS authentication**: an `AnthropicBedrock` client uses its own `aws_access_key` / `aws_secret_key` / `aws_session_token`, `aws_profile` or Bedrock `api_key`, exactly as without the middleware. A plain `anthropic.Anthropic` client with a Bedrock `base_url` uses the standard credential chain: environment variables, `~/.aws/credentials`, IAM roles, AWS SSO. Required permissions: `bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream`.
|
|
@@ -909,6 +938,8 @@ message = client.messages.create(
|
|
|
909
938
|
|
|
910
939
|
For other models, the middleware uses the format `anthropic.{model_name}`.
|
|
911
940
|
|
|
941
|
+
Bedrock usage is reported with provider `Bedrock` and model source `ANTHROPIC` (or the model's vendor for LangChain `ChatBedrock`), and caps on `AWS` still match.
|
|
942
|
+
|
|
912
943
|
#### Microsoft Foundry
|
|
913
944
|
|
|
914
945
|
Claude served through Microsoft Foundry is metered by the same patched endpoints as the
|
|
@@ -935,6 +966,36 @@ is separated from direct-Anthropic totals while still priced against the Anthrop
|
|
|
935
966
|
that Foundry bills at. `AsyncAnthropicFoundry` is metered the same way, as is
|
|
936
967
|
`client.messages.stream()`.
|
|
937
968
|
|
|
969
|
+
#### Google Cloud (Anthropic managed)
|
|
970
|
+
|
|
971
|
+
Claude reached through your Google Cloud project with the Anthropic SDK's Google Cloud
|
|
972
|
+
client (anthropic 2.4.0 or later) is metered by the same patched endpoints, with no extra setup.
|
|
973
|
+
|
|
974
|
+
```python
|
|
975
|
+
import anthropic
|
|
976
|
+
import revenium_middleware.anthropic
|
|
977
|
+
|
|
978
|
+
# Detected from the client class, so a custom base_url is fine too
|
|
979
|
+
client = anthropic.AnthropicGoogleCloud(
|
|
980
|
+
project="your-project",
|
|
981
|
+
location="global",
|
|
982
|
+
workspace_id="your-workspace-id",
|
|
983
|
+
)
|
|
984
|
+
|
|
985
|
+
message = client.messages.create(
|
|
986
|
+
model="claude-opus-4-7",
|
|
987
|
+
max_tokens=100,
|
|
988
|
+
messages=[{"role": "user", "content": "Hello from Google Cloud!"}]
|
|
989
|
+
)
|
|
990
|
+
```
|
|
991
|
+
|
|
992
|
+
Google Cloud usage is reported with provider `Google` and model source `ANTHROPIC`, the
|
|
993
|
+
values the Node SDK sends for Google-billed Claude, because Google Cloud Marketplace bills
|
|
994
|
+
these calls. `AsyncAnthropicGoogleCloud` is metered the same way, as is
|
|
995
|
+
`client.messages.stream()`. A spending cap scoped to the `Google` provider counts these
|
|
996
|
+
calls; one scoped to `ANTHROPIC` does not. Claude through the older `AnthropicVertex`
|
|
997
|
+
client is still reported with provider `ANTHROPIC`.
|
|
998
|
+
|
|
938
999
|
**Examples:** `examples/anthropic/` - `anthropic-basic.py`, `anthropic-streaming.py`, `anthropic-bedrock.py`, `anthropic-advanced.py`
|
|
939
1000
|
|
|
940
1001
|
---
|
|
@@ -1134,6 +1195,10 @@ except calls a spending cap refuses.
|
|
|
1134
1195
|
pip install "revenium-python-sdk[litellm-proxy]" # requires Python 3.10+
|
|
1135
1196
|
```
|
|
1136
1197
|
|
|
1198
|
+
The extra requires **LiteLLM 1.94.0 or newer**. On LiteLLM 1.93.x the proxy cannot
|
|
1199
|
+
load the guardrail from the config below: it only looks for a module file beside
|
|
1200
|
+
`config.yaml` and stops with `Could not find module file`.
|
|
1201
|
+
|
|
1137
1202
|
```yaml
|
|
1138
1203
|
guardrails:
|
|
1139
1204
|
- guardrail_name: "revenium"
|
|
@@ -1181,7 +1246,7 @@ the call proceeds, and it proceeds without waiting. The pre-call check reads the
|
|
|
1181
1246
|
rules the SDK already has cached and refreshes them on a background thread, so a
|
|
1182
1247
|
Revenium endpoint that hangs, refuses connections, returns errors or rejects your
|
|
1183
1248
|
key (403) neither blocks nor slows the proxy. A failed refresh is retried once
|
|
1184
|
-
per `REVENIUM_CB_POLL_INTERVAL_SECONDS
|
|
1249
|
+
per `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s), not once per request. Right after the
|
|
1185
1250
|
proxy starts, before the first rules fetch completes, no rules are cached and
|
|
1186
1251
|
calls go through; see [Fail-Open vs Fail-Closed](#fail-open-vs-fail-closed).
|
|
1187
1252
|
Metering is likewise non-disruptive — nothing in the post-call path can turn a
|
|
@@ -1379,7 +1444,7 @@ Blank or unset means on; `true`, `1`, `yes`, `on` mean on; any other value turns
|
|
|
1379
1444
|
New calls go straight back to two records when you do; records already merged stay
|
|
1380
1445
|
merged. Four things have to be true for it to work:
|
|
1381
1446
|
|
|
1382
|
-
* **LiteLLM 1.
|
|
1447
|
+
* **LiteLLM 1.94.0 or newer.** That is the floor of the `litellm-proxy` extra, which
|
|
1383
1448
|
is what installs the guardrail. On an older LiteLLM the guardrail logs one warning
|
|
1384
1449
|
at startup and behaves exactly as it does when opted out: no header is added,
|
|
1385
1450
|
the provider's response id is reported, and you get two records rather than none.
|
|
@@ -1875,6 +1940,8 @@ characters, and `product_name` at 224. Other text fields are sent as given.
|
|
|
1875
1940
|
| `response_quality_score` | Custom quality rating (0.0-1.0) | Track user satisfaction or automated quality metrics for model performance analysis |
|
|
1876
1941
|
| `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 |
|
|
1877
1942
|
| `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
|
+
| `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 |
|
|
1878
1945
|
|
|
1879
1946
|
**Example:**
|
|
1880
1947
|
|
|
@@ -1926,6 +1993,18 @@ underscores is left off the record with a WARNING, and the call is still
|
|
|
1926
1993
|
recorded. It is sent on completions only; image, video and audio calls ignore
|
|
1927
1994
|
it, and the LiteLLM proxy does not read it.
|
|
1928
1995
|
|
|
1996
|
+
**Claude Code cloud session and inference geography:** `ccr_session_id` records
|
|
1997
|
+
the Claude Code cloud session a completion ran in, and `inference_geo` records
|
|
1998
|
+
where the provider says the inference ran. Both are values you supply per call;
|
|
1999
|
+
the SDK does not read them from the environment or from the provider response.
|
|
2000
|
+
`inference_geo` is sent exactly as given, with no lowercasing or allow-list;
|
|
2001
|
+
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
|
|
2003
|
+
for `ccr_session_id`, 16 for `inference_geo`) or holds anything but letters,
|
|
2004
|
+
digits, hyphens and underscores is left off the record with a WARNING, and the
|
|
2005
|
+
call is still recorded. Both are sent on completions only; image, video and
|
|
2006
|
+
audio calls ignore them, and the LiteLLM proxy does not read them.
|
|
2007
|
+
|
|
1929
2008
|
**Deprecation notice:** The legacy field aliases `organizationId`, `organization_id`, `productId`, and `product_id` are accepted by this SDK only as an input-layer convenience and emit a `DeprecationWarning`. The Revenium backend no longer accepts them — they are translated to `organizationName` / `productName` before the wire call. Migrate to `organization_name` / `organizationName` and `product_name` / `productName` now; the input-layer aliases will be removed in the next major release.
|
|
1930
2009
|
|
|
1931
2010
|
**API Reference:** [Complete metadata field documentation](https://revenium.readme.io/reference/meter_ai_completion)
|
|
@@ -2299,7 +2378,7 @@ Block outbound provider requests client-side when a Revenium cost control trips.
|
|
|
2299
2378
|
|
|
2300
2379
|
> **Terminology note:** The customer-facing entity is called a **cost control**, served by the backend at `/v2/api/ai/cost-controls`. This SDK polls a separate compiled-rules feed at `/v2/api/ai/enforcement-rules/{teamId}` and is unaffected by changes to the CRUD path — no SDK upgrade is required.
|
|
2301
2380
|
|
|
2302
|
-
Every provider middleware checks the cap: OpenAI, Azure OpenAI, Anthropic (including Claude on Bedrock and
|
|
2381
|
+
Every provider middleware checks the cap: OpenAI, Azure OpenAI, Anthropic (including Claude on Bedrock, Foundry and Google Cloud), Google Gemini and Vertex AI, Ollama, Perplexity, fal, the LiteLLM client and proxy, and the LangChain callback.
|
|
2303
2382
|
|
|
2304
2383
|
### Enable
|
|
2305
2384
|
|
|
@@ -2322,7 +2401,7 @@ REVENIUM_ENFORCEMENT_BASE_URL=https://api.revenium.ai/profitstream # optional:
|
|
|
2322
2401
|
| `REVENIUM_BYPASS` | `false` | When `true`, every `check_enforcement` call short-circuits to a no-op. Useful for incident response. |
|
|
2323
2402
|
| `REVENIUM_TEAM_ID` | — | Hashed team ID. Path component on rule fetches; required when the breaker is enabled. |
|
|
2324
2403
|
| `REVENIUM_ENFORCEMENT_BASE_URL` | `https://api.revenium.ai/profitstream` | Base URL for the enforcement API, taken as given. When unset it is the address outcomes and jobs use (`REVENIUM_PROFITSTREAM_BASE_URL`, else the Revenium address `REVENIUM_METERING_BASE_URL` or `initialize_metering(base_url=...)` sits under, without its `/meter` segment) plus `/profitstream`. A rules fetch that answers 404 is retried once at the same address with `/profitstream` removed, or added if it was missing, and the address that answers with rules is used from then on, so a self-hosted server that serves the API at the root, or a value set without `/profitstream`, still reaches the rules. |
|
|
2325
|
-
| `REVENIUM_CB_POLL_INTERVAL_SECONDS` | `
|
|
2404
|
+
| `REVENIUM_CB_POLL_INTERVAL_SECONDS` | `30` | Seconds between background rule refreshes, and the wait before a failed refresh is retried. Whole seconds from a minimum of `5` to a maximum of `3600`: a lower value is raised to `5` with one warning per process start, and a higher one is capped at `3600`. Anything other than plain digits after trimming spaces (a sign, a decimal point, other text), an empty value and `0` use the default. Read once when polling starts, so a change takes effect when the process restarts. While calls are arriving, rules older than 120 seconds are refreshed on the next call whatever the interval, so a value above `120` only spaces out refreshes on an idle process and the retry after a failed refresh. |
|
|
2326
2405
|
| `REVENIUM_CB_FAIL_MODE` | `open` | `open` (default) lets calls through when no cache exists; `closed` raises `BudgetExceededError` until rules are loaded. |
|
|
2327
2406
|
| `REVENIUM_CACHE_DIR` | unset | When set, the rule cache is mirrored to `<dir>/revenium_enforcement_rules.<scope>.json` so a restarted process doesn't fail-closed on the very first call. `<scope>` is a short hash of the enforcement base URL and `REVENIUM_TEAM_ID`, so services for different teams can share one folder and each loads only its own rules. Nothing is saved without `REVENIUM_TEAM_ID`. |
|
|
2328
2407
|
|
|
@@ -2342,7 +2421,7 @@ client = openai.OpenAI()
|
|
|
2342
2421
|
The pre-call check fires before every call these middlewares meter, including streamed, raw-response, beta and async variants and calls selective metering leaves unmetered:
|
|
2343
2422
|
|
|
2344
2423
|
- OpenAI and Azure OpenAI: chat completions, responses, embeddings and audio.
|
|
2345
|
-
- Anthropic, including Claude on Bedrock (`AnthropicBedrock`, and raw boto3 calls with `REVENIUM_BEDROCK_TRANSPORT=1`), Claude on Vertex AI (`AnthropicVertex`) and
|
|
2424
|
+
- Anthropic, including Claude on Bedrock (`AnthropicBedrock`, and raw boto3 calls with `REVENIUM_BEDROCK_TRANSPORT=1`), Claude on Vertex AI (`AnthropicVertex`), Foundry and Google Cloud (`AnthropicGoogleCloud`): `messages.create`, `stream` and `parse`, and their beta twins.
|
|
2346
2425
|
- Google: google-genai content, embeddings, Imagen and Veo, and Vertex AI generation, chat, embeddings and Imagen.
|
|
2347
2426
|
- Ollama: chat, generate, embed and embeddings.
|
|
2348
2427
|
- Perplexity: the native client and the OpenAI-compatible client.
|
|
@@ -2355,9 +2434,9 @@ LangChain embeddings models run no callbacks: `OpenAIEmbeddings` and `AzureOpenA
|
|
|
2355
2434
|
When the circuit breaker is disabled, it is a no-op. When enabled:
|
|
2356
2435
|
|
|
2357
2436
|
1. A daemon thread (`revenium-enforcement-poll`) starts on first use.
|
|
2358
|
-
2. It polls `GET {REVENIUM_ENFORCEMENT_BASE_URL}/v2/api/ai/enforcement-rules/{REVENIUM_TEAM_ID}` every `REVENIUM_CB_POLL_INTERVAL_SECONDS` with the `x-api-key` header.
|
|
2437
|
+
2. It polls `GET {REVENIUM_ENFORCEMENT_BASE_URL}/v2/api/ai/enforcement-rules/{REVENIUM_TEAM_ID}` every `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s) with the `x-api-key` header.
|
|
2359
2438
|
3. Rules are cached in-process. The pre-call check only reads that cache: it never makes a network request and never sleeps, so it is safe on an event loop (LiteLLM proxy, `AsyncOpenAI`). When the cache is more than 120 s old the check wakes the poller to refresh it early and carries on with the rules it has. Only one refresh runs at a time per process.
|
|
2360
|
-
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
|
|
2439
|
+
4. A refresh that fails (timeout, refused connection, 5xx, or any 4xx such as a 403 for a wrong key or team id) keeps the cached rules, logs a warning, and is not retried for one `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s), however much traffic arrives meanwhile. A 4xx answer the SDK does not retry (any but 408 and 429) is logged at WARNING with the URL and the status, so a wrong address (404) or a wrong key or team id (401, 403) is visible without debug logging.
|
|
2361
2440
|
5. `204 No Content` is treated as "no rules configured" — the cache is cleared.
|
|
2362
2441
|
|
|
2363
2442
|
A rule with filters (a cap scoped to an agent, model, provider, subscriber, credential, task type, product or organization) blocks or warns only the calls that match all of them; a filter the SDK cannot evaluate, such as the model of a LiteLLM proxy request, keeps the rule applying.
|
|
@@ -2465,7 +2544,7 @@ for budget in budgets or []:
|
|
|
2465
2544
|
|
|
2466
2545
|
Each row has `source` `ANOMALY` and `action` `NOTIFY`, groups by `SUBSCRIBER` with a per-person `groupBreakdown`, and carries `readingAt` when the current window has a reading. The call returns `[]` when the team has no advisory budgets and `None` when the enforcement API cannot be reached.
|
|
2467
2546
|
|
|
2468
|
-
The background poller is unaffected: it keeps reading the **whole team's** rules every `REVENIUM_CB_POLL_INTERVAL_SECONDS
|
|
2547
|
+
The background poller is unaffected: it keeps reading the **whole team's** rules every `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s). That is deliberate. The server computes the department-budget maps team-wide and attaches them to the team-wide read, so a poll narrowed to a single rule would stop receiving them and department budgets would quietly stop blocking anyone. Narrowing is an explicit, opt-in inspection call and never the refresh.
|
|
2469
2548
|
|
|
2470
2549
|
### End-to-End Example
|
|
2471
2550
|
|
|
@@ -2721,7 +2800,7 @@ timeout raises `ValueError`.
|
|
|
2721
2800
|
| `REVENIUM_WRITE_API_KEY` | - | Primary write-scope key (`rev_sk_`) for the agentic outcomes API (report/amend/history); falls back to `REVENIUM_OUTCOME_API_KEY` (deprecated), then `REVENIUM_METERING_API_KEY` |
|
|
2722
2801
|
| `REVENIUM_OUTCOME_API_KEY` | - | Deprecated fallback name for the write-scope key; used only when `REVENIUM_WRITE_API_KEY` is unset |
|
|
2723
2802
|
| `REVENIUM_PROFITSTREAM_BASE_URL` | same address as `REVENIUM_METERING_BASE_URL` | Agentic outcomes API base URL. Only needed when outcomes live at a different address than usage. By default it follows the `REVENIUM_METERING_BASE_URL` environment variable: a trailing `/meter` is removed and a path prefix is kept. `AgenticOutcomeClient` also follows a usage address set in code with `initialize_metering(base_url=...)` or a `metering_key(..., base_url=...)` block, for its jobs and outcomes as for its usage records, unless this variable or `profitstream_base_url=` sets an outcome address, or `meter_base_url=` names an address other than the one in `REVENIUM_METERING_BASE_URL`. |
|
|
2724
|
-
| `REVENIUM_BEDROCK_DISABLE` | - | Set to `1` to stop Anthropic clients being detected as Bedrock; Foundry detection
|
|
2803
|
+
| `REVENIUM_BEDROCK_DISABLE` | - | Set to `1` to stop Anthropic clients being detected as Bedrock; Foundry and Google Cloud detection are unaffected. Raw boto3 calls metered with `REVENIUM_BEDROCK_TRANSPORT`, and LangChain's `ChatBedrock` and `ChatBedrockConverse`, are recorded as Bedrock |
|
|
2725
2804
|
| `REVENIUM_BEDROCK_TRANSPORT` | - | Set to `1` or `true` to meter Claude models called through a raw `boto3.client("bedrock-runtime")` (`invoke_model`, `invoke_model_with_response_stream`, `converse`, `converse_stream`); other Bedrock models are never metered this way |
|
|
2726
2805
|
| `REVENIUM_BUFFER_MAX_SIZE` | `20000` | Store-and-forward buffer capacity (oldest events evicted when full) |
|
|
2727
2806
|
| `REVENIUM_BUFFER_FLUSH_INTERVAL` | `30` | Seconds between automatic replay attempts for buffered events |
|
|
@@ -2776,7 +2855,7 @@ Per-call `usage_metadata` values take precedence over the `REVENIUM_AGENTIC_JOB_
|
|
|
2776
2855
|
|
|
2777
2856
|
**Debug mode:** Set `REVENIUM_LOG_LEVEL=DEBUG` (or `REVENIUM_DEBUG=true`, which is the same for every integration) to see detailed provider detection, routing decisions, and metering payloads, with credentials, emails and prompt or reply text redacted. Token counts, ids, model names and attribution names still print.
|
|
2778
2857
|
|
|
2779
|
-
**Stop Bedrock detection on Anthropic clients:** Set `REVENIUM_BEDROCK_DISABLE=1` to disable Bedrock auto-detection on Anthropic clients. It does not send your calls to Anthropic directly: an `AnthropicBedrock` call still goes to AWS and is billed by AWS, but is recorded as provider `anthropic` at the Anthropic price. Foundry detection
|
|
2858
|
+
**Stop Bedrock detection on Anthropic clients:** Set `REVENIUM_BEDROCK_DISABLE=1` to disable Bedrock auto-detection on Anthropic clients. It does not send your calls to Anthropic directly: an `AnthropicBedrock` call still goes to AWS and is billed by AWS, but is recorded as provider `anthropic` at the Anthropic price. Foundry and Google Cloud detection are unaffected - a Foundry client is still labelled `Foundry` and a Google Cloud client `Google`. Raw boto3 calls metered with `REVENIUM_BEDROCK_TRANSPORT` and LangChain's `ChatBedrock` and `ChatBedrockConverse` are recorded as Bedrock.
|
|
2780
2859
|
|
|
2781
2860
|
**Check initialization status (Anthropic):** Use `revenium_middleware.anthropic.is_initialized()` to verify setup.
|
|
2782
2861
|
|
|
@@ -28,8 +28,10 @@ The official Revenium Python SDK — unified AI metering middleware for deeply a
|
|
|
28
28
|
| OpenAI | `openai` | `pip install revenium-python-sdk[openai]` |
|
|
29
29
|
| Azure OpenAI | `openai` | `pip install revenium-python-sdk[openai]` |
|
|
30
30
|
| xAI (Grok, via OpenAI SDK) | `openai` | `pip install revenium-python-sdk[openai]` |
|
|
31
|
+
| OpenRouter (via OpenAI SDK) | `openai` | `pip install revenium-python-sdk[openai]` |
|
|
31
32
|
| Anthropic | `anthropic` | `pip install revenium-python-sdk[anthropic]` |
|
|
32
33
|
| AWS Bedrock (Anthropic) | `anthropic` | `pip install revenium-python-sdk[anthropic]` |
|
|
34
|
+
| Google Cloud (Anthropic managed) | `anthropic` | `pip install revenium-python-sdk[anthropic]` |
|
|
33
35
|
| Google Gemini | `google-genai` | `pip install revenium-python-sdk[google-genai]` |
|
|
34
36
|
| Google Vertex AI | `google-vertex` | `pip install revenium-python-sdk[google-vertex]` |
|
|
35
37
|
| Ollama | `ollama` | `pip install revenium-python-sdk[ollama]` |
|
|
@@ -78,11 +80,11 @@ The calls below are billed by the provider (some, such as batch and fine-tuning
|
|
|
78
80
|
<!-- not-metered:start -->
|
|
79
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`
|
|
80
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`
|
|
81
|
-
- **Google Gemini** (`google.genai` `Client` and `Client.aio`): `batches.create`, `batches.create_embeddings`, `caches.create`, `caches.update`, `file_search_stores.import_file`, `file_search_stores.upload_to_file_search_store`, `interactions.create`, `live.connect`, `live.music.connect`, `models.edit_image`, `models.recontext_image`, `models.segment_image`, `models.upscale_image`, `triggers.run`, `tunings.tune`
|
|
83
|
+
- **Google Gemini** (`google.genai` `Client` and `Client.aio`): `batches.create`, `batches.create_embeddings`, `caches.create`, `caches.update`, `decisions.create`, `file_search_stores.import_file`, `file_search_stores.upload_to_file_search_store`, `interactions.create`, `live.connect`, `live.music.connect`, `models.edit_image`, `models.recontext_image`, `models.segment_image`, `models.upscale_image`, `triggers.run`, `tunings.tune`
|
|
82
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`
|
|
83
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`
|
|
84
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`
|
|
85
|
-
- **LiteLLM** (the `litellm` module): `aadapter_completion`, `aadapter_generate_content`, `acode_interpreter_tool`, `acompact_responses`, `acreate_batch`, `acreate_fine_tuning_job`, `acreate_run`, `acreate_sandbox`, `adapter_completion`, `adecisions`, `agenerate_content`, `aimage_edit`, `aimage_generation`, `aimage_variation`, `aingest`, `anthropic_interface.messages.acreate`, `anthropic_interface.messages.create`, `anthropic_messages`, `anthropic_messages_handler`, `aocr`, `aquery`, `arealtime_calls`, `arerank`, `aresponses`, `aresponses_api_with_mcp`, `aresponses_with_retries`, `arun_code`, `arun_thread`, `arun_thread_stream`, `asearch`, `aspeech`, `asystemone`, `atranscription`, `avideo_create_character`, `avideo_edit`, `avideo_extension`, `avideo_generation`, `avideo_remix`, `compact_responses`, `config_completion`, `create_batch`, `create_fine_tuning_job`, `create_run`, `decisions`, `image_edit`, `image_generation`, `image_variation`, `ingest`, `nlp_cloud_chat_completion`, `ocr`, `query`, `replicate_chat_completion`, `rerank`, `responses`, `responses_with_retries`, `run_thread`, `run_thread_stream`, `search`, `speech`, `systemone`, `transcription`, `video_create_character`, `video_edit`, `video_extension`, `video_generation`, `video_remix`
|
|
87
|
+
- **LiteLLM** (the `litellm` module): `aadapter_completion`, `aadapter_generate_content`, `acode_interpreter_tool`, `acompact_responses`, `acreate_batch`, `acreate_fine_tuning_job`, `acreate_run`, `acreate_sandbox`, `adapter_completion`, `adecisions`, `aextraction`, `agenerate_content`, `aimage_edit`, `aimage_generation`, `aimage_variation`, `aingest`, `anthropic_interface.messages.acreate`, `anthropic_interface.messages.create`, `anthropic_messages`, `anthropic_messages_handler`, `aocr`, `aquery`, `arealtime_calls`, `arerank`, `aresponses`, `aresponses_api_with_mcp`, `aresponses_with_retries`, `arun_code`, `arun_thread`, `arun_thread_stream`, `asearch`, `aspeech`, `asystemone`, `atranscription`, `avideo_create_character`, `avideo_edit`, `avideo_extension`, `avideo_generation`, `avideo_remix`, `compact_responses`, `config_completion`, `create_batch`, `create_fine_tuning_job`, `create_run`, `decisions`, `extraction`, `image_edit`, `image_generation`, `image_variation`, `ingest`, `nlp_cloud_chat_completion`, `ocr`, `query`, `replicate_chat_completion`, `rerank`, `responses`, `responses_with_retries`, `run_thread`, `run_thread_stream`, `search`, `speech`, `systemone`, `transcription`, `video_create_character`, `video_edit`, `video_extension`, `video_generation`, `video_remix`
|
|
86
88
|
- **Ollama** (`Client`, `AsyncClient` and the `ollama` module): `systemone`, `web_fetch`, `web_search`
|
|
87
89
|
- **fal.ai** (`SyncClient`, `AsyncClient` and the `fal_client` module): `realtime`, `realtime_async`, `ws_connect`, `ws_connect_async`
|
|
88
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`
|
|
@@ -264,6 +266,13 @@ explicit override. Economics metric directions are
|
|
|
264
266
|
Use `CUSTOMER_DECLARED` or `MEASURED` for a baseline override. Use `MEASURED`,
|
|
265
267
|
`SELF_REPORTED`, or `DERIVED` for a period fact override.
|
|
266
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
|
+
|
|
267
276
|
Facts are append-only and keyed on the period, dimension and metric key
|
|
268
277
|
together. Re-appending that tuple supersedes the active fact, and the server
|
|
269
278
|
requires `reason=` on the entry when it does.
|
|
@@ -671,6 +680,26 @@ response = client.chat.completions.create(
|
|
|
671
680
|
)
|
|
672
681
|
```
|
|
673
682
|
|
|
683
|
+
#### OpenRouter
|
|
684
|
+
|
|
685
|
+
Point the OpenAI client at OpenRouter and calls are recorded with provider and model source `OPENROUTER`, so OpenRouter spend is reported as OpenRouter rather than OpenAI and a spending cap scoped to OpenRouter applies to it. This covers chat, Responses and embeddings calls, sync and async, streamed or not, on any base URL whose host is `openrouter.ai` or one of its subdomains; a proxy or gateway on your own domain is recorded as the OpenAI-compatible call it appears to be.
|
|
686
|
+
|
|
687
|
+
```python
|
|
688
|
+
import os
|
|
689
|
+
from openai import OpenAI
|
|
690
|
+
import revenium_middleware.openai
|
|
691
|
+
|
|
692
|
+
client = OpenAI(
|
|
693
|
+
api_key=os.getenv("OPENROUTER_API_KEY"),
|
|
694
|
+
base_url="https://openrouter.ai/api/v1"
|
|
695
|
+
)
|
|
696
|
+
|
|
697
|
+
response = client.chat.completions.create(
|
|
698
|
+
model="openai/gpt-4o-mini",
|
|
699
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
700
|
+
)
|
|
701
|
+
```
|
|
702
|
+
|
|
674
703
|
---
|
|
675
704
|
|
|
676
705
|
### Anthropic
|
|
@@ -760,7 +789,7 @@ message = client.messages.create(
|
|
|
760
789
|
|
|
761
790
|
**Provider detection** automatically routes between Bedrock and direct Anthropic API based on:
|
|
762
791
|
- AWS credentials availability (`aws configure`, IAM roles, environment variables)
|
|
763
|
-
- Base URL detection (when `base_url` contains `amazonaws.com`)
|
|
792
|
+
- Base URL detection (when `base_url` contains `amazonaws.com`). The Anthropic SDK's Foundry and Google Cloud clients are labelled by their class first, so one behind an AWS-hosted gateway stays `Foundry` or `Google`
|
|
764
793
|
- Defaults to direct Anthropic API - Bedrock only used when explicitly configured
|
|
765
794
|
|
|
766
795
|
**Bedrock environment variables:**
|
|
@@ -768,7 +797,7 @@ message = client.messages.create(
|
|
|
768
797
|
| Variable | Description | Default |
|
|
769
798
|
|----------|-------------|---------|
|
|
770
799
|
| `AWS_REGION` | AWS region for Bedrock | `us-east-1` |
|
|
771
|
-
| `REVENIUM_BEDROCK_DISABLE` | Set to `1` to disable Bedrock support for Anthropic clients (Bedrock detection only - Foundry detection
|
|
800
|
+
| `REVENIUM_BEDROCK_DISABLE` | Set to `1` to disable Bedrock support for Anthropic clients (Bedrock detection only - Foundry and Google Cloud detection are unaffected). Raw boto3 calls metered with `REVENIUM_BEDROCK_TRANSPORT`, and LangChain's `ChatBedrock` and `ChatBedrockConverse`, are recorded as Bedrock | Not set |
|
|
772
801
|
| `REVENIUM_BEDROCK_TRANSPORT` | Set to `1` or `true` to meter Claude models called through a raw `boto3.client("bedrock-runtime")` (`invoke_model`, `invoke_model_with_response_stream`, `converse`, `converse_stream`); other Bedrock models are never metered this way | Not set |
|
|
773
802
|
|
|
774
803
|
**AWS authentication**: an `AnthropicBedrock` client uses its own `aws_access_key` / `aws_secret_key` / `aws_session_token`, `aws_profile` or Bedrock `api_key`, exactly as without the middleware. A plain `anthropic.Anthropic` client with a Bedrock `base_url` uses the standard credential chain: environment variables, `~/.aws/credentials`, IAM roles, AWS SSO. Required permissions: `bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream`.
|
|
@@ -793,6 +822,8 @@ message = client.messages.create(
|
|
|
793
822
|
|
|
794
823
|
For other models, the middleware uses the format `anthropic.{model_name}`.
|
|
795
824
|
|
|
825
|
+
Bedrock usage is reported with provider `Bedrock` and model source `ANTHROPIC` (or the model's vendor for LangChain `ChatBedrock`), and caps on `AWS` still match.
|
|
826
|
+
|
|
796
827
|
#### Microsoft Foundry
|
|
797
828
|
|
|
798
829
|
Claude served through Microsoft Foundry is metered by the same patched endpoints as the
|
|
@@ -819,6 +850,36 @@ is separated from direct-Anthropic totals while still priced against the Anthrop
|
|
|
819
850
|
that Foundry bills at. `AsyncAnthropicFoundry` is metered the same way, as is
|
|
820
851
|
`client.messages.stream()`.
|
|
821
852
|
|
|
853
|
+
#### Google Cloud (Anthropic managed)
|
|
854
|
+
|
|
855
|
+
Claude reached through your Google Cloud project with the Anthropic SDK's Google Cloud
|
|
856
|
+
client (anthropic 2.4.0 or later) is metered by the same patched endpoints, with no extra setup.
|
|
857
|
+
|
|
858
|
+
```python
|
|
859
|
+
import anthropic
|
|
860
|
+
import revenium_middleware.anthropic
|
|
861
|
+
|
|
862
|
+
# Detected from the client class, so a custom base_url is fine too
|
|
863
|
+
client = anthropic.AnthropicGoogleCloud(
|
|
864
|
+
project="your-project",
|
|
865
|
+
location="global",
|
|
866
|
+
workspace_id="your-workspace-id",
|
|
867
|
+
)
|
|
868
|
+
|
|
869
|
+
message = client.messages.create(
|
|
870
|
+
model="claude-opus-4-7",
|
|
871
|
+
max_tokens=100,
|
|
872
|
+
messages=[{"role": "user", "content": "Hello from Google Cloud!"}]
|
|
873
|
+
)
|
|
874
|
+
```
|
|
875
|
+
|
|
876
|
+
Google Cloud usage is reported with provider `Google` and model source `ANTHROPIC`, the
|
|
877
|
+
values the Node SDK sends for Google-billed Claude, because Google Cloud Marketplace bills
|
|
878
|
+
these calls. `AsyncAnthropicGoogleCloud` is metered the same way, as is
|
|
879
|
+
`client.messages.stream()`. A spending cap scoped to the `Google` provider counts these
|
|
880
|
+
calls; one scoped to `ANTHROPIC` does not. Claude through the older `AnthropicVertex`
|
|
881
|
+
client is still reported with provider `ANTHROPIC`.
|
|
882
|
+
|
|
822
883
|
**Examples:** `examples/anthropic/` - `anthropic-basic.py`, `anthropic-streaming.py`, `anthropic-bedrock.py`, `anthropic-advanced.py`
|
|
823
884
|
|
|
824
885
|
---
|
|
@@ -1018,6 +1079,10 @@ except calls a spending cap refuses.
|
|
|
1018
1079
|
pip install "revenium-python-sdk[litellm-proxy]" # requires Python 3.10+
|
|
1019
1080
|
```
|
|
1020
1081
|
|
|
1082
|
+
The extra requires **LiteLLM 1.94.0 or newer**. On LiteLLM 1.93.x the proxy cannot
|
|
1083
|
+
load the guardrail from the config below: it only looks for a module file beside
|
|
1084
|
+
`config.yaml` and stops with `Could not find module file`.
|
|
1085
|
+
|
|
1021
1086
|
```yaml
|
|
1022
1087
|
guardrails:
|
|
1023
1088
|
- guardrail_name: "revenium"
|
|
@@ -1065,7 +1130,7 @@ the call proceeds, and it proceeds without waiting. The pre-call check reads the
|
|
|
1065
1130
|
rules the SDK already has cached and refreshes them on a background thread, so a
|
|
1066
1131
|
Revenium endpoint that hangs, refuses connections, returns errors or rejects your
|
|
1067
1132
|
key (403) neither blocks nor slows the proxy. A failed refresh is retried once
|
|
1068
|
-
per `REVENIUM_CB_POLL_INTERVAL_SECONDS
|
|
1133
|
+
per `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s), not once per request. Right after the
|
|
1069
1134
|
proxy starts, before the first rules fetch completes, no rules are cached and
|
|
1070
1135
|
calls go through; see [Fail-Open vs Fail-Closed](#fail-open-vs-fail-closed).
|
|
1071
1136
|
Metering is likewise non-disruptive — nothing in the post-call path can turn a
|
|
@@ -1263,7 +1328,7 @@ Blank or unset means on; `true`, `1`, `yes`, `on` mean on; any other value turns
|
|
|
1263
1328
|
New calls go straight back to two records when you do; records already merged stay
|
|
1264
1329
|
merged. Four things have to be true for it to work:
|
|
1265
1330
|
|
|
1266
|
-
* **LiteLLM 1.
|
|
1331
|
+
* **LiteLLM 1.94.0 or newer.** That is the floor of the `litellm-proxy` extra, which
|
|
1267
1332
|
is what installs the guardrail. On an older LiteLLM the guardrail logs one warning
|
|
1268
1333
|
at startup and behaves exactly as it does when opted out: no header is added,
|
|
1269
1334
|
the provider's response id is reported, and you get two records rather than none.
|
|
@@ -1759,6 +1824,8 @@ characters, and `product_name` at 224. Other text fields are sent as given.
|
|
|
1759
1824
|
| `response_quality_score` | Custom quality rating (0.0-1.0) | Track user satisfaction or automated quality metrics for model performance analysis |
|
|
1760
1825
|
| `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 |
|
|
1761
1826
|
| `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
|
+
| `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 |
|
|
1762
1829
|
|
|
1763
1830
|
**Example:**
|
|
1764
1831
|
|
|
@@ -1810,6 +1877,18 @@ underscores is left off the record with a WARNING, and the call is still
|
|
|
1810
1877
|
recorded. It is sent on completions only; image, video and audio calls ignore
|
|
1811
1878
|
it, and the LiteLLM proxy does not read it.
|
|
1812
1879
|
|
|
1880
|
+
**Claude Code cloud session and inference geography:** `ccr_session_id` records
|
|
1881
|
+
the Claude Code cloud session a completion ran in, and `inference_geo` records
|
|
1882
|
+
where the provider says the inference ran. Both are values you supply per call;
|
|
1883
|
+
the SDK does not read them from the environment or from the provider response.
|
|
1884
|
+
`inference_geo` is sent exactly as given, with no lowercasing or allow-list;
|
|
1885
|
+
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
|
|
1887
|
+
for `ccr_session_id`, 16 for `inference_geo`) or holds anything but letters,
|
|
1888
|
+
digits, hyphens and underscores is left off the record with a WARNING, and the
|
|
1889
|
+
call is still recorded. Both are sent on completions only; image, video and
|
|
1890
|
+
audio calls ignore them, and the LiteLLM proxy does not read them.
|
|
1891
|
+
|
|
1813
1892
|
**Deprecation notice:** The legacy field aliases `organizationId`, `organization_id`, `productId`, and `product_id` are accepted by this SDK only as an input-layer convenience and emit a `DeprecationWarning`. The Revenium backend no longer accepts them — they are translated to `organizationName` / `productName` before the wire call. Migrate to `organization_name` / `organizationName` and `product_name` / `productName` now; the input-layer aliases will be removed in the next major release.
|
|
1814
1893
|
|
|
1815
1894
|
**API Reference:** [Complete metadata field documentation](https://revenium.readme.io/reference/meter_ai_completion)
|
|
@@ -2183,7 +2262,7 @@ Block outbound provider requests client-side when a Revenium cost control trips.
|
|
|
2183
2262
|
|
|
2184
2263
|
> **Terminology note:** The customer-facing entity is called a **cost control**, served by the backend at `/v2/api/ai/cost-controls`. This SDK polls a separate compiled-rules feed at `/v2/api/ai/enforcement-rules/{teamId}` and is unaffected by changes to the CRUD path — no SDK upgrade is required.
|
|
2185
2264
|
|
|
2186
|
-
Every provider middleware checks the cap: OpenAI, Azure OpenAI, Anthropic (including Claude on Bedrock and
|
|
2265
|
+
Every provider middleware checks the cap: OpenAI, Azure OpenAI, Anthropic (including Claude on Bedrock, Foundry and Google Cloud), Google Gemini and Vertex AI, Ollama, Perplexity, fal, the LiteLLM client and proxy, and the LangChain callback.
|
|
2187
2266
|
|
|
2188
2267
|
### Enable
|
|
2189
2268
|
|
|
@@ -2206,7 +2285,7 @@ REVENIUM_ENFORCEMENT_BASE_URL=https://api.revenium.ai/profitstream # optional:
|
|
|
2206
2285
|
| `REVENIUM_BYPASS` | `false` | When `true`, every `check_enforcement` call short-circuits to a no-op. Useful for incident response. |
|
|
2207
2286
|
| `REVENIUM_TEAM_ID` | — | Hashed team ID. Path component on rule fetches; required when the breaker is enabled. |
|
|
2208
2287
|
| `REVENIUM_ENFORCEMENT_BASE_URL` | `https://api.revenium.ai/profitstream` | Base URL for the enforcement API, taken as given. When unset it is the address outcomes and jobs use (`REVENIUM_PROFITSTREAM_BASE_URL`, else the Revenium address `REVENIUM_METERING_BASE_URL` or `initialize_metering(base_url=...)` sits under, without its `/meter` segment) plus `/profitstream`. A rules fetch that answers 404 is retried once at the same address with `/profitstream` removed, or added if it was missing, and the address that answers with rules is used from then on, so a self-hosted server that serves the API at the root, or a value set without `/profitstream`, still reaches the rules. |
|
|
2209
|
-
| `REVENIUM_CB_POLL_INTERVAL_SECONDS` | `
|
|
2288
|
+
| `REVENIUM_CB_POLL_INTERVAL_SECONDS` | `30` | Seconds between background rule refreshes, and the wait before a failed refresh is retried. Whole seconds from a minimum of `5` to a maximum of `3600`: a lower value is raised to `5` with one warning per process start, and a higher one is capped at `3600`. Anything other than plain digits after trimming spaces (a sign, a decimal point, other text), an empty value and `0` use the default. Read once when polling starts, so a change takes effect when the process restarts. While calls are arriving, rules older than 120 seconds are refreshed on the next call whatever the interval, so a value above `120` only spaces out refreshes on an idle process and the retry after a failed refresh. |
|
|
2210
2289
|
| `REVENIUM_CB_FAIL_MODE` | `open` | `open` (default) lets calls through when no cache exists; `closed` raises `BudgetExceededError` until rules are loaded. |
|
|
2211
2290
|
| `REVENIUM_CACHE_DIR` | unset | When set, the rule cache is mirrored to `<dir>/revenium_enforcement_rules.<scope>.json` so a restarted process doesn't fail-closed on the very first call. `<scope>` is a short hash of the enforcement base URL and `REVENIUM_TEAM_ID`, so services for different teams can share one folder and each loads only its own rules. Nothing is saved without `REVENIUM_TEAM_ID`. |
|
|
2212
2291
|
|
|
@@ -2226,7 +2305,7 @@ client = openai.OpenAI()
|
|
|
2226
2305
|
The pre-call check fires before every call these middlewares meter, including streamed, raw-response, beta and async variants and calls selective metering leaves unmetered:
|
|
2227
2306
|
|
|
2228
2307
|
- OpenAI and Azure OpenAI: chat completions, responses, embeddings and audio.
|
|
2229
|
-
- Anthropic, including Claude on Bedrock (`AnthropicBedrock`, and raw boto3 calls with `REVENIUM_BEDROCK_TRANSPORT=1`), Claude on Vertex AI (`AnthropicVertex`) and
|
|
2308
|
+
- Anthropic, including Claude on Bedrock (`AnthropicBedrock`, and raw boto3 calls with `REVENIUM_BEDROCK_TRANSPORT=1`), Claude on Vertex AI (`AnthropicVertex`), Foundry and Google Cloud (`AnthropicGoogleCloud`): `messages.create`, `stream` and `parse`, and their beta twins.
|
|
2230
2309
|
- Google: google-genai content, embeddings, Imagen and Veo, and Vertex AI generation, chat, embeddings and Imagen.
|
|
2231
2310
|
- Ollama: chat, generate, embed and embeddings.
|
|
2232
2311
|
- Perplexity: the native client and the OpenAI-compatible client.
|
|
@@ -2239,9 +2318,9 @@ LangChain embeddings models run no callbacks: `OpenAIEmbeddings` and `AzureOpenA
|
|
|
2239
2318
|
When the circuit breaker is disabled, it is a no-op. When enabled:
|
|
2240
2319
|
|
|
2241
2320
|
1. A daemon thread (`revenium-enforcement-poll`) starts on first use.
|
|
2242
|
-
2. It polls `GET {REVENIUM_ENFORCEMENT_BASE_URL}/v2/api/ai/enforcement-rules/{REVENIUM_TEAM_ID}` every `REVENIUM_CB_POLL_INTERVAL_SECONDS` with the `x-api-key` header.
|
|
2321
|
+
2. It polls `GET {REVENIUM_ENFORCEMENT_BASE_URL}/v2/api/ai/enforcement-rules/{REVENIUM_TEAM_ID}` every `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s) with the `x-api-key` header.
|
|
2243
2322
|
3. Rules are cached in-process. The pre-call check only reads that cache: it never makes a network request and never sleeps, so it is safe on an event loop (LiteLLM proxy, `AsyncOpenAI`). When the cache is more than 120 s old the check wakes the poller to refresh it early and carries on with the rules it has. Only one refresh runs at a time per process.
|
|
2244
|
-
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
|
|
2323
|
+
4. A refresh that fails (timeout, refused connection, 5xx, or any 4xx such as a 403 for a wrong key or team id) keeps the cached rules, logs a warning, and is not retried for one `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s), however much traffic arrives meanwhile. A 4xx answer the SDK does not retry (any but 408 and 429) is logged at WARNING with the URL and the status, so a wrong address (404) or a wrong key or team id (401, 403) is visible without debug logging.
|
|
2245
2324
|
5. `204 No Content` is treated as "no rules configured" — the cache is cleared.
|
|
2246
2325
|
|
|
2247
2326
|
A rule with filters (a cap scoped to an agent, model, provider, subscriber, credential, task type, product or organization) blocks or warns only the calls that match all of them; a filter the SDK cannot evaluate, such as the model of a LiteLLM proxy request, keeps the rule applying.
|
|
@@ -2349,7 +2428,7 @@ for budget in budgets or []:
|
|
|
2349
2428
|
|
|
2350
2429
|
Each row has `source` `ANOMALY` and `action` `NOTIFY`, groups by `SUBSCRIBER` with a per-person `groupBreakdown`, and carries `readingAt` when the current window has a reading. The call returns `[]` when the team has no advisory budgets and `None` when the enforcement API cannot be reached.
|
|
2351
2430
|
|
|
2352
|
-
The background poller is unaffected: it keeps reading the **whole team's** rules every `REVENIUM_CB_POLL_INTERVAL_SECONDS
|
|
2431
|
+
The background poller is unaffected: it keeps reading the **whole team's** rules every `REVENIUM_CB_POLL_INTERVAL_SECONDS` (default 30 s, minimum 5 s). That is deliberate. The server computes the department-budget maps team-wide and attaches them to the team-wide read, so a poll narrowed to a single rule would stop receiving them and department budgets would quietly stop blocking anyone. Narrowing is an explicit, opt-in inspection call and never the refresh.
|
|
2353
2432
|
|
|
2354
2433
|
### End-to-End Example
|
|
2355
2434
|
|
|
@@ -2605,7 +2684,7 @@ timeout raises `ValueError`.
|
|
|
2605
2684
|
| `REVENIUM_WRITE_API_KEY` | - | Primary write-scope key (`rev_sk_`) for the agentic outcomes API (report/amend/history); falls back to `REVENIUM_OUTCOME_API_KEY` (deprecated), then `REVENIUM_METERING_API_KEY` |
|
|
2606
2685
|
| `REVENIUM_OUTCOME_API_KEY` | - | Deprecated fallback name for the write-scope key; used only when `REVENIUM_WRITE_API_KEY` is unset |
|
|
2607
2686
|
| `REVENIUM_PROFITSTREAM_BASE_URL` | same address as `REVENIUM_METERING_BASE_URL` | Agentic outcomes API base URL. Only needed when outcomes live at a different address than usage. By default it follows the `REVENIUM_METERING_BASE_URL` environment variable: a trailing `/meter` is removed and a path prefix is kept. `AgenticOutcomeClient` also follows a usage address set in code with `initialize_metering(base_url=...)` or a `metering_key(..., base_url=...)` block, for its jobs and outcomes as for its usage records, unless this variable or `profitstream_base_url=` sets an outcome address, or `meter_base_url=` names an address other than the one in `REVENIUM_METERING_BASE_URL`. |
|
|
2608
|
-
| `REVENIUM_BEDROCK_DISABLE` | - | Set to `1` to stop Anthropic clients being detected as Bedrock; Foundry detection
|
|
2687
|
+
| `REVENIUM_BEDROCK_DISABLE` | - | Set to `1` to stop Anthropic clients being detected as Bedrock; Foundry and Google Cloud detection are unaffected. Raw boto3 calls metered with `REVENIUM_BEDROCK_TRANSPORT`, and LangChain's `ChatBedrock` and `ChatBedrockConverse`, are recorded as Bedrock |
|
|
2609
2688
|
| `REVENIUM_BEDROCK_TRANSPORT` | - | Set to `1` or `true` to meter Claude models called through a raw `boto3.client("bedrock-runtime")` (`invoke_model`, `invoke_model_with_response_stream`, `converse`, `converse_stream`); other Bedrock models are never metered this way |
|
|
2610
2689
|
| `REVENIUM_BUFFER_MAX_SIZE` | `20000` | Store-and-forward buffer capacity (oldest events evicted when full) |
|
|
2611
2690
|
| `REVENIUM_BUFFER_FLUSH_INTERVAL` | `30` | Seconds between automatic replay attempts for buffered events |
|
|
@@ -2660,7 +2739,7 @@ Per-call `usage_metadata` values take precedence over the `REVENIUM_AGENTIC_JOB_
|
|
|
2660
2739
|
|
|
2661
2740
|
**Debug mode:** Set `REVENIUM_LOG_LEVEL=DEBUG` (or `REVENIUM_DEBUG=true`, which is the same for every integration) to see detailed provider detection, routing decisions, and metering payloads, with credentials, emails and prompt or reply text redacted. Token counts, ids, model names and attribution names still print.
|
|
2662
2741
|
|
|
2663
|
-
**Stop Bedrock detection on Anthropic clients:** Set `REVENIUM_BEDROCK_DISABLE=1` to disable Bedrock auto-detection on Anthropic clients. It does not send your calls to Anthropic directly: an `AnthropicBedrock` call still goes to AWS and is billed by AWS, but is recorded as provider `anthropic` at the Anthropic price. Foundry detection
|
|
2742
|
+
**Stop Bedrock detection on Anthropic clients:** Set `REVENIUM_BEDROCK_DISABLE=1` to disable Bedrock auto-detection on Anthropic clients. It does not send your calls to Anthropic directly: an `AnthropicBedrock` call still goes to AWS and is billed by AWS, but is recorded as provider `anthropic` at the Anthropic price. Foundry and Google Cloud detection are unaffected - a Foundry client is still labelled `Foundry` and a Google Cloud client `Google`. Raw boto3 calls metered with `REVENIUM_BEDROCK_TRANSPORT` and LangChain's `ChatBedrock` and `ChatBedrockConverse` are recorded as Bedrock.
|
|
2664
2743
|
|
|
2665
2744
|
**Check initialization status (Anthropic):** Use `revenium_middleware.anthropic.is_initialized()` to verify setup.
|
|
2666
2745
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "revenium-python-sdk"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.15.0"
|
|
8
8
|
description = "The official Revenium Python SDK — unified AI metering middleware for OpenAI, Anthropic, Google, Ollama, LiteLLM, Perplexity, and fal.ai."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|
|
@@ -110,9 +110,12 @@ litellm = [
|
|
|
110
110
|
# dispatch that meters streamed calls. litellm[proxy] itself requires Python
|
|
111
111
|
# 3.10+, which is why revenium_middleware.litellm.proxy.guardrail carries an
|
|
112
112
|
# import guard for it while the rest of the SDK stays on requires-python >=3.8.
|
|
113
|
+
# 1.94.0 is the first LiteLLM whose config loader (get_instance_fn) imports an
|
|
114
|
+
# installed package: 1.93.x only loads a module file sitting beside config.yaml,
|
|
115
|
+
# so the README's guardrail entry cannot load there.
|
|
113
116
|
litellm-proxy = [
|
|
114
117
|
"wrapt>=1.14.0",
|
|
115
|
-
"litellm[proxy]>=1.
|
|
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,
|
|
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",
|