sgcWebSockets · Technical Document

OpenAI Realtime API

OpenAI Realtime WebSocket client — bidirectional audio, function-calling and tool-use sessions with GPT-4o models.

Overview

The OpenAI Realtime API enables low-latency, multimodal interactions including speech-to-speech conversational experiences and real-time transcription.

At a glance

Component class
TsgcWSAPI_OpenAI
Standards / spec
OpenAI Realtime API guide
Transports
TCP, TLS
Platforms
Windows, macOS, Linux, iOS, Android
Frameworks
VCL, FireMonkey, Lazarus / FPC, .NET
Edition
Standard / Professional / Enterprise

Features

Technical specification

Standards & specsOpenAI Realtime API guide · OpenAI Realtime events
Component classTsgcWSAPI_OpenAI (unit sgcWebSocket_API_OpenAI)
FrameworksVCL, FireMonkey, Lazarus / FPC, .NET
PlatformsWindows, macOS, Linux, iOS, Android

Main properties

The principal published / public properties used to configure and drive the component. Consult the online help for the full list.

ClientPublished or public property used to configure or query the component.
OpenAIOptionsPublished or public property used to configure or query the component.
OnConnectPublished or public property used to configure or query the component.
OnDisconnectPublished or public property used to configure or query the component.
OnMessagePublished or public property used to configure or query the component.
OnBinaryPublished or public property used to configure or query the component.
OnFragmentedPublished or public property used to configure or query the component.
OnErrorPublished or public property used to configure or query the component.
OnExceptionPublished or public property used to configure or query the component.
AudioRecorderPublished or public property used to configure or query the component.

Main methods

The principal public methods exposed by the component.

AppendInputAudioBuffer()Public procedure exposed by the component.

Quick Start

Drop the component on a form, configure the properties below and activate it. The snippet that follows shows the typical OpenAI Chat — Simple Example configuration sourced from the online help.

About this scenario. Interact with ChatGPT by sending a Hello message.

Delphi (VCL / FireMonkey)

OpenAI := TsgcHTTP_API_OpenAI.Create(nil);
OpenAI.OpenAIOptions.ApiKey := 'API_KEY';
WriteLn(OpenAI._CreateChatCompletion('gpt-3.5-turbo', 'Hello!'));

C++ Builder

TsgcHTTP_API_OpenAI *OpenAI = new TsgcHTTP_API_OpenAI(NULL);
OpenAI->OpenAIOptions->ApiKey = "API_KEY";
ShowMessage(OpenAI->_CreateChatCompletion("gpt-3.5-turbo", "Hello!"));

.NET (C#)

TsgcHTTP_API_OpenAI OpenAI = new TsgcHTTP_API_OpenAI();
OpenAI.OpenAIOptions.ApiKey = "API_KEY";
MessageBox.Show(OpenAI._CreateChatCompletion("gpt-3.5-turbo", "Hello!"));

Common scenarios

The following scenarios are lifted verbatim from the online help. Each shows the configuration and method calls needed to drive the component through a specific real-world flow.

1 · OpenAI Batch — Simple Example

Create a batch job and retrieve its status.

Delphi (VCL / FireMonkey)
OpenAI := TsgcHTTP_API_OpenAI.Create(nil);
OpenAI.OpenAIOptions.ApiKey := 'API_KEY';

// Create a batch
WriteLn(OpenAI._CreateBatch('file-abc123', '/v1/chat/completions'));

// List batches
WriteLn(OpenAI._ListBatches());
C++ Builder
TsgcHTTP_API_OpenAI *OpenAI = new TsgcHTTP_API_OpenAI(NULL);
OpenAI->OpenAIOptions->ApiKey = "API_KEY";

// Create a batch
ShowMessage(OpenAI->_CreateBatch("file-abc123", "/v1/chat/completions"));

// List batches
ShowMessage(OpenAI->_ListBatches());
.NET (C#)
TsgcHTTP_API_OpenAI OpenAI = new TsgcHTTP_API_OpenAI();
OpenAI.OpenAIOptions.ApiKey = "API_KEY";

// Create a batch
MessageBox.Show(OpenAI._CreateBatch("file-abc123", "/v1/chat/completions"));

// List batches
MessageBox.Show(OpenAI._ListBatches());

2 · OpenAI Completion — Simple Example

Use the text-davinci-003 model to get a predicted completion.

Delphi (VCL / FireMonkey)
OpenAI := TsgcHTTP_API_OpenAI.Create(nil);
OpenAI.OpenAIOptions.ApiKey := 'API_KEY';
WriteLn(OpenAI._CreateCompletion('text-davinci-003', 'Say this is a test'));
C++ Builder
TsgcHTTP_API_OpenAI *OpenAI = new TsgcHTTP_API_OpenAI(NULL);
OpenAI->OpenAIOptions->ApiKey = "API_KEY";
ShowMessage(OpenAI->_CreateCompletion("text-davinci-003", "Say this is a test"));
.NET (C#)
TsgcHTTP_API_OpenAI OpenAI = new TsgcHTTP_API_OpenAI();
OpenAI.OpenAIOptions.ApiKey = "API_KEY";
MessageBox.Show(OpenAI._CreateCompletion("text-davinci-003", "Say this is a test"));

3 · OpenAI Edit — Simple Example

Tell OpenAI to fix the spelling mistakes of a prompt.

Delphi (VCL / FireMonkey)
OpenAI := TsgcHTTP_API_OpenAI.Create(nil);
OpenAI.OpenAIOptions.ApiKey := 'API_KEY';
WriteLn(OpenAI._CreateEdit('text-davinci-edit-001', 'Fix the spelling mistakes', 'What day of the wek is it?'));
C++ Builder
TsgcHTTP_API_OpenAI *OpenAI = new TsgcHTTP_API_OpenAI(NULL);
OpenAI->OpenAIOptions->ApiKey = "API_KEY";
ShowMessage(OpenAI->_CreateEdit("text-davinci-edit-001", "Fix the spelling mistakes", "What day of the wek is it?"));
.NET (C#)
TsgcHTTP_API_OpenAI OpenAI = new TsgcHTTP_API_OpenAI();
OpenAI.OpenAIOptions.ApiKey = "API_KEY";
MessageBox.Show(OpenAI._CreateEdit("text-davinci-edit-001", "Fix the spelling mistakes", "What day of the wek is it?"));

4 · OpenAI Fine-Tuning — Simple Example

Create a fine-tuning job and list existing jobs.

Delphi (VCL / FireMonkey)
OpenAI := TsgcHTTP_API_OpenAI.Create(nil);
OpenAI.OpenAIOptions.ApiKey := 'API_KEY';

// Create a fine-tuning job
WriteLn(OpenAI._CreateFineTuningJob('gpt-4o-mini-2024-07-18', 'file-abc123'));

// List fine-tuning jobs
WriteLn(OpenAI._ListFineTuningJobs());
C++ Builder
TsgcHTTP_API_OpenAI *OpenAI = new TsgcHTTP_API_OpenAI(NULL);
OpenAI->OpenAIOptions->ApiKey = "API_KEY";

// Create a fine-tuning job
ShowMessage(OpenAI->_CreateFineTuningJob("gpt-4o-mini-2024-07-18", "file-abc123"));

// List fine-tuning jobs
ShowMessage(OpenAI->_ListFineTuningJobs());
.NET (C#)
TsgcHTTP_API_OpenAI OpenAI = new TsgcHTTP_API_OpenAI();
OpenAI.OpenAIOptions.ApiKey = "API_KEY";

// Create a fine-tuning job
MessageBox.Show(OpenAI._CreateFineTuningJob("gpt-4o-mini-2024-07-18", "file-abc123"));

// List fine-tuning jobs
MessageBox.Show(OpenAI._ListFineTuningJobs());

5 · OpenAI Moderation — Simple Example

Moderate the following text

Delphi (VCL / FireMonkey)
OpenAI := TsgcHTTP_API_OpenAI.Create(nil);
OpenAI.OpenAIOptions.ApiKey := 'API_KEY';

WriteLn(OpenAI._CreateModeration('I want to kill them.'));
C++ Builder
TsgcHTTP_API_OpenAI *OpenAI = new TsgcHTTP_API_OpenAI(NULL);
OpenAI->OpenAIOptions->ApiKey = "API_KEY";

ShowMessage(OpenAI->_CreateModeration("I want to kill them."));
.NET (C#)
TsgcHTTP_API_OpenAI OpenAI = new TsgcHTTP_API_OpenAI();
OpenAI.OpenAIOptions.ApiKey = "API_KEY";

MessageBox.Show(OpenAI._CreateModeration("I want to kill them."));

6 · OpenAI Responses — Simple Example

Create a response using the Responses API.

Delphi (VCL / FireMonkey)
OpenAI := TsgcHTTP_API_OpenAI.Create(nil);
OpenAI.OpenAIOptions.ApiKey := 'API_KEY';
WriteLn(OpenAI._CreateResponse('gpt-4o', 'What is the capital of France?'));
C++ Builder
TsgcHTTP_API_OpenAI *OpenAI = new TsgcHTTP_API_OpenAI(NULL);
OpenAI->OpenAIOptions->ApiKey = "API_KEY";
ShowMessage(OpenAI->_CreateResponse("gpt-4o", "What is the capital of France?"));
.NET (C#)
TsgcHTTP_API_OpenAI OpenAI = new TsgcHTTP_API_OpenAI();
OpenAI.OpenAIOptions.ApiKey = "API_KEY";
MessageBox.Show(OpenAI._CreateResponse("gpt-4o", "What is the capital of France?"));

Sources used to build this document

Every external claim links back to a primary source. The online-help references decode the canonical deep-link the company maintains for this component.

Document scope. This document covers the publicly-documented surface of the OpenAI Realtime API component shipped with sgcWebSockets. For full property, method and event reference consult the online help linked above.