The API
Web app and Chrome extension talk to the same API
One endpoint, one set of rules: the plan limit is checked, the session and memory are attached, the model answers and the reply is logged.
api/app/Http/Controllers/Api/ChatController.phpLaravel · PHP 8.2+
// POST /api/v1/chat/reply (auth:sanctum) public function reply(ReplyRequest $request) { $user = $request->user(); $quota = $user->subscription->plan->message_limit; if (UsageLog::countThisMonth($user) >= $quota) { return response()->json([ 'error' => 'plan_limit_reached', 'plan' => $user->subscription->plan->name, ], 429); } $session = $user->sessions()->findOrFail($request->session); $reply = Model::active($request->model)->ask( $session->history(), $user->memory->facts(), // carried between chats $request->message, ); UsageLog::record($user, $request->model); return new ReplyResource($reply); }
What one message goes through
The extension and the web app use this endpoint.
Sent from the Chrome extensionSanctum token; device on the accountExtension
Plan limit checked1,948 of 4,000 messages usedPlus
Session and memory attachedThis session and 4 stored factsMemory
The chosen model repliesMust be switched on by the admin1.1 s
One row added to usage logsThe user and the model+1
usage_logs · new row
SAVED- User
- Rohan Mehta
- Model
- yap-deep
- Used / limit
- 1,949 / 4,000
- Status
- Inside the plan