Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
AIRequestLog
n/a
0 / 0
n/a
0 / 0
0
n/a
0 / 0
1<?php
2
3namespace App\Http\Models\FlyMsgAI;
4
5use App\Http\Models\Moloquent;
6
7/**
8 * Represents a logged AI API request.
9 *
10 * Stored in the `ai_request_logs` MongoDB collection.
11 *
12 * @property string $user_id The authenticated user's ID
13 * @property string|null $company_id The user's company ID (if applicable)
14 * @property string $feature Feature that triggered the request (engage_generate, post_generate, rewrite, check_sentences, persona_generate)
15 * @property string $provider AI provider used (vertex, gpt, claude, grok)
16 * @property string $model Model identifier (e.g. gemini-3.1-flash-lite-preview)
17 * @property string $prompt_input The full prompt sent to the AI
18 * @property string|null $prompt_output The AI-generated response text
19 * @property mixed|null $context Additional context data for the request
20 * @property string $status Request status: pending | success | error
21 * @property int|null $execution_duration_ms Total AI API execution time in milliseconds
22 * @property int $prompt_tokens Estimated or actual number of input tokens
23 * @property int $completion_tokens Estimated or actual number of output tokens
24 * @property int $total_tokens Total tokens (prompt + completion)
25 * @property float $estimated_cost_usd Estimated cost in USD based on token counts and model pricing
26 * @property float|null $temperature Temperature setting requested for this call
27 * @property float|null $top_p Top-P sampling setting requested for this call
28 * @property int|null $max_tokens Max output tokens requested for this call
29 * @property int|null $thinking_budget Thinking-token budget requested for this call
30 * @property bool|null $enable_google_search Whether Google Search grounding was enabled
31 * @property string|null $prompt_id ID of the ai_prompts record whose config was used
32 * @property bool $regenerated Whether this log was created by re-executing a previous request
33 * @property string|null $regenerated_from_id The ID of the original log entry that was re-executed
34 */
35class AIRequestLog extends Moloquent
36{
37    protected $table = 'ai_request_logs';
38
39    protected $fillable = [
40        'user_id',
41        'company_id',
42        'feature',
43        'provider',
44        'model',
45        'prompt_input',
46        'prompt_output',
47        'context',
48        'status',
49        'execution_duration_ms',
50        'prompt_tokens',
51        'completion_tokens',
52        'total_tokens',
53        'estimated_cost_usd',
54        'temperature',
55        'top_p',
56        'max_tokens',
57        'thinking_budget',
58        'enable_google_search',
59        'prompt_id',
60        'regenerated',
61        'regenerated_from_id',
62    ];
63
64    protected $casts = [
65        'execution_duration_ms' => 'integer',
66        'prompt_tokens' => 'integer',
67        'completion_tokens' => 'integer',
68        'total_tokens' => 'integer',
69        'estimated_cost_usd' => 'float',
70        'temperature' => 'float',
71        'top_p' => 'float',
72        'max_tokens' => 'integer',
73        'thinking_budget' => 'integer',
74        'enable_google_search' => 'boolean',
75        'regenerated' => 'boolean',
76        'created_at' => 'datetime',
77        'updated_at' => 'datetime',
78    ];
79}