xAI Grok
Updated
Use xAI Grok as the LLM in a Conversational AI Platform agent.
Preview documentation
xAI provides access to Grok large language models through an OpenAI-compatible chat completions API for conversational AI applications.
Sample configuration
The following example shows how to configure xAI Grok as the agent's LLM when you create or update an agent. For a complete example, see Create an agent and start a session.
xAI Grok supports BYOK only. It isn't available in managed mode. Store your xAI API key in a secret set, and refer to it from the agent. For details, see Use your own provider keys.
from agora_agent import Agent, OpenAI, secret_ref
# client is your configured Agora client
agent = (
Agent(client=client)
.with_stt(...) # configure your ASR vendor
.with_llm(
OpenAI(
api_key=secret_ref("support_prod", "xai"),
vendor="xai",
base_url="https://api.x.ai/v1/chat/completions",
model="grok-4.3",
max_history=32,
failure_message="Please hold on a second.",
system_messages=[
{"role": "system", "content": "You are a friendly support agent for Acme. Keep your answers short."}
],
)
)
.with_tts(...) # configure your TTS vendor
)import { Agent, OpenAI, secretRef } from 'agora-agents';
// client is your configured Agora client
const agent = new Agent({ client })
.withStt(/* configure your ASR vendor */)
.withLlm(
new OpenAI({
apiKey: secretRef('support_prod', 'xai'),
vendor: 'xai',
url: 'https://api.x.ai/v1/chat/completions',
model: 'grok-4.3',
maxHistory: 32,
failureMessage: 'Please hold on a second.',
systemMessages: [
{ role: 'system', content: 'You are a friendly support agent for Acme. Keep your answers short.' },
],
}),
)
.withTts(/* configure your TTS vendor */);// client is your configured Agora client
maxHistory := 32
agent := agentkit.NewAgent(client).
WithStt( /* configure your ASR vendor */ ).
WithLlm(vendors.NewXaiLLM(vendors.XaiLLMOptions{
APIKey: agentkit.SecretRef("support_prod", "xai"),
BaseURL: "https://api.x.ai/v1/chat/completions",
Model: "grok-4.3",
MaxHistory: &maxHistory,
FailureMessage: "Please hold on a second.",
SystemMessages: []map[string]interface{}{
{"role": "system", "content": "You are a friendly support agent for Acme. Keep your answers short."},
},
})).
WithTts( /* configure your TTS vendor */ )Set credential.mode to byok and credential.fields.api_key to a reference to the key. In the following example, the key is stored as xai in the support_prod set:
"llm": {
"credential": {
"mode": "byok",
"fields": {
"api_key": "$secrets.support_prod.xai"
}
},
"vendor": "xai",
"model": "grok-4.3",
"url": "https://api.x.ai/v1/chat/completions",
"max_history": 32,
"failure_message": "Please hold on a second."
}Set the system prompt and the greeting with the agent's instructions and greeting, not in the llm block.
Key parameters
The llm block takes the following fields. In the SDKs, the LLM class sets them from its options. In Python and TypeScript, use the OpenAI-compatible OpenAI class with the vendor set to xai. In Go, use NewXaiLLM, which sets the vendor for you.
vendorstringSet to xai.
credentialobjectSet mode to byok and fields.api_key to a $secrets.<set>.<key> reference to your xAI API key.
modelstringThe Grok model to use. For example, grok-4.3. For available models, refer to the xAI models documentation.
urlstringThe xAI chat completions endpoint. Set to https://api.x.ai/v1/chat/completions.
For complete llm block options, see Create an agent. For more information, refer to the xAI Chat Completions documentation.
