lucianotonet/groq-php
A PHP SDK for the GroqCloud API that lets developers add fast LLM inference to any PHP app, with chat completions, tool calling, vision, reasoning, audio transcription, text-to-speech, batch processing, and RAG support.
Architecture fit
lucianotonet/groq-php is a framework-agnostic PHP SDK, not a Laravel package. Laravel support is delegated to a separate companion (groq-laravel), which means an integration decision is really two decisions: the SDK (core HTTP/domain logic) and the wrapper (service provider, config, facade).$response['choices'][0]['message']['content']) out of domain code.json_schema, strict), vision, transcription/translation, TTS, files/batch, built-in compound tools, documents/RAG with citations, Responses API, prompt caching, moderation. One dependency can back several product surfaces (support assistant, audio pipeline, document Q&A, extraction jobs), which improves the business case for the onboarding cost.GROQ_API_BASE), so a provider-swap escape hatch exists at the transport layer even though the SDK is Groq-shaped.Integration feasibility
composer require, one env var, one call. A spike can validate the core value in under a day.parallel_tool_calls must currently be forced false; audio response formats exclude vtt/srt; Orpheus TTS caps input at 200 characters and wav only. Each is a product-requirement check, not a blocker per se.Technical risk
composer.json PHP constraint, Laravel version matrix, Guzzle major-version compatibility against our existing lockfile.ob_flush()/flush().Key questions
GroqException? Can we distinguish 429 / 5xx / 400 validation / content-policy failures without string matching?max_completion_tokens, response_format strict schema, service tier), or do we need to pass raw arrays through?Stack fit
Groq as a singleton in a dedicated GroqServiceProvider, with config/groq.php reading GROQ_API_KEY / GROQ_API_BASE. Application code should never call getenv() directly — the README's own example does, and that pattern must not propagate.LlmClient, TranscriptionClient) that the SDK implements. Provider swaps, model changes, and SDK replacement then become a single container binding.response()->stream() for SSE; explicitly disable output buffering and verify through the actual load balancer/CDN, not just locally.Migration path
openai-php pointed at Groq's base URL: the swap is mechanical if the internal interface already exists. Write the adapter first, then replace the implementation — one file changes.groq-laravel wrapper initially. Adding a second low-adoption dependency to save ~40 lines of service-provider code is a poor trade at this maturity level. Revisit the wrapper only if it demonstrably tracks upstream releases.Compatibility
vtt/srt output means subtitle/caption features need our own formatting layer.vision()->analyze(), audio()->speech()), even where the wire format is OpenAI-like.Sequencing
json_schema strict) call and one streaming call. Confirm error taxonomy. Exit criterion: go/no-go on constraints.usage tokens, and a per-tenant rate budget.Maintenance
Support
Scaling
usage per request, set budget alerts per tenant, tier models deliberately (small model for classification, reasoning model for hard cases), and use prompt caching on stable system prompts.Failure modes
| Mode | Signal | Mitigation |
|---|---|---|
| Rate limit (429) | Exception + Groq headers | Exponential backoff, queue, degrade to fallback provider |
| Timeout / 5xx | Guzzle exception | Retry idempotent reads only; never retry tool side effects |
| Stream breakage | Truncated SSE, buffered output | Explicit no-buffer headers, LB test, non-streaming fallback |
| Malformed JSON despite strict schema | Parse failure | Defensive parse + single repair retry, then fail cleanly |
| Tool-call loop | Repeated tool_calls |
Max-iteration guard, allowlist, sandboxed side effects |
| Model retired | 400/404 at runtime | Model IDs in config, startup validation job, alert on failure rate |
| Package abandoned | No releases | Adapter boundary + MIT fork option |
Ramp-up
How can I help you explore Laravel packages today?