v2.3.6-1778780128
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.
Basic Usage
xAI Chat
ts
const llm = useLlm("xai.chat.v1", {
model: "grok-4", // specify a model
});x.ai Chat By Model
ts
const llm = useLlm("xai.grok-4", {
// other options,
// no model needed, using grok-4
});ts
const llm = useLlm("xai.grok-3-mini", {
// other options,
// no model needed, using grok-3-mini
});INFO
You can use the following models using this shorthand:
xai.grok-2xai.grok-3xai.grok-3-minixai.grok-4xai.grok-4-fast
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.
ts
// 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". |
See xAI API Reference for details on these parameters.
