🚀 Available for Freelance, Remote, and Full-Time Opportunities. Let's build something amazing together.

News
1 min read

Laravel AI: Get Raw HTTP Responses and Rate Limits

Inspect provider response headers, token usage quotas, and raw JSON payloads directly through the Laravel AI HTTP client.

A

Author

6 days ago

Inspecting HTTP Headers & Quotas in Laravel AI

Debugging AI model integrations requires visibility into low-level HTTP responses, rate limit reset times, and exact token counts returned by providers like OpenAI, Anthropic, and Ollama.

use Laravel\AI\Facades\AI;

$response = AI::agent('coder')
    ->prompt('Write a PHP regex pattern for emails')
    ->withRawResponse()
    ->run();

$statusCode = $response->status(); // 200
$remainingRequests = $response->header('x-ratelimit-remaining-requests');
$tokenUsage = $response->usage();