| name | klingai-usage-analytics |
| description | Build usage analytics and reporting for Kling AI video generation. Use when tracking patterns,
analyzing costs, or building dashboards. Trigger with phrases like 'klingai analytics',
'kling ai usage report', 'klingai metrics', 'video generation stats'.
|
| allowed-tools | Read, Write, Edit, Bash(npm:*), Grep |
| version | 1.18.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","kling-ai","analytics","reporting"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Kling AI Usage Analytics
Overview
Track video generation usage with structured logging, aggregate metrics, daily reports, and cost analysis. Built on JSONL event logs that can feed into any analytics platform.
Event Logger
import json
import time
from datetime import datetime
from pathlib import Path
class KlingEventLogger:
"""Append-only JSONL event log for Kling AI operations."""
def __init__(self, log_dir: str = "logs"):
self.log_dir = Path(log_dir)
self.log_dir.mkdir(exist_ok=True)
def _write(self, event: dict):
date = datetime.utcnow().strftime("%Y-%m-%d")
filepath = self.log_dir / f"kling-{date}.jsonl"
event["timestamp"] = datetime.utcnow().isoformat()
with open(filepath, "a") as f:
f.write(json.dumps(event) + "\n")
def log_submission(self, task_id, prompt, model, duration, mode):
self._write({
"event": "task_submitted",
"task_id": task_id,
"model": model,
"duration": int(duration),
"mode": mode,
: (prompt),
})
():
._write({
: ,
: task_id,
: status,
: elapsed_sec,
: credits_used,
})
():
._write({
: ,
: task_id,
: error_type,
: message[:],
})