Cost dashboard: TTS providers endpoint, header link, polish
Adds /api/costs/tts endpoint backed by get_tts_providers() in cost_db, surfaces a Costs link in the control panel header, and small polish to the costs page HTML/JS. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10354,6 +10354,11 @@ async def get_cost_expensive_calls(period: str = "all", limit: int = 10):
|
||||
return cost_db.get_expensive_calls(period, limit)
|
||||
|
||||
|
||||
@app.get("/api/costs/tts")
|
||||
async def get_cost_tts_providers(period: str = "all"):
|
||||
return cost_db.get_tts_providers(period)
|
||||
|
||||
|
||||
# --- Caller Screening ---
|
||||
|
||||
SCREENING_PROMPT = """You are a friendly, brief phone screener for "Luke at the Roost" radio show.
|
||||
|
||||
@@ -500,6 +500,27 @@ def get_session_detail(session_id: str) -> dict | None:
|
||||
}
|
||||
|
||||
|
||||
def get_tts_providers(period: str = "all") -> list[dict]:
|
||||
conn = get_db()
|
||||
start = _period_filter(period)
|
||||
if start:
|
||||
rows = conn.execute(
|
||||
"SELECT t.provider, COUNT(*) as calls, COALESCE(SUM(t.cost), 0) as cost, "
|
||||
"COALESCE(SUM(t.char_count), 0) as chars "
|
||||
"FROM tts_calls t JOIN sessions s ON t.session_id = s.id "
|
||||
"WHERE s.started_at >= ? GROUP BY t.provider ORDER BY cost DESC",
|
||||
[start]
|
||||
).fetchall()
|
||||
else:
|
||||
rows = conn.execute(
|
||||
"SELECT provider, COUNT(*) as calls, COALESCE(SUM(cost), 0) as cost, "
|
||||
"COALESCE(SUM(char_count), 0) as chars "
|
||||
"FROM tts_calls GROUP BY provider ORDER BY cost DESC"
|
||||
).fetchall()
|
||||
return [{"provider": r["provider"], "calls": r["calls"],
|
||||
"cost": round(r["cost"], 4), "chars": r["chars"]} for r in rows]
|
||||
|
||||
|
||||
def get_expensive_calls(period: str = "all", limit: int = 20) -> list[dict]:
|
||||
conn = get_db()
|
||||
start = _period_filter(period)
|
||||
|
||||
Reference in New Issue
Block a user