xAI

Updated

Use xAI for text-to-speech (TTS) in a Conversational AI Platform agent.

Preview documentation

You're reading the Conversational AI Platform (Preview) docs. Switch to Main.

xAI provides text-to-speech (TTS) with a range of expressive voices for conversational AI applications.

Sample configuration

The following example shows how to configure xAI as the agent's TTS when you create or update an agent. For a complete example, see Create an agent and start a session.

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.

from agora_agent import Agent, XaiTTS, secret_ref

# client is your configured Agora client
agent = (
    Agent(client=client)
    .with_stt(...)  # configure your ASR vendor
    .with_llm(...)  # configure your LLM vendor
    .with_tts(
        XaiTTS(
            api_key=secret_ref("support_prod", "xai"),
            voice_id="eve",
            language="en",
            sample_rate=16000,
        )
    )
)
import { Agent, XAiTTS, secretRef } from 'agora-agents';

// client is your configured Agora client
const agent = new Agent({ client })
  .withStt(/* configure your ASR vendor */)
  .withLlm(/* configure your LLM vendor */)
  .withTts(
    new XAiTTS({
      apiKey: secretRef('support_prod', 'xai'),
      voiceId: 'eve',
      language: 'en',
      sampleRate: 16000,
    }),
  );
sampleRate := vendors.SampleRate16kHz
// client is your configured Agora client
agent := agentkit.NewAgent(client).
	WithStt( /* configure your ASR vendor */ ).
	WithLlm( /* configure your LLM vendor */ ).
	WithTts(vendors.NewXaiTTS(vendors.XaiTTSOptions{
		APIKey:     agentkit.SecretRef("support_prod", "xai"),
		VoiceID:    "eve",
		Language:   "en",
		SampleRate: &sampleRate,
	}))

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:

"tts": {
  "credential": {
    "mode": "byok",
    "fields": {
      "api_key": "$secrets.support_prod.xai"
    }
  },
  "vendor": "xai",
  "params": {
    "voice_id": "eve",
    "language": "en",
    "sample_rate": 16000
  }
}

Key parameters

The tts block takes the following fields. In the SDKs, the xAI TTS class sets them from its options.

tts
vendorstring
required

Set to xai.

credentialobject
required

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

paramsobject
required
voice_idstring
optional

The voice to use for speech synthesis. For voice IDs and samples, refer to the xAI documentation.

languagestring
required

The BCP-47 language code for speech synthesis. For example, use en for English. For supported language codes, refer to the xAI documentation.

sample_rateinteger
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 Text to Speech documentation.

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.