Skip to content

Commit 929ffc3

Browse files
committed
Add check for limits exceeded in PlaygroundConsumer
1 parent a86b364 commit 929ffc3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

llmstack/server/consumers.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.core.exceptions import PermissionDenied
1111
from django.http import HttpRequest, QueryDict
1212
from django_ratelimit.exceptions import Ratelimited
13+
from flags.state import flag_enabled
1314

1415
from llmstack.connections.actors import ConnectionActivationActor
1516
from llmstack.connections.models import (
@@ -30,6 +31,19 @@ class UsageLimitReached(PermissionDenied):
3031
pass
3132

3233

34+
class OutOfCredits(PermissionDenied):
35+
pass
36+
37+
38+
@database_sync_to_async
39+
def _usage_limit_exceeded(request, user):
40+
return flag_enabled(
41+
"HAS_EXCEEDED_MONTHLY_PROCESSOR_RUN_QUOTA",
42+
request=request,
43+
user=request.user,
44+
)
45+
46+
3347
@database_sync_to_async
3448
def _build_request_from_input(post_data, scope):
3549
session = dict(scope["session"])
@@ -253,6 +267,11 @@ async def connect(self):
253267
def _run_app(self, request_uuid, request, **kwargs):
254268
from llmstack.apps.apis import AppViewSet
255269

270+
if _usage_limit_exceeded(request, self._run_app):
271+
raise OutOfCredits(
272+
"You have exceeded your usage credits. Please add credits to your account from settings to continue using the platform.",
273+
)
274+
256275
return AppViewSet().run_playground_internal_async(
257276
session_id=self._session_id,
258277
request_uuid=request_uuid,

0 commit comments

Comments
 (0)