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.

The Groq facade (namespace AiSdk) is the primary entry point for the Groq provider package. It manages a lazily-created singleton GroqProvider instance so that most applications need only a single line of setup — or no setup at all when GROQ_API_KEY is present in the environment. All methods are static, making the facade convenient to call from anywhere in your codebase without dependency injection.

Methods

Groq::create()

Creates a new GroqProvider from a configuration array and registers it as the package-wide default. Any subsequent call to Groq::default() or Groq::model() will use this provider until Groq::reset() is called.
Creating a provider explicitly
use AiSdk\Groq;

$provider = Groq::create([
    'apiKey'  => 'gsk-...',
    'baseUrl' => 'https://api.groq.com/openai/v1',
    'headers' => ['X-Request-ID' => 'my-app'],
]);
config
array
default:"[]"
An associative array of provider options. All keys are optional when the corresponding environment variable is set. Accepted keys:
returns
GroqProvider
The newly created GroqProvider instance, which has also been set as the current default.

Groq::default()

Returns the current default GroqProvider. If no provider has been created yet, it calls Groq::create() with an empty config array, which resolves credentials from environment variables.
Accessing the default provider
use AiSdk\Groq;

// Automatically reads GROQ_API_KEY from the environment.
$provider = Groq::default();

$model = $provider->textModel('llama-3.3-70b-versatile');
You rarely need to call Groq::default() directly. Groq::model() calls it internally and is the more ergonomic option for most use cases.
returns
GroqProvider
The existing default provider, or a freshly created one if none has been set.

Groq::model()

Resolves a text model by its Groq model ID using the default provider. This is the canonical way to obtain a TextModelInterface ready to be passed to Generate::text().
Resolving a model and generating text
use AiSdk\Generate;
use AiSdk\Groq;

$result = Generate::text()
    ->model(Groq::model('llama-3.3-70b-versatile'))
    ->prompt('Explain closures in PHP.')
    ->run();

echo $result->text;
modelId
string
required
The Groq model identifier, such as 'llama-3.3-70b-versatile', 'llama-4-scout-17b-16e-instruct', or any other model available on your Groq account. Unknown model IDs are allowed — the provider will surface the API error at call time.
returns
TextModelInterface
A GroqTextModel instance implementing AiSdk\Contracts\TextModelInterface, ready for use with Generate::text().

Groq::reset()

Clears the default provider singleton, setting it back to null. The next call to Groq::default() or Groq::model() will create a fresh provider.
Resetting between tests
use AiSdk\Groq;

afterEach(function () {
    Groq::reset();
});
Groq::reset() is intended for use in tests. Calling it in production code will cause the next model call to re-read environment variables and create a new provider, which may have unexpected side effects if Groq::create() was called with explicit configuration earlier in the request lifecycle.
returns
void

Groq::registerModel()

Registers a custom model definition on the default provider’s model registry. Use this to add new or preview Groq models at runtime without waiting for a package release. The method is provided by the RegistersModels trait. Two calling conventions are supported: Terse form — pass a string model ID and a capability array:
Registering a model with the terse form
use AiSdk\Capability;
use AiSdk\Groq;

Groq::registerModel('llama-5-70b', capabilities: [
    Capability::TextGeneration,
    Capability::Streaming,
    Capability::ToolCalling,
    Capability::StructuredOutput,
    Capability::TextInput,
]);
Full form — pass a ModelDefinition object for fine-grained control over adapted capabilities and metadata:
Registering a model with a ModelDefinition
use AiSdk\Groq;
use AiSdk\ModelDefinition;

Groq::registerModel(
    new ModelDefinition(
        id: 'llama-5-70b',
        capabilities: [...],
    )
);
model
string|ModelDefinition
required
Either the string model ID (used with the capabilities array) or a fully constructed ModelDefinition object.
capabilities
array
default:"[]"
An array of AiSdk\Capability enum cases describing what the model supports. Only used when $model is a string; ignored when a ModelDefinition is passed.
returns
void
Use the terse form for the vast majority of registrations. Reach for ModelDefinition only when you need to mark specific capabilities as Adapted rather than natively supported.

Build docs developers (and LLMs) love