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.
GroqOptions (namespace AiSdk\Groq) is an immutable value object that carries all configuration for a GroqProvider instance. Every field is declared readonly, so the object acts as a snapshot of provider settings from the moment it is constructed. You can build a GroqOptions directly via its constructor or — more commonly — via the static fromArray() factory, which also reads GROQ_API_KEY and GROQ_BASE_URL from the environment as fallbacks.
Constants
| Constant | Value | Description |
|---|---|---|
GroqOptions::DEFAULT_BASE_URL | 'https://api.groq.com/openai/v1' | The production Groq REST API endpoint used when no base URL is specified. |
GroqOptions::PROVIDER_NAME | 'groq' | The canonical provider identifier used internally across the SDK for capability lookup, request tagging, and error messages. |
Constructor
new GroqOptions(...)
Builds an options object from explicit values. All parameters except apiKey have sensible defaults.
Constructing GroqOptions directly
Your Groq API key. The key is sent as a
Bearer token in the Authorization header on every request. It must be non-empty; an empty string will cause GroqOptions::fromArray() to throw before the object is constructed.The base URL prepended to all API paths. Defaults to
GroqOptions::DEFAULT_BASE_URL. Useful when routing through an OpenAI-compatible proxy or a local mock server. Trailing slashes are stripped by fromArray() but not by the constructor — prefer fromArray() to normalise the value.Extra HTTP headers merged into every outbound request via
authHeaders(). The Authorization header is always appended automatically and must not be included here.An optional
AiSdk\Support\Sdk instance that controls the HTTP transport layer. Pass a custom Sdk to inject a test double or pre-configured HTTP client. When null, the default transport is used.Static factory
GroqOptions::fromArray()
Builds a GroqOptions from a plain associative array, falling back to environment variables for apiKey and baseUrl. This is the factory used internally by Groq::create().
Building from an array with env-var fallback
An associative array mirroring the constructor parameters. Accepted keys:
apiKey, baseUrl, headers, sdk. Unknown keys are silently ignored.A fully constructed, immutable
GroqOptions instance.Environment variable fallback
fromArray() applies the following resolution order for each setting:
| Setting | Resolution order |
|---|---|
apiKey | $config['apiKey'] → GROQ_API_KEY env var → exception if both missing |
baseUrl | $config['baseUrl'] → GROQ_BASE_URL env var → DEFAULT_BASE_URL |
headers | $config['headers'] → [] |
sdk | $config['sdk'] (must be a Sdk instance) → null |
Setting environment variables
Instance method
authHeaders()
Returns the complete set of HTTP headers to attach to every API request, combining the Authorization bearer token with any extra headers supplied at construction time.
Inspecting auth headers
An associative array of HTTP header name → value pairs.
Authorization is always the first entry; additional headers from the constructor follow in the order they were provided.authHeaders() is called by GroqTextModel automatically before every HTTP request. You do not need to call it yourself unless you are building a custom transport or debugging outbound headers.Complete configuration example
Full configuration with all options