xAI
When using xAI models, llm-exe will make POST requests to https://api.x.ai/v1/chat/completions. All models are supported if you pass xai.chat.v1 as the first argument, and then specify a model in the options.
llm-exe ships typed shorthands for the most common xAI models so you do not have to remember the exact model strings:
| Shorthand | Default model |
|---|---|
xai.chat.v1 | none — set model |
xai.grok-4.3 | grok-4.3 (reasoning model) |
xai.grok-4.20 | grok-4.20-0309-non-reasoning |
xai.grok-4.20-reasoning | grok-4.20-0309-reasoning |
xai.grok-4.5 | grok-4.5 (reasoning model) |
xai.grok-4.6 | grok-4.6 (reasoning model) |
xai.grok-4.7 | grok-4.7 (reasoning model) |
Deprecated shorthands
These shorthands still resolve, but emit a deprecation warning when used. Migrate to xai.grok-4.3 (or another active shorthand above).
| Shorthand | Default model | Status |
|---|---|---|
xai.grok-3 | grok-3 | Retired by xAI on 2026-05-15 — requests are redirected to grok-4.3 |
xai.grok-4-fast | grok-4-fast-non-reasoning | Retired by xAI on 2026-05-15 — requests are redirected to grok-4.3 |
xai.grok-4-1-fast | grok-4-1-fast-non-reasoning | Retired by xAI on 2026-05-15 — requests are redirected to grok-4.3 |
xai.grok-2 | grok-2-latest | No longer served by xAI — requests will fail at the API |
xai.grok-3-mini | grok-3-mini | Delisted by xAI, no published redirect |
xai.grok-4 | grok-4 | Delisted by xAI, no published redirect |
Basic Usage
xAI Chat
const llm = useLlm("xai.chat.v1", {
model: "grok-4.3", // specify a model
});x.ai Chat By Model
const llm = useLlm("xai.grok-4.3", {
// other options,
// no model needed, using grok-4.3
});const llm = useLlm("xai.grok-4.7", {
// other options,
// no model needed, using grok-4.7
});xai.grok-4.3xai.grok-4.20xai.grok-4.20-reasoningxai.grok-4.5xai.grok-4.6xai.grok-4.7xai.grok-3deprecatedxai.grok-4-fastdeprecatedxai.grok-4-1-fastdeprecatedxai.grok-2deprecatedxai.grok-3-minideprecatedxai.grok-4deprecated
Authentication
To authenticate, you need to provide an xAI API Key. You can provide the API key various ways, depending on your use case.
- Pass in as execute options using
xAiApiKey - Pass in as setup options using
xAiApiKey - Use a default key by setting an environment variable of
XAI_API_KEY
Generally you pass the LLM instance off to an LLM Executor and call that. However, it is possible to interact with the LLM object directly, if you wanted.
// call the LLM directly with a prompt
await llm.call(prompt);xAI-Specific Options
In addition to the generic options, the following options are xAI-specific and can be passed in when creating a llm function.
| Option | Type | Default | Description |
|---|---|---|---|
| model | string | — | The model to use. Must be specified when using xai.chat.v1. |
| xAiApiKey | string | undefined | API key for xAI. Optionally can be set using process.env.XAI_API_KEY |
| topP | number | undefined | Maps to top_p. See xAI Docs |
| stopSequences | array | undefined | Maps to stop. See xAI Docs |
| frequencyPenalty | number | undefined | Maps to frequency_penalty. See xAI Docs |
| logitBias | object | undefined | Maps to logit_bias. See xAI Docs |
| useJson | boolean | undefined | When true, sets response_format to json_object |
| effort | string | undefined | Maps to reasoning_effort. Valid values: "minimal", "low", "medium", "high", "xhigh" (grok-4.5 treats "xhigh" as "high"). Only sent for grok-4.3, grok-4.5, grok-4.6 and grok-4.7; on any other model, or for a value outside that list, it is silently dropped. "none" is always dropped: grok-4.5 and later reject it, and although grok-4.3 accepts it (it turns reasoning off), the value list is shared across models. |
effort and xai.grok-4.20-reasoning
xai.grok-4.20-reasoning resolves to grok-4.20-0309-reasoning, which is a reasoning model, but xAI rejects reasoning_effort for it: every value returns a 400 ("does not support parameter reasoningEffort"). So llm-exe drops effort for this shorthand instead of sending it. There is no error or warning. To control reasoning effort, use xai.grok-4.3, xai.grok-4.5, xai.grok-4.6, or xai.grok-4.7.
See xAI API Reference for details on these parameters.
