AIO Commands

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > AI - Artificial Intelligence Commands > AIO. - OpenRouter AI >

AIO Commands

AIO.GetGenStats

Previous Top Next


MiniRobotLanguage (MRL)

 

AIO.GetGenStats

 

Description

 

Queries generation statistics by generation ID. This command retrieves detailed metrics about a previous AI generation, including token usage, costs, latency, and provider information.

 

Syntax

 

AIO.GetGenStats|$$GEN_ID[|$$RET]

 

Parameters

 

$$GEN_ID (Required) - The generation ID from a previous chat session. This ID is typically obtained from response headers or metadata returned by the AIO.Chat command.

 

$$RET (Optional) - Optional variable name to store the JSON response containing the generation statistics. If omitted, the result may be output to the default response channel.

 

Return Value

 

Returns a JSON object containing the following fields:

 

cost - The total cost of the generation (typically in USD)

tokens - Token usage statistics (prompt tokens, completion tokens, total tokens)

latency - Response time metrics (time to first token, total generation time)

provider - Information about the AI provider used (name, model, endpoint)

timestamp - When the generation occurred

status - Completion status of the generation

 

Example

 

The following example demonstrates how to use AIO.GetGenStats to retrieve statistics from a previous chat:

 

' Send a chat message and get the result

AIO.Chat|Hello|$$Result

 

' Get generation ID from response headers (if available)

AIO.GetGenStats|gen_abc123|$$Stats

 

' Display the statistics

DBP.Stats: $$Stats

 

Expected output (formatted JSON):

 

{

 "cost": 0.0021,

 "tokens": {

 "prompt": 15,

 "completion": 42,

 "total": 57

 },

 "latency": {

 "time_to_first_token": 0.35,

 "total_time": 1.24

 },

 "provider": {

 "name": "OpenAI",

 "model": "gpt-4",

 "endpoint": "chat/completions"

 },

 "timestamp": "2026-02-16T11:02:00Z",

 "status": "completed"

}

 

Remarks

 

The generation ID ($$GEN_ID) is typically provided in the response headers or metadata when using AIO.Chat or AIO.Complete commands. Not all providers may expose generation IDs or detailed statistics.

 

Statistics retention depends on the provider and configuration. Some generations may not have statistics available if the retention period has expired or if statistics logging was disabled.

 

See Also

 

AIO.Chat - Sends a chat message to the AI and returns the response

AIO.Complete - Requests a text completion from the AI

DBP.Stats - Displays or logs statistical information