---
sidebar:
  hidden: true
title: roboto.domain.actions.stats
---
Action statistics functionality for retrieving invocation metrics.

## Module Contents

### ActionStatsRecord

```python
class roboto.domain.actions.stats.ActionStatsRecord(/, **data: Any)
```

`from roboto.domain.actions import ActionStatsRecord`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/actions/stats.py#L19-L39)

Bases: `pydantic.BaseModel`

Statistical summary of action invocations for a specific action within a time period.

This model represents aggregated invocation counts for a single action, broken down by completion status (completed, failed, queued).

**Parameters**

- **data** (`Any`)

**Attributes**

- **ActionStatsRecord.action_name** (`str`): Name of the action. Action names are unique within an organization.
- **ActionStatsRecord.action_org_id** (`str`): Organization ID that owns the action.
- **ActionStatsRecord.completed_count** (`int`): Number of invocations that completed successfully during the time period.
- **ActionStatsRecord.fail_count** (`int`): Number of invocations that failed during the time period.
- **ActionStatsRecord.queued_count** (`int`): Number of invocations that are currently queued or in progress during the time period.

### get_action_stats()

```python
def roboto.domain.actions.stats.get_action_stats(
    start_time: datetime.datetime,
    end_time: datetime.datetime,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    org_id: Optional[str] = None,
) -> list[ActionStatsRecord]
```

`from roboto.domain.actions.stats import get_action_stats`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/actions/stats.py#L42-L92)

Retrieve action invocation statistics for all actions in an organization.

Fetches aggregated statistics showing invocation counts by status for each action within the specified organization and time range. This provides a high-level view of action usage and success rates across the organization.

**Parameters**

- **org_id** (`Optional[str]`): Organization ID to retrieve statistics for.
- **start_time** (`datetime.datetime`): Start of the time period (inclusive) for which to retrieve statistics.
- **end_time** (`datetime.datetime`): End of the time period (exclusive) for which to retrieve statistics.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): HTTP client for making API requests. If not provided, uses the default client configuration.

**Returns**

- `list[ActionStatsRecord]`: List of ActionStatsRecord objects, one for each action that had invocations during the specified time period. Actions with no invocations are not included.

**Raises**

- [`RobotoUnauthorizedException`](/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoUnauthorizedException): The caller is not authorized to access statistics for the specified organization.
- [`RobotoInvalidRequestException`](/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): Invalid time range or organization ID provided.

**Usage**

Get statistics for the last 24 hours:

```python
import datetime
from roboto.domain.actions.stats import get_action_stats
end_time = datetime.datetime.now()
start_time = end_time - datetime.timedelta(days=1)
stats = get_action_stats(start_time, end_time, org_id="og_1234567890abcdef")
for stat in stats:
    print(f"{stat.action_name}: {stat.completed_count} completed, {stat.fail_count} failed")
```
