feat: xAI (Grok) voice provider suite — STT, TTS, Realtime in both SDKs#211
Merged
Conversation
… both SDKs All three xAI Voice APIs land in the Python and TypeScript SDKs with full parity, official pricing, mocked protocol tests, and Mintlify docs: - XaiRealtime engine (Grok Voice Agent API, wss://api.x.ai/v1/realtime): OpenAI-Realtime-GA-compatible, so the adapter subclasses the GA adapter and inherits audio streaming, barge-in, and the tool-calling bridge. xAI session knobs exposed opt-in: reasoning_effort, VAD threshold/ prefix_padding/idle_timeout, language_hint, keyterms, output speed, pronunciation replace map, session resumption, server_tools passthrough. - XaiSTT: streaming STT over wss://api.x.ai/v1/stt (binary frames, transcript.created handshake, Smart Turn, keyterms, diarization) plus a batch transcribe() helper for POST /v1/stt. - XaiTTS: one-shot streaming synthesis via POST /v1/tts, 26-voice roster (eve default), for_twilio/for_telnyx carrier presets, and a create_custom_voice() helper for POST /v1/custom-voices. - Pricing (official): Realtime $0.05/min, TTS $15.00/1M chars, STT $0.20/hr streaming ($0.10/hr batch). calculate_realtime_cost / calculateRealtimeCost gain optional provider + duration arguments for per-minute realtime billing; the token-based path is unchanged. - Docs: provider pages for both SDK trees, docs.json nav, metrics pricing tables, stt/tts/engines landing pages, concepts overview. Beta: validated against the xAI API spec and mocked protocol tests; not yet exercised on a live phone call. Known Beta limitation: caller-side transcript display does not populate (xAI emits input_audio_transcription.updated rather than .completed). Python: 3124 passed. TypeScript: 2542 passed, tsc clean, build OK.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
nicolotognoni
marked this pull request as ready for review
July 14, 2026 07:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implementation
XaiRealtimeengine +XaiRealtimeAdapter: xAI's Voice Agent API (wss://api.x.ai/v1/realtime, default modelgrok-voice-latest, voiceeve) is OpenAI-Realtime-GA protocol-compatible, so the adapter subclasses the GA adapter and inherits audio streaming, barge-in, session handshake, and the entire tool-calling bridge (including built-intransfer_call/end_call). The TypeScript GA adapter gained a smallrealtimeBaseUrl()hook (pure refactor, behavior byte-identical) so protocol-compatible providers can override the endpoint; Python overrides the URL class attribute. xAI-specific session knobs are exposed opt-in:reasoning_effort("high"/"none"), VADthreshold/prefix_padding_ms/idle_timeout_ms, ASRlanguage_hint/keyterms, outputspeed, pronunciationreplacemap, sessionresumption, and rawserver_toolspassthrough (xAI server-sideweb_search,x_search,mcp,file_search). Input transcription model defaults togrok-transcribe. v1 inherits the proven GA PCM24 transcode path; native G.711 passthrough (xAI supportsaudio/pcmu@ 8 kHz) is flagged as a follow-up latency optimization.XaiSTT(provider_key "xai"): streaming WebSocket adapter (wss://api.x.ai/v1/stt, config via URL query params, raw binary frames,transcript.createdhandshake gating, chunk-final/utterance-final mapping,finalizesupport, Smart Turn end-of-turn detection, repeatablekeytermbiasing, diarization, filler words). Defaultspcm@16000to match the pipeline's decoded feed (consistent with Deepgram/Soniox). Plus a batchtranscribe()/xaiTranscribe()REST helper (multipart with file-last ordering, word-level timestamps, ITN formatting, URL-or-bytes input).XaiTTS(provider_key "xai_tts"): REST one-shot streaming synthesis (POST /v1/tts), 26-voice roster (evedefault),language="auto"default,for_twilio()(G.711 µ-law 8 kHz) /for_telnyx()(PCM16 16 kHz) carrier presets,speed,optimize_streaming_latency,text_normalization, MP3bit_rate; pluscreate_custom_voice()/xaiCreateCustomVoice()forPOST /v1/custom-voicesvoice cloning (≤120 s reference clip).DEFAULT_PRICINGentries;calculate_realtime_cost/calculateRealtimeCostgain optionalproviderand duration arguments to support per-minute realtime billing (token path unchanged — regression-tested); metrics accumulator metersxai_realtimeby session duration. The xAI $0.004/text-input-message charge is documented as a pricing constant but not metered in v1.xai_key), telemetry vendor allowlist + aliases, root exports,pyproject.toml[xai]extra (aiohttp).libraries/python/getpatter/providers/xai_{stt,tts,realtime}.py,libraries/typescript/src/providers/xai-{stt,tts,realtime}.ts,engines/xai.*,stt/xai.*,tts/xai.*, pricing/metrics/telemetry/client/server edits, 6 docs pages +docs.json+ metrics/landing pages, CHANGELOG.[xai]extra reusingaiohttp(same pin as the soniox extra).Breaking change?
No. All new surface is opt-in with safe defaults; existing providers, pricing entries, and the token-based realtime cost path are unchanged (existing OpenAI Realtime tests pass untouched).
Beta notes / known limitations
input_audio_transcription.updatedrather than.completed); audio, responses, barge-in, and tool calling are unaffected. Documented in the provider page.elevenlabs_wsexists as a separate provider — a futurexai_ws_ttscould mirror it).package.jsonexportsonly maps".", so namespaced subpath imports shown in provider docs resolve for types but not at runtime; docs lead with the flat aliases.Test plan
pytest tests/— 3124 passed, 8 skipped, 2 xfailed (34+ new xAI tests: WS handshake ordering, is_final/speech_final mapping, finalize, multipart ordering, session-config grafting, pricing math incl. per-minute realtime + unchanged token path)npm test— 2542 passed (45+ new xAI tests incl. GA-adapter refactor regression) +npm run lint(tsc clean) +npm run build(success)Docs updates
docs/{python,typescript}-sdk/providers/xai-stt.mdx,xai-tts.mdx,xai-realtime.mdx(new, both trees)docs/docs.json(6 nav insertions),docs/{python,typescript}-sdk/metrics.mdx(pricing tables),docs/{python,typescript}-sdk/{stt,tts,engines}.mdx,docs/concepts.mdx