# Telemetry

Operations related to post-LLM prompt execution telemetry reporting.

## Report execution telemetry details post-LLM call

`POST /v1/executions/{execution}/telemetry`

Authentication (security requirement alternatives):

```json
[
  {
    "ApiKeyAuth": [],
    "BearerAuth": []
  }
]
```

- ApiKeyAuth: apiKey, header X-Api-Key
- BearerAuth: http (bearer)

Parameters:

- `execution` (path, string, uuid, required)
  Type: string, uuid

Request body: application/json (required)

Type: object

Schema: [PromptExecutionTelemetryPayload](https://api.prompteasy.eu/docs/api/models/promptexecutiontelemetrypayload/index.md)

- `actual_llm_model` (optional)
  Type: string
  
  Actual LLM model name used for completion
  
  maxLength: 64
  
  Example:
  
  ```json
  "gpt-4o"
  ```

- `prompt_tokens` (optional)
  Type: integer
  
  Number of prompt/input tokens used
  
  minimum: 0
  
  Example:
  
  ```json
  1500
  ```

- `completion_tokens` (optional)
  Type: integer
  
  Number of output/completion tokens generated
  
  minimum: 0
  
  Example:
  
  ```json
  300
  ```

- `cached_prompt_tokens` (optional)
  Type: integer
  
  Number of cached prompt tokens
  
  minimum: 0
  
  Example:
  
  ```json
  500
  ```

- `reasoning_tokens` (optional)
  Type: integer
  
  Number of reasoning tokens used
  
  minimum: 0
  
  Example:
  
  ```json
  100
  ```

- `latency_ms` (optional)
  Type: integer
  
  Total request execution duration in milliseconds
  
  minimum: 0
  
  Example:
  
  ```json
  1250
  ```

- `ttft_ms` (optional)
  Type: integer
  
  Time to first token in milliseconds
  
  minimum: 0
  
  Example:
  
  ```json
  200
  ```

- `finish_reason` (optional)
  Type: string
  
  LLM completion finish reason
  
  maxLength: 32
  
  Example:
  
  ```json
  "stop"
  ```

- `status` (optional)
  Type: integer
  
  Execution status (1 = fetched, 2 = completed, 3 = failed)
  
  enum: [1,2,3]
  
  Example:
  
  ```json
  2
  ```

Responses:

- 200: Telemetry recorded successfully

Content type: application/json

Type: object

Schema: [PromptExecutionTelemetryResponse](https://api.prompteasy.eu/docs/api/models/promptexecutiontelemetryresponse/index.md)

- `message` (required)
  Type: string
  
  Example:
  
  ```json
  "Telemetry recorded successfully."
  ```

- `execution_id` (required)
  Type: string, uuid
  
  Example:
  
  ```json
  "018f0000-0000-7000-8000-000000000002"
  ```

- `has_telemetry` (required)
  Type: boolean
  
  Example:
  
  ```json
  true
  ```

- `status` (required)
  Type: integer
  
  Example:
  
  ```json
  2
  ```

- 403: Forbidden

- 404: Not Found

- 422: Unprocessable Entity

Content type: application/json

Type: object

Schema: [ValidationError](https://api.prompteasy.eu/docs/api/models/validationerror/index.md)

- `message` (optional)
  Type: string
  
  Example:
  
  ```json
  "Validation failed"
  ```

- `errors` (optional)
  Reference: [ValidationErrorErrors](https://api.prompteasy.eu/docs/api/models/validationerrorerrors/index.md); Type: object

## Examples

### cURL

```bash
curl -X POST 'https://api.prompteasy.eu/v1/executions/550e8400-e29b-41d4-a716-446655440000/telemetry' \
  -H 'X-Api-Key: YOUR_TOKEN' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "actual_llm_model": "gpt-4o",
  "prompt_tokens": 1500,
  "completion_tokens": 300,
  "cached_prompt_tokens": 500,
  "reasoning_tokens": 100,
  "latency_ms": 1250,
  "ttft_ms": 200,
  "finish_reason": "stop",
  "status": 2
}'
```

### JavaScript

```javascript
const body = `{
  "actual_llm_model": "gpt-4o",
  "prompt_tokens": 1500,
  "completion_tokens": 300,
  "cached_prompt_tokens": 500,
  "reasoning_tokens": 100,
  "latency_ms": 1250,
  "ttft_ms": 200,
  "finish_reason": "stop",
  "status": 2
}`;

const response = await fetch('https://api.prompteasy.eu/v1/executions/550e8400-e29b-41d4-a716-446655440000/telemetry', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_TOKEN',
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "actual_llm_model": "gpt-4o",
  "prompt_tokens": 1500,
  "completion_tokens": 300,
  "cached_prompt_tokens": 500,
  "reasoning_tokens": 100,
  "latency_ms": 1250,
  "ttft_ms": 200,
  "finish_reason": "stop",
  "status": 2
}'''

response = requests.post(
    'https://api.prompteasy.eu/v1/executions/550e8400-e29b-41d4-a716-446655440000/telemetry',
    data=body.encode('utf-8'),
    headers={
        'X-Api-Key': 'YOUR_TOKEN',
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
