Usage guide
Setup, environment variables, and Python/JavaScript/Go usage examples.
XAILLM
xAI Grok LLM plugin for text and reasoning completions. Wraps the xAI chat completions API (OpenAI-compatible) to integrate Grok models for real-time voice agents. Supports tool/function calling, structured outputs, optional chain-of-thought reasoning, and prompt caching.Constructor
xAI API key. Falls back to the
XAI_API_KEY environment variable when None.Grok model ID. Defaults to
'grok-4-1-fast-non-reasoning'. Other notable IDs: 'grok-4.3' (latest general-purpose, supports reasoning_effort), 'grok-4.20-0309-reasoning', 'grok-4.20-0309-non-reasoning', 'grok-4.20-multi-agent-0309'.xAI API base URL. Defaults to
'https://api.x.ai/v1'. Override for private deployments.Sampling temperature controlling output randomness. Defaults to
0.7. Higher values increase creativity; lower values make output more deterministic.Controls how the model selects tools. Defaults to
'auto'. Other values: 'none', 'required', or a specific tool name dict.Maximum number of tokens the model may generate per response.
None defaults to 1024.Nucleus sampling probability mass.
None uses the model default.Penalises repeated tokens proportional to their frequency. Range
-2.0–2.0; None uses the model default. Cannot be used with reasoning models.Penalises tokens that have already appeared, encouraging topic diversity. Range
-2.0–2.0; None uses the model default. Cannot be used with reasoning models.Fixed integer seed for deterministic sampling.
None disables seeding.Stop sequence string; generation halts when this token is produced.
None disables early stopping. Cannot be used with reasoning models.Opaque end-user identifier forwarded to the API for abuse monitoring.
None omits the field.When
True, allows the model to emit multiple tool calls in a single turn. None uses the model default.Structured-output schema dict (e.g.
{'type': 'json_object'}). None returns plain text.Chain-of-thought depth for models that support it (e.g.
'grok-4.3'). Valid values: 'none', 'low' (default when omitted), 'medium', 'high'. None lets the model decide. Cannot be combined with frequency_penalty, presence_penalty, or stop.Cache key string for prompt caching. Requests with the same key reuse cached KV state to reduce latency and cost.
None disables caching.API service tier for routing and rate-limit bucketing.
None uses the account default.aclose
cancel_current_generation
chat
The conversation history to send to the model.
Optional tool definitions the model may call.
Optional conversational graph guiding the exchange.
LLMResponse: Response chunks produced as the model generates output.
emit
The event to emit.
off
The event the handler was registered for.
The handler to remove.
on
callback is omitted.
The event to listen for.
The handler to invoke when the event is emitted. If
None, a decorator is returned that registers the decorated function.The registered callback when
callback is provided, otherwise a decorator that registers and returns the function it wraps.