lucianotonet/groq-php
PHP client for the Groq API. Provides a simple, lightweight way to call Groq LLM endpoints from PHP apps, with support for common chat/completions workflows and easy integration into existing projects.
Start by installing the package via Composer: composer require lucianotonet/groq-php. Next, configure your Groq API key in .env as GROQ_API_KEY=.... In Laravel, the client can be resolved via the service container (app(\LucianoTonet\Groq\GroqClient::class)) or bound manually. The first use case is typically chat completions — create a message payload and send it to a model like llama-3-8b-8192:
$client = app(\LucianoTonet\Groq\GroqClient::class);
$response = $client->chat()->create([
'model' => 'llama-3-8b-8192',
'messages' => [['role' => 'user', 'content' => 'Hello, Groq!']],
]);
echo $response->content(); // convenience method for text extraction
Check the examples/ folder in the repo for quick integration patterns.
GroqClient as a singleton in AppServiceProvider or use Laravel’s built-in binding via with() in config/app.php for type-hinted injection.GroqClient::chat()->withSystemPrompt(...) and withTools(...) for structured, reusable message templates — avoids repetitive array construction.ChatCompletion to access choices, usage stats, and token counts safely (e.g., $response->usage()->totalTokens).GroqClient in unit tests; the client’s interface (GroqClientInterface) simplifies swapping in fakes or stubs with given() scenarios.llama3-70b-8192) or store them in config (config(groq.models.chat)) to avoid runtime failures on API upgrades.usage() info for monitoring and fallback logic.id or created timestamp to avoid duplicate calls.\LucianoTonet\Groq\Exceptions\GroqException (not generic \Exception) to distinguish API errors (e.g., rate limits) from local bugs. Use $exception->response() to inspect raw HTTP response for debugging.How can I help you explore Laravel packages today?