The Groq provider is configured through theDocumentation 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.
GroqOptions class, which is constructed automatically when you call Groq::create(). Every option can be supplied either as a PHP array passed to Groq::create() or as an environment variable, so you can keep secrets out of your codebase and switch environments without touching application code.
Environment Variables
The simplest way to configure the provider is via environment variables. Set them once in your.env file or server environment, and the provider picks them up automatically — no code changes needed between environments.
| Variable | Description | Default |
|---|---|---|
GROQ_API_KEY | Your Groq API key (begins with gsk-). Required — the provider will throw if this is absent and no apiKey was passed programmatically. | (none — required) |
GROQ_BASE_URL | Override the API base URL. Useful for proxies or local mock servers. Trailing slashes are stripped automatically. | https://api.groq.com/openai/v1 |
.env
Programmatic Configuration
Pass a configuration array toGroq::create() when you need runtime control — for instance, when loading credentials from a secrets manager or when writing tests that inject a custom HTTP client.
Programmatic setup
Programmatic values take precedence over environment variables. If you pass
apiKey directly, GROQ_API_KEY is ignored for that instance.Configuration Parameters
Your Groq API key. All keys issued by Groq begin with the prefix
gsk-. When omitted from the array, the provider reads the GROQ_API_KEY environment variable. An exception is thrown at construction time if neither source provides a value.The base URL for all API requests. The provider strips any trailing slash before use. Override this when routing traffic through a proxy, a gateway, or a local mock server. Falls back to the
GROQ_BASE_URL environment variable if the key is absent from the config array.An associative array of additional HTTP headers merged into every request alongside the
Authorization header. Use this for tracing identifiers, organisation IDs, or any other per-request metadata your infrastructure requires. Keys and values must both be strings.An optional
AiSdk\Support\Sdk instance. Inject a custom HTTP client here to intercept or mock outbound requests in tests. When null, the provider constructs its own default HTTP client.Setting a Global Default
Groq::create() stores the resulting provider in a static $default property and returns it. Every subsequent call to Groq::model() resolves against that default — so you only need to call Groq::create() once, typically in your application bootstrap.
Bootstrap (e.g. AppServiceProvider)
Anywhere in the application
Resetting the Default (Useful in Tests)
The staticGroq::reset() method sets $default back to null. The next call to Groq::model() or Groq::default() will then either trigger auto-creation from environment variables or throw if none are set.
PHPUnit tearDown
Full Configuration Example
The example below shows all four options used together. Thesdk parameter receives a mock HTTP client so no real network calls are made during tests.
Full example with all options