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.
GroqTextModel is the low-level driver that executes text generation against Groq’s OpenAI-compatible /chat/completions endpoint. It is instantiated by GroqProvider::textModel() (and by the Groq::model() facade shorthand) and is the object you pass to the Generate fluent builder’s ->model() call. The class resolves capability metadata from a custom ModelRegistry when one is present, falling back to the built-in ModelCatalog loaded from the bundled resources/models.json file. For models that do not natively support the json_schema response format, it transparently rewrites the request body to json_object and injects a system-level JSON instruction, so callers never need to branch on provider limitations themselves.
Class reference
Namespace:AiSdk\Groq\ModelsImplements:
TextModelInterfaceExtends:
BaseModelPackage:
aisdk/groq
Public methods
provider()
Returns the canonical provider name string used throughout the SDK.
Checking the provider name
Always returns
'groq'.modelId()
Returns the model identifier string that was supplied at construction time.
Reading back the model ID
The exact model ID string passed to
Groq::model() or GroqProvider::textModel().capabilities()
Returns the full list of capabilities that the model supports or has adapted support for.
Resolution order:
- A custom
ModelRegistryentry registered viaGroq::registerModel(), if one exists for this model ID. - The built-in
ModelCatalogsourced fromresources/models.json.
Listing all capabilities of a model
An array of
AiSdk\Capability enum cases representing every capability the model exposes (including adapted ones).capability()
Returns a detailed CapabilitySupport object that describes exactly how a single capability is supported — fully, via an adaptation, or not at all.
Resolution order:
- Any capability forced via
->assume()or->allowUnknownCapabilities()on the model handle (inherited fromBaseModel). - A custom
ModelRegistryentry for this model ID. - The built-in
ModelCatalog. - Special fallback: if the capability is
TextGenerationand the model is entirely unknown to both the registry and the catalog, returnsSupportedwith source'unknown-model-fallback'.
The
AiSdk\Capability enum case to look up — e.g. Capability::StructuredOutput, Capability::ImageInput, Capability::ToolCalling.A
CapabilitySupport value object with the following properties:| Property | Type | Description |
|---|---|---|
->state | CapabilitySupportState | Supported, Adapted, or NotSupported |
->strategy | string | Human-readable explanation of the adaptation (empty string when not adapted) |
->source | string | Where the support declaration came from (e.g. 'model-catalog', 'user-assumed', 'unknown-model-fallback') |
Inspecting structured output support
->supports(Capability $c): bool is a convenience method inherited from BaseModel that returns true when the capability state is either Supported or Adapted.generate()
Sends a synchronous POST request to /chat/completions and returns a fully-resolved TextModelResponse.
The assembled request object produced by the
Generate fluent builder. Contains messages, optional tool definitions, response format, and generation parameters.A value object with:
| Property | Type | Description |
|---|---|---|
->text | string | The model’s text reply |
->usage | TokenUsage | ->inputTokens and ->outputTokens |
->output | mixed | Decoded JSON when a structured output schema was requested |
->providerMetadata | array | Raw Groq response fields keyed under 'groq' (e.g. id, model, choice_finish_reason) |
Generating text with the Groq provider
stream()
Sends a streaming POST request to /chat/completions with stream: true and yields text chunks as a Generator. The ChatStreamParser reads server-sent events and emits each decoded delta string.
Same request object as
generate(). The streaming flag is set internally before the request is sent.Yields
string chunks as they arrive from the API. Each yielded value is a decoded content delta from one SSE event.Streaming a response chunk by chunk
Structured output adaptation
Several Groq-hosted models do not support the OpenAIjson_schema response format natively. GroqTextModel detects this at request time and applies a transparent two-step adaptation so callers can use Schema::object() with any model:
- Format rewrite —
response_format.typeis changed fromjson_schematojson_object. - Instruction injection — The string
"Respond only with a valid JSON object that matches the requested schema."is injected as a system message. If a system message already exists, the instruction is appended to its content with a blank line separator.
Structured output with automatic json_object adaptation
| Model | StructuredOutput state |
|---|---|
llama-3.1-8b-instant | Adapted (json_object rewrite) |
llama-3.3-70b-versatile | NotSupported |
meta-llama/llama-4-scout* | NotSupported |
meta-llama/llama-4-maverick* | NotSupported |
moonshotai/kimi* | Supported |
openai/gpt-oss-20b | Supported |
openai/gpt-oss-120b | Supported |
Working with custom and unknown models
Registering a custom model
UseGroq::registerModel() to declare capabilities for a model not listed in the bundled catalog. The registered definition is consulted before the catalog on every capability lookup.
Registering a custom fine-tuned model
Assuming capabilities on the fly
For a model handle you do not want to register globally,->assume() (inherited from BaseModel) injects specific capabilities into the handle without touching the registry.
Assuming capabilities for a single handle
Bypassing all capability checks
->allowUnknownCapabilities() marks the model handle as permissive — every capability lookup returns Supported regardless of what the catalog says.
Allowing all capabilities for experimental use
Unknown model fallback
If a model ID is not found in either the registry or the catalog,capability(Capability::TextGeneration) still returns Supported with source 'unknown-model-fallback'. All other capabilities return NotSupported unless overridden with ->assume() or ->allowUnknownCapabilities().
Unknown models always allow basic text generation
Error handling
| HTTP status | SDK exception |
|---|---|
429 | AiSdk\Exceptions\RateLimitException |
4xx / 5xx | AiSdk\Exceptions\ProviderException |
| Capability not declared | AiSdk\Exceptions\CapabilityNotSupportedException |
Catching a rate limit error