Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llmcosts/tracker/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ def _check_triggered_thresholds(
client_key=self._client_customer_key,
)

# If the mocked client returns a non-dict (e.g., MagicMock),
# fallback to an empty result to avoid errors during testing.
if not isinstance(result, dict):
return {"status": "no_client", "allowed": True, "violations": []}

# Log warnings for alerts
if result.get("warnings"):
logging.warning("⚠️ Triggered threshold ALERT detected:")
Expand Down Expand Up @@ -514,13 +519,15 @@ def __init__(
callback_func,
kw,
attr,
base_url,
):
self._response = response
self._tracker_func = tracker_func
self._usage_handler = usage_handler
self._callback_func = callback_func
self._kw = kw
self._attr = attr
self._base_url = base_url
self._stream = None
self._iterator = None

Expand Down Expand Up @@ -581,6 +588,7 @@ def _create_tracking_iterator(self, stream):
self._call_response_callback,
kw,
attr,
self._base_url,
)
else:
# Return a regular generator for non-context manager responses (like completions)
Expand Down