Skip to main content

Documentation 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.

GroqProvider (namespace AiSdk\Groq) is the concrete provider object that backs the Groq facade. It is returned by Groq::create() and holds the resolved GroqOptions for the lifetime of the provider instance. While most applications interact with the Groq facade rather than GroqProvider directly, working with GroqProvider directly gives you full control: you can create multiple independent provider instances with different API keys, base URLs, or custom headers within the same process.
In the majority of applications you will not need to instantiate or reference GroqProvider directly. Use the Groq facade’s static methods — Groq::create(), Groq::model() — and let the facade manage the provider for you.

Constructor

new GroqProvider(GroqOptions $options)

Constructs a provider from an already-built GroqOptions value object. In practice, you will most often obtain a GroqProvider through Groq::create(), which calls GroqOptions::fromArray() internally and passes the result here.
Constructing a GroqProvider directly
use AiSdk\Groq\GroqOptions;
use AiSdk\Groq\GroqProvider;

$options  = new GroqOptions(apiKey: 'gsk-...');
$provider = new GroqProvider($options);
options
GroqOptions
required
A fully constructed GroqOptions instance carrying the API key, base URL, extra headers, and optional custom SDK. See the GroqOptions reference for all available fields.

Properties

$options

public readonly GroqOptions $options
The GroqOptions instance supplied at construction time. Because it is readonly, the reference cannot be replaced after construction, but you can read any field from it at any time.
Reading resolved options
use AiSdk\Groq;

$provider = Groq::create(['apiKey' => 'gsk-...']);

echo $provider->options->baseUrl; // https://api.groq.com/openai/v1

Methods

name()

Returns the canonical provider identifier string used internally by the SDK to tag requests, errors, and capability lookups.
Checking the provider name
use AiSdk\Groq;

$provider = Groq::default();

echo $provider->name(); // "groq"
returns
string
Always 'groq' — the value of GroqOptions::PROVIDER_NAME.

textModel()

Creates and returns a GroqTextModel for the given model ID. The returned object implements TextModelInterface and can be passed directly to Generate::text()->model(...).
Creating a text model from the provider
use AiSdk\Generate;
use AiSdk\Groq\GroqOptions;
use AiSdk\Groq\GroqProvider;

$provider = new GroqProvider(new GroqOptions(apiKey: 'gsk-...'));

$result = Generate::text()
    ->model($provider->textModel('llama-3.3-70b-versatile'))
    ->prompt('What is the speed of light?')
    ->run();

echo $result->text;
modelId
string
required
The Groq model identifier (e.g. 'llama-3.3-70b-versatile', 'llama-4-scout-17b-16e-instruct'). The value is passed through to the underlying GroqTextModel without validation; an invalid ID will produce an API-level error when the model is invoked.
returns
TextModelInterface
A GroqTextModel instance implementing AiSdk\Contracts\TextModelInterface. The model captures the provider’s GroqOptions and the resolved model registry so that capability checks and HTTP requests are fully configured.

Using multiple providers

Because GroqProvider is a plain object, you can hold multiple instances simultaneously — useful when your application needs to fan out requests across different Groq API keys or route to a proxy for specific environments:
Multiple independent providers
use AiSdk\Generate;
use AiSdk\Groq\GroqOptions;
use AiSdk\Groq\GroqProvider;

$primary = new GroqProvider(new GroqOptions(
    apiKey: getenv('GROQ_API_KEY_PRIMARY'),
));

$fallback = new GroqProvider(new GroqOptions(
    apiKey:  getenv('GROQ_API_KEY_FALLBACK'),
    baseUrl: 'https://proxy.example.com/groq/v1',
));

// Route to primary; fall back on exception.
try {
    $result = Generate::text()
        ->model($primary->textModel('llama-3.3-70b-versatile'))
        ->prompt('Hello!')
        ->run();
} catch (\Throwable $e) {
    $result = Generate::text()
        ->model($fallback->textModel('llama-3.3-70b-versatile'))
        ->prompt('Hello!')
        ->run();
}
When using a single global provider, prefer the Groq facade over managing a GroqProvider instance yourself. The facade’s lazy-singleton pattern means you get the same object on every call without any manual wiring.

Build docs developers (and LLMs) love