Table of Contents

Class RealtimeSession

A session refers to a single WebSocket connection between a client and the server.

Once a client creates a session, it then sends JSON-formatted events containing text and audio chunks. The server will respond in kind with audio containing voice output, a text transcript of that voice output, and function calls (if functions are provided by the client).

A realtime Session represents the overall client-server interaction, and contains default configuration.

It has a set of default values which can be updated at any time (via session.update) or on a per-response level (via response.create).

public class RealtimeSession
Inheritance
object
RealtimeSession

Properties

AudioConfig

Configuration for input and output audio.

public AudioConfig AudioConfig { get; set; }

Property Value

AudioConfig

Id

The unique ID of the session.

public string Id { get; set; }

Property Value

string

Include

Optional. Additional fields to include in server outputs.

    public List<string> Include { get; set; }

    Property Value

    List<string>

    Instructions

    The default system instructions (i.e. system message) prepended to model calls. This field allows the client to guide the model on desired responses. The model can be instructed on response content and format, (e.g. "be extremely succinct", "act friendly", "here are examples of good responses") and on audio behavior (e.g. "talk quickly", "inject emotion into your voice", "laugh frequently"). The instructions are not guaranteed to be followed by the model, but they provide guidance to the model on the desired behavior.

    Note that the server sets default instructions which will be used if this field is not set and are visible in the session.created event at the start of the session.

    public string Instructions { get; set; }

    Property Value

    string

    MaxOutputTokens

    Maximum number of output tokens for a single assistant response, inclusive of tool calls. Provide an integer between 1 and 4096 to limit output tokens, or inf for the maximum available tokens for a given model.

    Defaults to inf.

    public int? MaxOutputTokens { get; set; }

    Property Value

    int?

    Model

    The default model used for this session.

    public string Model { get; set; }

    Property Value

    string

    OutputModalities

    The set of modalities the model can respond with.

    public Modalities OutputModalities { get; set; }

    Property Value

    Modalities

    Prompt

    Reference to a prompt template and its variables.

    Learn more: https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts

    public PromptTemplate Prompt { get; set; }

    Property Value

    PromptTemplate

    ToolChoice

    Optional. How the model chooses tools. Provide one of the string modes or force a specific function/MCP tool.

    public ToolChoice ToolChoice { get; set; }

    Property Value

    ToolChoice

    Tools

    Optional. Tools available to the model.

    public Tool[] Tools { get; set; }

    Property Value

    Tool[]

    Tracing

    Optional. Realtime API can write session traces to the Traces Dashboard. Set to null to disable tracing. Once tracing is enabled for a session, the configuration cannot be modified.

    auto will create a trace for the session with default values for the workflow name, group id, and metadata.

    public StringOr<TracingConfig> Tracing { get; set; }

    Property Value

    StringOr<TracingConfig>

    Truncation

    Controls how the realtime conversation is truncated prior to model inference. The default is auto.

    public TruncationStrategy Truncation { get; set; }

    Property Value

    TruncationStrategy

    Type

    The type of session to create. Always realtime for the Realtime API.

    public string Type { get; set; }

    Property Value

    string

    Methods

    ToString()

    Returns a string that represents the current object.

    public override string ToString()

    Returns

    string

    A string that represents the current object.