# get\_\_ai\_llm\_stats

{% hint style="info" %}
This API endpoint is currently available only in the TEST environment. It is not yet available in production.
{% endhint %}

`GET /ai/llm/stats`

*Get AI LLM Statistics*

Retrieve usage statistics for AI/LLM configurations. This endpoint provides comprehensive metrics about API usage, token consumption, and policy enforcement.

**Query Filtering:**

* Optionally filter by `aiLlmId` to get statistics for a specific configuration
* Without filters, returns aggregated statistics across all your accessible configurations

**Metrics Provided:**

* **Total API Calls**: Number of API requests made to the AI provider
* **Total Tokens In**: Tokens consumed in requests
* **Total Tokens Out**: Tokens generated in responses
* **Total LLM Tokens In**: Language model-specific input tokens
* **Total LLM Tokens Out**: Language model-specific output tokens
* **Policy Violations**: Count of policy violations detected
* **Alerts**: Number of alerts triggered
* **Blocks**: Number of blocked requests

**Use Cases:**

* Monitor AI usage and costs
* Track compliance with AI policies
* Analyze token consumption patterns
* Identify potential issues or violations

#### TypeScript Client Library

```typescript
public getAiLlmStats = async (aiLlmId?: string): Promise<AiLlmStatsResponse> => {
  const queryParams = new URLSearchParams();
  if (aiLlmId) {
    queryParams.append('aiLlmId', aiLlmId);
  }
  return this.makeRequest<AiLlmStatsResponse>(
    `ai/llm/stats${queryParams.toString() ? `?${queryParams.toString()}` : ''}`,
    'GET',
    null
  );
};
```

#### Code Samples

{% tabs %}
{% tab title="Shell" %}

```shell
# You can also use wget
curl -X GET https://backend.flashback.tech/ai/llm/stats?aiLlmId=550e8400-e29b-41d4-a716-446655440000 \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}'
```

{% endtab %}

{% tab title="HTTP" %}

```http
GET https://backend.flashback.tech/ai/llm/stats?aiLlmId=550e8400-e29b-41d4-a716-446655440000 HTTP/1.1
Host: backend.flashback.tech
Accept: application/json
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const headers = {
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('https://backend.flashback.tech/ai/llm/stats?aiLlmId=550e8400-e29b-41d4-a716-446655440000',
{
  method: 'GET',
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.get 'https://backend.flashback.tech/ai/llm/stats',
  params: {
  'aiLlmId' => 'string'
}, headers: headers

p JSON.parse(result)
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
headers = {
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

r = requests.get('https://backend.flashback.tech/ai/llm/stats', params={
  'aiLlmId': '550e8400-e29b-41d4-a716-446655440000'
}, headers = headers)

print(r.json())
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

require 'vendor/autoload.php';

$headers = array(
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

try {
    $response = $client->request('GET','https://backend.flashback.tech/ai/llm/stats', array(
        'headers' => $headers,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
```

{% endtab %}

{% tab title="Java" %}

```java
URL obj = new URL("https://backend.flashback.tech/ai/llm/stats?aiLlmId=550e8400-e29b-41d4-a716-446655440000");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("GET", "https://backend.flashback.tech/ai/llm/stats", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}
```

{% endtab %}
{% endtabs %}

#### Parameters <a href="#get__ai_llm_stats-parameters" id="get__ai_llm_stats-parameters"></a>

| Name    | In    | Type   | Required | Description                                  |
| ------- | ----- | ------ | -------- | -------------------------------------------- |
| aiLlmId | query | string | false    | Filter statistics by AI LLM configuration ID |

> Example responses

> 200 Response

```json
{
  "success": true,
  "stats": [
    {
      "aiLlmId": "550e8400-e29b-41d4-a716-446655440000",
      "totalApiCalls": "1523",
      "totalTokensIn": "45678",
      "totalTokensOut": "89012",
      "totalLlmTokensIn": "43210",
      "totalLlmTokensOut": "87654",
      "totalPolicyViolations": "3",
      "totalAlerts": "5",
      "totalBlocks": "2"
    }
  ]
}
```

#### Responses <a href="#get__ai_llm_stats-responses" id="get__ai_llm_stats-responses"></a>

| Status | Meaning                                                                    | Description                       | Schema |
| ------ | -------------------------------------------------------------------------- | --------------------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)                    | Successfully retrieved statistics | Inline |
| 403    | [Forbidden](https://tools.ietf.org/html/rfc7231#section-6.5.3)             | Insufficient permissions          | Inline |
| 500    | [Internal Server Error](https://tools.ietf.org/html/rfc7231#section-6.6.1) | Failed to retrieve statistics     | Inline |

#### Response Schema <a href="#get__ai_llm_stats-responseschema" id="get__ai_llm_stats-responseschema"></a>

Status Code **200**

| Name                     | Type      | Required | Restrictions | Description                         |
| ------------------------ | --------- | -------- | ------------ | ----------------------------------- |
| » success                | boolean   | false    | none         | Operation success status            |
| » stats                  | \[object] | false    | none         | Array of statistics objects         |
| »» aiLlmId               | string    | false    | none         | AI LLM configuration ID             |
| »» totalApiCalls         | string    | false    | none         | Total number of API calls made      |
| »» totalTokensIn         | string    | false    | none         | Total tokens consumed in requests   |
| »» totalTokensOut        | string    | false    | none         | Total tokens generated in responses |
| »» totalLlmTokensIn      | string    | false    | none         | Total LLM-specific input tokens     |
| »» totalLlmTokensOut     | string    | false    | none         | Total LLM-specific output tokens    |
| »» totalPolicyViolations | string    | false    | none         | Total policy violations detected    |
| »» totalAlerts           | string    | false    | none         | Total alerts triggered              |
| »» totalBlocks           | string    | false    | none         | Total requests blocked              |

**Note:** Numeric values are returned as strings to support large numbers without precision loss.

Status Code **403**

| Name      | Type    | Required | Restrictions | Description |
| --------- | ------- | -------- | ------------ | ----------- |
| » success | boolean | false    | none         | none        |
| » message | string  | false    | none         | none        |

Status Code **500**

| Name      | Type    | Required | Restrictions | Description |
| --------- | ------- | -------- | ------------ | ----------- |
| » success | boolean | false    | none         | none        |
| » message | string  | false    | none         | none        |

To perform this operation, you must be authenticated by means of one of the following methods: BearerAuth


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flashback.tech/support-reference/platform-api-reference/ai-apis/ai-llms/get__ai_llm_stats.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
