# getApiUsage

This method allows you to retrieve Linked API usage statistics so you can monitor your limits and stay within their [recommended values](/guides/understanding-linkedin-limits).

> In addition to monitoring usage, you can configure action limits for each account on the [platform](https://app.linkedapi.io/). When a limit is reached, actions will automatically return a `limitExceeded` error instead of executing.

```typescript
try {
  // Get usage stats for the last 7 days
  const endDate = new Date();
  const startDate = new Date(endDate.getTime() - 7 * 24 * 60 * 60 * 1000);
  
  const { data } = await linkedapi.getApiUsage({
    start: startDate.toISOString(),
    end: endDate.toISOString()
  });

  if (data) {
    console.log('Usage statistics retrieved successfully');
    console.log('Total actions executed:', statsResponse.length);
      
    // Analyze the statistics
    const successfulActions = statsResponse.result?.filter(action => action.success);
    const failedActions = statsResponse.result?.filter(action => !action.success);
    
    console.log('Successful actions:', successfulActions?.length);
    console.log('Failed actions:', failedActions?.length);
  }
} catch (e) {
  // A list of all critical errors can be found here:
  // https://linkedapi.io/sdks/handling-results-and-errors/#handling-critical-errors
  if (e instanceof LinkedApiError) {
    console.error(`Critical Error - Type: ${e.type}, Message: ${e.message}`);
  } else {
    console.error('An unexpected, non-API error occurred:', e);
  }
}
```

```python
from datetime import datetime, timedelta, timezone

from linkedapi import ApiUsageParams, LinkedApiError

try:
    # Get usage stats for the last 7 days
    end_date = datetime.now(timezone.utc)
    start_date = end_date - timedelta(days=7)

    result = linkedapi.get_api_usage(
        ApiUsageParams(
            start=start_date.isoformat(),
            end=end_date.isoformat(),
        )
    )
    data = result.data

    if data:
        print("Usage statistics retrieved successfully")
        print("Total actions executed:", len(data))

        # Analyze the statistics
        successful_actions = [action for action in data if action.success]
        failed_actions = [action for action in data if not action.success]

        print("Successful actions:", len(successful_actions))
        print("Failed actions:", len(failed_actions))
except LinkedApiError as e:
    # A list of all critical errors can be found here:
    # https://linkedapi.io/sdks/handling-results-and-errors/#handling-critical-errors
    print(f"Critical Error - Type: {e.type}, Message: {e.message}")
except Exception as error:
    print("An unexpected, non-API error occurred:", error)
```

## Params

- `start` – timestamp from which the statistics will be retrieved.
- `end` – timestamp up to which the statistics will be retrieved.

> The difference between `start` and `end` must not exceed 30 days.

## Data

Array of [HTTP API actions](/docs/actions-overview). Each action contains:

- `actionType` – type of the action (e.g., `st.sendMessage`, `st.openCompanyPage`).
- `success` – boolean indicating whether the action executed successfully.
- `time` – timestamp when the action was executed.

## Errors

The method has no execution errors (`errors` is always `[]`).
