From 62dbf7b37bc9007f9fb69babb368b9396755dec4 Mon Sep 17 00:00:00 2001 From: Christian Gick Date: Fri, 3 Apr 2026 12:54:05 +0300 Subject: [PATCH] feat: show budget limit message with MatrixHost link instead of generic error Co-Authored-By: Claude Opus 4.6 (1M context) --- bot.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bot.py b/bot.py index bcfcd4f..5664417 100644 --- a/bot.py +++ b/bot.py @@ -15,6 +15,7 @@ import docx import fitz # pymupdf import httpx from openai import AsyncOpenAI +import openai as _openai from olm import sas as olm_sas import olm.pk import canonicaljson @@ -3298,6 +3299,20 @@ class Bot: await self._auto_rename_room(room, user_message, reply) return reply + except _openai.APIStatusError as e: + body = getattr(e, "body", None) or {} + msg = body.get("message", "") if isinstance(body, dict) else str(body) + if "BudgetGuard" in msg or "exceed budget" in msg: + logger.warning("LLM budget exceeded: %s", msg) + portal = PORTAL_URL.rstrip("/") + await self._send_text( + room.room_id, + f"⚠️ AI budget limit reached. Please check your plan at {portal}/settings/billing", + ) + else: + logger.exception("LLM API error") + await self._send_text(room.room_id, "Sorry, I couldn't generate a response.") + return None except Exception: logger.exception("LLM call failed") await self._send_text(room.room_id, "Sorry, I couldn't generate a response.")