# xAI Grok (/en/ai/platform/models/llm/xai)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

> Documentation: Conversational AI.
> Documentation version: Preview.
> This document describes only this version. [Version index](/llms/doc-versions-convoai-guides-v2.txt).


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](/en/ai/platform/get-started/start-stop-agent#create-an-agent).

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](/en/ai/platform/build/use-your-own-keys).

**Python SDK**

```python
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
)
```

**TypeScript SDK**

```ts
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 */);
```

**Go SDK**

```go
// 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 */ )
```

**REST API**

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:

```json
"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.

**llm**

**`vendor` (string) required**

Set to `xai`.

**`credential` (object) required**

Set `mode` to `byok` and `fields.api_key` to a `$secrets.<set>.<key>` reference to your xAI API key.

**`model` (string) required**

The Grok model to use. For example, `grok-4.3`. For available models, refer to the [xAI models documentation](https://docs.x.ai/developers/models).

**`url` (string) required**

The xAI chat completions endpoint. Set to `https://api.x.ai/v1/chat/completions`.

For complete `llm` block options, see [Create an agent](/en/api-reference/api-ref/conversational-ai/platform/create-agent). For more information, refer to the [xAI Chat Completions documentation](https://docs.x.ai/developers/model-capabilities/legacy/chat-completions).
