# xAI (/en/ai/platform/models/asr/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 real-time automatic speech recognition (ASR) over WebSocket for conversational AI applications.

## Sample configuration

The following example shows how to configure xAI as the agent's ASR 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 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, XaiSTT, secret_ref

# client is your configured Agora client
agent = (
    Agent(client=client)
    .with_stt(
        XaiSTT(
            api_key=secret_ref("support_prod", "xai"),
            language="en",
            base_url="wss://api.x.ai/v1/stt",
            sample_rate=16000,
        )
    )
    .with_llm(...)  # configure your LLM vendor
    .with_tts(...)  # configure your TTS vendor
)
```

**TypeScript SDK**

```ts
import { Agent, XAiSTT, secretRef } from 'agora-agents';

// client is your configured Agora client
const agent = new Agent({ client })
  .withStt(
    new XAiSTT({
      apiKey: secretRef('support_prod', 'xai'),
      language: 'en',
      baseUrl: 'wss://api.x.ai/v1/stt',
      sampleRate: 16000,
    }),
  )
  .withLlm(/* configure your LLM vendor */)
  .withTts(/* configure your TTS vendor */);
```

**Go SDK**

```go
sampleRate := vendors.SampleRate16kHz

// client is your configured Agora client
agent := agentkit.NewAgent(client).
	WithStt(vendors.NewXaiSTT(vendors.XaiSTTOptions{
		APIKey:     agentkit.SecretRef("support_prod", "xai"),
		Language:   "en",
		BaseURL:    "wss://api.x.ai/v1/stt",
		SampleRate: &sampleRate,
	})).
	WithLlm( /* configure your LLM vendor */ ).
	WithTts( /* configure your TTS vendor */ )
```

**REST API**

Set `credential.mode` to `byok` and `credential.fields.api_key` to a reference to your xAI API key in a secret set. In the following example, the key is stored as `xai` in the `support_prod` set:

```json
"asr": {
  "credential": {
    "mode": "byok",
    "fields": {
      "api_key": "$secrets.support_prod.xai"
    }
  },
  "vendor": "xai",
  "language": "en",
  "url": "wss://api.x.ai/v1/stt",
  "params": {
    "sample_rate": 16000
  }
}
```

## Key parameters

The `asr` block takes the following fields. In the SDKs, `XaiSTT` sets them from its options, and passes any other xAI parameters from its additional parameters option to `params`.

**asr required**

**`vendor` (string) required**

Set to `xai`.

**`credential` (object) required**

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

**`language` (string) optional**

The language code to use for transcription. For example, use `en` for English. Setting this enables text formatting of numbers, currencies, and units. For supported language codes, refer to the [xAI documentation](https://docs.x.ai/developers/model-capabilities/audio/speech-to-text#supported-languages).

**`url` (string) optional**

The WebSocket endpoint URL for the xAI streaming STT API. Defaults to `wss://api.x.ai/v1/stt`.

**`params` (object) optional**

**`sample_rate` (integer) optional**

The audio sample rate in Hz. Supported values: `8000`, `16000`, `22050`, `24000`, `44100`, `48000`.

> **Caution**
>
> The parameters listed on this page are validated for use with the Conversational AI Platform. Required parameters must be provided as documented. Any additional parameters in `params` are passed through directly to xAI without validation. For a full list of supported options, refer to the [xAI Speech to Text documentation](https://docs.x.ai/developers/model-capabilities/audio/speech-to-text#streaming-speech-to-text-websocket).

This integration is fully supported for use with the Conversational AI Platform. While it has completed functional validation, it is newer to the platform, and additional provider-specific edge cases may be identified as usage scales across a broader range of applications and workloads.
