Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/phpaisdk/xai/llms.txt

Use this file to discover all available pages before exploring further.

Grok’s reasoning mode instructs the model to think through a problem before producing a final response, trading higher token usage for better accuracy on complex tasks. The aisdk/xai provider exposes this through the portable Reasoning::effort() helper, which maps directly onto the reasoning_effort field in the underlying OpenAI-compatible request body.

Enabling Reasoning

Pass a Reasoning::effort() instance to the ->reasoning() builder method on any Generate::text() call. The provider serialises the effort level and forwards it to the xAI API automatically:
use AiSdk\Generate;
use AiSdk\Reasoning;
use AiSdk\XAI;

$result = Generate::text('Explain the tradeoff between latency and throughput.')
    ->model(XAI::model('grok-4'))
    ->reasoning(Reasoning::effort('low'))
    ->run();

echo $result->text;

Effort Levels

The Reasoning::effort() helper accepts one of three string values:
LevelBehaviour
'low'Minimal reasoning steps — fastest response, lowest token cost. Suitable for most everyday tasks.
'medium'Balanced reasoning depth. A good default when you need more careful answers without the full cost of high effort.
'high'Maximum reasoning depth — slowest response, highest token cost. Best reserved for complex multi-step problems, mathematical proofs, or code that requires exhaustive analysis.
These values map directly to the reasoning_effort parameter in the OpenAI-compatible request body sent to xAI. The test suite confirms this mapping:
// From XAITextTest.php — after calling ->reasoning(Reasoning::effort('low'))
expect($client->sentBody()['reasoning_effort'])->toBe('low');

Supported Models

Reasoning is available on models that declare the reasoning capability in resources/models.json:
Model patternReasoning support
grok-4* (e.g. grok-4, grok-4.3)✅ Yes
grok-3* (e.g. grok-3, grok-3-mini)✅ Yes
grok-2* (e.g. grok-2-vision)❌ No
The grok-2* family does not list the reasoning capability in the model catalog. Passing ->reasoning() to a grok-2 model will be ignored or may produce an API error — use grok-3* or grok-4* for reasoning tasks.
Use low effort for the vast majority of tasks — it is significantly cheaper in tokens and still produces high-quality answers for most questions. Reserve high for genuinely complex problems such as multi-step mathematical reasoning, intricate code generation, or tasks where accuracy is more important than speed.

Build docs developers (and LLMs) love