This guide takes you from zero to a working Groq-powered PHP application. By the end you will have installed the package, authenticated with the Groq API, generated text, and seen a streaming response — all using the same fluentDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/groq/llms.txt
Use this file to discover all available pages before exploring further.
Generate interface shared across every provider in the PHP AI SDK.
Install the package
Require
aisdk/groq via Composer. It automatically pulls in aisdk/core and aisdk/openai-compatible.Terminal
Set your API key
The provider reads your key from the
GROQ_API_KEY environment variable by default. Get a free key from console.groq.com under API Keys..env
Generate text
Use The
Generate::text() to send a prompt and read the response. The ->model() call accepts any Groq::model() handle.generate.php
$result object exposes both the generated text and token-usage information:usage.php
Set a default model
If your application always uses the same model, register it once with
Generate::model(). Every subsequent Generate::text() call skips the ->model() step.bootstrap.php
anywhere-in-your-app.php
Provider Metadata
Every completed response includes aproviderMetadata map keyed by provider name. The groq key holds response-level details returned by the Groq API:
metadata.php
choice_finish_reason can be "stop" (natural end), "tool_calls" (model invoked a tool), "length" (context limit reached), or "content_filter". Check this field if you suspect truncation.Next Steps
Configuration
Customise the base URL, inject headers, and register models that aren’t in the catalogue yet.
Text Generation Guide
Deep-dive into system instructions, tool calling, and structured output with schemas.
Models Overview
See every supported Groq model, its context window, and its capability flags.
API Reference
Full reference for the
Groq facade, GroqProvider, GroqOptions, and response types.