xAI Grok
GrokLLMService streams chat completions from xAI Grok through its OpenAI-compatible API.
Overview
xAI's Grok models.
GrokLLMService: anOpenAILLMServicesubclass with xAI Grok's base URL and default model.
Upstream page
Pipecat's documentation for the same service.
Source
packages/xai/src/llm.ts.
xAI docs
The chat completions API reference.
Installation
bun add @pipedog/xaiIt depends on @pipedog/openai, which is installed with it.
import { GrokLLMService } from "@pipedog/xai/llm";Prerequisites
- An xAI account and an API key from the xAI console.
- Pass the key as
apiKey. It is required, and the service never falls back toOPENAI_API_KEY. The examples read it fromXAI_API_KEY.
GrokLLMService
Configuration
Prop
Type
The other options (organization, project, defaultHeaders, serviceTier,
retryOnTimeout, retryTimeoutSecs, function calling) are OpenAILLMService's. See
OpenAI.
| Base URL | https://api.x.ai/v1 |
| Default model | grok-4.20-non-reasoning |
| Models to try | grok-4.20-non-reasoning, grok-4.6. See the provider's catalog for the rest. |
Settings
Runtime-updatable settings, passed as settings: new GrokLLMService.Settings({...})
(GrokLLMSettings). They are OpenAI's settings, with these
defaults:
| Setting | Type | Default | Description |
|---|---|---|---|
model | string | "grok-4.20-non-reasoning" | Model name. |
reasoningEffort | "none" | "low" | "medium" | "high" | "xhigh" | null | null | Sent as reasoning_effort when set, unless extra already has one. The non-reasoning models, including the default, reject it. |
Every other setting keeps OpenAI's default. Unset sampling settings are left out of the request, so
the provider's own defaults apply. extra carries provider-specific request fields.
Usage
import { LLMUpdateSettingsFrame } from "@pipedog/core/frames/frames";
import { GrokLLMService } from "@pipedog/xai/llm";
const llm = new GrokLLMService({
apiKey: process.env.XAI_API_KEY ?? "",
settings: new GrokLLMService.Settings({
model: "grok-4.20-non-reasoning",
systemInstruction: "You are a helpful assistant in a voice conversation.",
temperature: 0.7,
}),
});A reasoning model, with its reasoning effort:
const reasoning = new GrokLLMService({
apiKey: process.env.XAI_API_KEY ?? "",
settings: new GrokLLMService.Settings({ model: "grok-4.6", reasoningEffort: "low" }),
});Change settings mid-call with an LLMUpdateSettingsFrame. The next completion uses them:
// Queue it on the worker, or push it from a processor upstream of the service.
const update = new LLMUpdateSettingsFrame({
delta: new GrokLLMService.Settings({ temperature: 0.2, maxTokens: 300 }),
});Notes
- Runs a completion for each
LLMContextFrame, between anLLMFullResponseStartFrameand anLLMFullResponseEndFrame, and streams the reply asLLMTextFrames, asOpenAILLMServicedoes. Function calls, token usage metrics andrunInferencework the same way. - "developer" messages are sent as is: the API supports that role.
- xAI reports reasoning tokens apart from
completion_tokens, so they are added to the completion count in token usage metrics when the total says so. @pipedog/grokre-exportsGrokLLMServicefrom@pipedog/xai/llm, as upstream's deprecatedpipecat.services.grok.llmdoes. Import from@pipedog/xai/llm.- The same package has xAI's speech-to-text and text-to-speech services, and Grok Voice Agent, the realtime (speech-to-speech) service.
Runtime notes
| Runtime | Works | What it needs |
|---|---|---|
| Bun | ✅ yes | Nothing. |
| Node.js | ✅ yes | Nothing. |
| Deno | ✅ yes | Nothing. |
| Cloudflare Workers | ✅ yes | Nothing. |
Generated from pipecat.runtimes and pipecat.compat in packages/xai/package.json: ✅ means the compat smoke test passes on that runtime.
- The client is the official
openaiJS SDK (through@pipedog/openai), which talks throughfetch. It works on Bun, Node, Deno and Cloudflare Workers. - The deprecated
modelconstructor option is not ported. Usesettings. - Tested against a local OpenAI-compatible mock server, not against xAI Grok itself.
pipedog is an unofficial community TypeScript port of Pipecat. It is not affiliated with or endorsed by Daily or the Pipecat project.
Portions adapted from the Pipecat documentation, Copyright (c) 2024–2025 Daily, BSD-2-Clause (see apps/docs/LICENSE-pipecat-docs).