Skip to content

XaiRealtimeModel

Namespace: Vercel.AI.Xai

public sealed class XaiRealtimeModel : IRealtimeModel

xAI realtime voice model.

Inheritance: object

Implements: IRealtimeModel

View source

XaiRealtimeModel(string, HttpClient, string, Func<IReadOnlyDictionary<string, string?>>?)

Section titled “XaiRealtimeModel(string, HttpClient, string, Func<IReadOnlyDictionary<string, string?>>?)”
public XaiRealtimeModel(string modelId, HttpClient httpClient, string baseUrl, Func<IReadOnlyDictionary<string, string?>>? headers)

Creates a realtime model.

Parameters

Name Type Description
modelId string
httpClient HttpClient
baseUrl string
headers Func<IReadOnlyDictionary<string, string>>

View source

public string ModelId { get; }

Model id.

Value: string

View source

public string Provider { get; }

Provider id.

Value: string

View source

public Uri BuildUri()

WebSocket URI for this model.

Returns: Uri

View source

public Task<IRealtimeSession> ConnectAsync(CancellationToken cancellationToken)

WebSocket sessions are opened by the caller with Url.

Parameters

Name Type Description
cancellationToken CancellationToken

Returns: Task<IRealtimeSession>

View source

CreateClientSecretAsync(int?, CancellationToken)

Section titled “CreateClientSecretAsync(int?, CancellationToken)”
public Task<XaiClientSecret> CreateClientSecretAsync(int? expiresAfterSeconds, CancellationToken cancellationToken)

Posts to /realtime/client_secrets and returns a WebSocket URL that includes the model.

Parameters

Name Type Description
expiresAfterSeconds int?
cancellationToken CancellationToken

Returns: Task<XaiClientSecret>

View source

public string? SerializeClientEvent(string type)

Serializes a client event. conversation-item-truncate is dropped because xAI ignores it over WebSocket.

Parameters

Name Type Description
type string

Returns: string

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product