Buckets:

download
raw
1.5 kB
"""
This file contains the handler for xAI's Grok Voice Agent API `/v1/realtime` endpoint.
xAI's Realtime API is fully OpenAI-compatible, so we inherit from OpenAIRealtime
and only override the configuration differences.
This requires websockets, and is currently only supported on LiteLLM Proxy.
"""
from litellm.constants import XAI_API_BASE
from ...openai.realtime.handler import OpenAIRealtime
from .transformation import XAIRealtimeNormalizer
class XAIRealtime(OpenAIRealtime):
"""
Handler for xAI Grok Voice Agent API.
xAI's Realtime API uses the same WebSocket protocol as OpenAI but with:
- Different endpoint: wss://api.x.ai/v1/realtime (via _get_default_api_base)
- No OpenAI-Beta header required (via _get_additional_headers)
- Model: grok-4-1-fast-non-reasoning
All WebSocket logic is inherited from OpenAIRealtime.
"""
def _get_default_api_base(self) -> str:
"""xAI uses a different API base URL."""
return XAI_API_BASE
def _make_event_normalizer(self) -> XAIRealtimeNormalizer:
"""Return a fresh per-session XAI normalizer instance."""
return XAIRealtimeNormalizer()
def _get_additional_headers(
self,
api_key: str,
*,
openai_beta_realtime: bool = False,
) -> dict:
"""
xAI does NOT require the OpenAI-Beta header.
Only send Authorization header.
"""
return {
"Authorization": f"Bearer {api_key}",
}

Xet Storage Details

Size:
1.5 kB
·
Xet hash:
24725d4e2a17e62eb196f247c980cd7981ee552766f59ce62b1627e1bf6ec48d

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.