Scope3AI Reference
The Scope3AI class is the central interface for tracking and analyzing the environmental impact of AI model interactions. It provides methods for tracing and logging interactions, as well as calculating key sustainability metrics like energy usage and emissions.
Core features: - Initialization with customizable tracking parameters - Context management for measuring impact across multiple interactions - Synchronous and asynchronous impact calculation modes - Metadata support for session, environment and project tracking
scope3ai.lib.Scope3AI
Scope3AI tracer class
This class is a singleton that provides a context manager for tracing inference metadata and submitting impact requests to the Scope3 AI API.
Methods:
-
asubmit_impact–Async version of Scope3AI::submit_impact.
-
get_instance–Return the instance of the Scope3AI singleton.
-
init–Initialize the Scope3AI SDK with the provided configuration settings.
-
submit_impact–Submit an impact request to the Scope3 AI API.
Attributes:
-
current_tracer–Return the current tracer.
-
root_tracer–Return the root tracer.
current_tracer
property
Return the current tracer.
The current tracer is the last tracer in the current execution context (tracer stack). If no tracers are currently active, it returns None.
Returns:
-
Tracer–The current tracer if available, otherwise None.
root_tracer
property
Return the root tracer.
The root tracer is the first tracer in the current execution context (tracer stack). If no tracers are currently active, it returns None.
Returns:
-
Tracer–The root tracer if available, otherwise None.
asubmit_impact
async
asubmit_impact(impact_row: ImpactRow) -> Scope3AIContext
Async version of Scope3AI::submit_impact.
get_instance
classmethod
get_instance() -> Scope3AI
Return the instance of the Scope3AI singleton.
This method provides access to the default global state of the Scope3AI library. The returned instance can be used to trace inference metadata and submit impact requests to the Scope3 AI API from anywhere in the application.
Returns:
-
Scope3AI(Scope3AI) –The singleton instance of the Scope3AI class.
init
classmethod
init(api_key: Optional[str] = None, api_url: Optional[str] = None, sync_mode: bool = False, enable_debug_logging: bool = False, provider_clients: Optional[List[str]] = None, environment: Optional[str] = None, client_id: Optional[str] = None, project_id: Optional[str] = None, application_id: Optional[str] = None) -> Scope3AI
Initialize the Scope3AI SDK with the provided configuration settings.
Parameters:
-
(api_keystr, default:None) –The Scope3AI API key. Can be set via
SCOPE3AI_API_KEYenvironment variable. Required for authentication. -
(api_urlstr, default:None) –The base URL for the Scope3AI API. Can be set via
SCOPE3AI_API_URLenvironment variable. Defaults to standard API URL. -
(sync_modebool, default:False) –If True, the SDK will operate synchronously. Can be set via
SCOPE3AI_SYNC_MODEenvironment variable. Defaults to False. -
(enable_debug_loggingbool, default:False) –Enable debug level logging. Can be set via
SCOPE3AI_DEBUG_LOGGINGenvironment variable. Defaults to False. -
(clientsList[str]) –List of provider clients to instrument. If None, all available provider clients will be instrumented.
-
(environmentstr, default:None) –The environment name (e.g. "production", "staging"). Can be set via
SCOPE3AI_ENVIRONMENTenvironment variable. -
(client_idstr, default:None) –Client identifier for grouping traces. Can be set via
SCOPE3AI_CLIENT_IDenvironment variable. -
(project_idstr, default:None) –Project identifier for grouping traces. Can be set via
SCOPE3AI_PROJECT_IDenvironment variable. -
(application_idstr, default:None) –Application identifier. Can be set via
SCOPE3AI_APPLICATION_IDenvironment variable. Defaults to "default".
Returns:
-
Scope3AI(Scope3AI) –The initialized Scope3AI instance.
Raises:
-
Scope3AIError–If the instance is already initialized or if required settings are missing.
submit_impact
submit_impact(impact_row: ImpactRow) -> Scope3AIContext
Submit an impact request to the Scope3 AI API.
This function sends an impact request represented by the impact_row
to the Scope3 AI API and optionally returns the response.
Parameters:
-
(impact_rowImpactRow) –The impact request data that needs to be submitted to the Scope3 AI API.
Returns:
-
Scope3AIContext(Scope3AIContext) –A context object containing the request data and
-
Scope3AIContext–the response from the API.