OpenAI Realtime API
OpenAI Realtime WebSocket client — bidirectional audio, function-calling and tool-use sessions with GPT-4o models.
OpenAI Realtime WebSocket client — bidirectional audio, function-calling and tool-use sessions with GPT-4o models.
The OpenAI Realtime API enables low-latency, multimodal interactions including speech-to-speech conversational experiences and real-time transcription.
TsgcWSAPI_OpenAI| Standards & specs | OpenAI Realtime API guide · OpenAI Realtime events |
| Component class | TsgcWSAPI_OpenAI (unit sgcWebSocket_API_OpenAI) |
| Frameworks | VCL, FireMonkey, Lazarus / FPC, .NET |
| Platforms | Windows, macOS, Linux, iOS, Android |
The principal published / public properties used to configure and drive the component. Consult the online help for the full list.
Client | Published or public property used to configure or query the component. |
OpenAIOptions | Published or public property used to configure or query the component. |
OnConnect | Published or public property used to configure or query the component. |
OnDisconnect | Published or public property used to configure or query the component. |
OnMessage | Published or public property used to configure or query the component. |
OnBinary | Published or public property used to configure or query the component. |
OnFragmented | Published or public property used to configure or query the component. |
OnError | Published or public property used to configure or query the component. |
OnException | Published or public property used to configure or query the component. |
AudioRecorder | Published or public property used to configure or query the component. |
The principal public methods exposed by the component.
AppendInputAudioBuffer() | Public procedure exposed by the component. |
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.
OpenAI := TsgcHTTP_API_OpenAI.Create(nil); OpenAI.OpenAIOptions.ApiKey := 'API_KEY'; WriteLn(OpenAI._CreateChatCompletion('gpt-3.5-turbo', 'Hello!'));
TsgcHTTP_API_OpenAI *OpenAI = new TsgcHTTP_API_OpenAI(NULL); OpenAI->OpenAIOptions->ApiKey = "API_KEY"; ShowMessage(OpenAI->_CreateChatCompletion("gpt-3.5-turbo", "Hello!"));
TsgcHTTP_API_OpenAI OpenAI = new TsgcHTTP_API_OpenAI(); OpenAI.OpenAIOptions.ApiKey = "API_KEY"; MessageBox.Show(OpenAI._CreateChatCompletion("gpt-3.5-turbo", "Hello!"));
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.
Create a batch job and retrieve its status.
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());
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());
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());
Use the text-davinci-003 model to get a predicted completion.
OpenAI := TsgcHTTP_API_OpenAI.Create(nil); OpenAI.OpenAIOptions.ApiKey := 'API_KEY'; WriteLn(OpenAI._CreateCompletion('text-davinci-003', 'Say this is a test'));
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"));
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"));
Tell OpenAI to fix the spelling mistakes of a prompt.
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?'));
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?"));
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?"));
Create a fine-tuning job and list existing jobs.
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());
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());
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());
Moderate the following text
OpenAI := TsgcHTTP_API_OpenAI.Create(nil); OpenAI.OpenAIOptions.ApiKey := 'API_KEY'; WriteLn(OpenAI._CreateModeration('I want to kill them.'));
TsgcHTTP_API_OpenAI *OpenAI = new TsgcHTTP_API_OpenAI(NULL); OpenAI->OpenAIOptions->ApiKey = "API_KEY"; ShowMessage(OpenAI->_CreateModeration("I want to kill them."));
TsgcHTTP_API_OpenAI OpenAI = new TsgcHTTP_API_OpenAI(); OpenAI.OpenAIOptions.ApiKey = "API_KEY"; MessageBox.Show(OpenAI._CreateModeration("I want to kill them."));
Create a response using the Responses API.
OpenAI := TsgcHTTP_API_OpenAI.Create(nil); OpenAI.OpenAIOptions.ApiKey := 'API_KEY'; WriteLn(OpenAI._CreateResponse('gpt-4o', 'What is the capital of France?'));
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?"));
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?"));
Every external claim links back to a primary source. The online-help references decode the canonical deep-link the company maintains for this component.
Demos\15.AI\01.QuickStart\06.RealTime
.net\demos\15.AI\01.QuickStart\06.RealTime