OpenAI GPT-4, DALL-E, Whisper

Integrate OpenAI GPT-4, DALL-E, and Whisper APIs into Delphi applications. Chat completions, image generation, and speech-to-text.

TsgcHTTP_API_OpenAI

OpenAI REST client — Chat Completions, Responses, Images, Audio (TTS / Whisper), Embeddings, Files, Fine-tuning, Moderation, Assistants and Threads.

Component class

TsgcHTTP_API_OpenAI

Protocol

OpenAI REST API over HTTPS

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Enterprise (AI add-on)

Drop the component, set a few properties, go

Set the ApiKey in OpenAIOptions, then call typed Create*() methods or one-liner helpers like _CreateChatCompletion.

uses
  sgcHTTP_API_OpenAI;

var
  OpenAI: TsgcHTTP_API_OpenAI;
begin
  OpenAI := TsgcHTTP_API_OpenAI.Create(nil);
  OpenAI.OpenAIOptions.ApiKey := 'sk-...';

  // One-shot chat completion (returns the raw JSON body)
  Memo1.Lines.Text := OpenAI._CreateChatCompletion(
    'gpt-4o-mini', 'Hello, world.');

  // Other one-liners ship out of the box:
  OpenAI._CreateEmbeddings('text-embedding-3-small', 'sgcWebSockets rocks');
  OpenAI._CreateImage('a delphi-blue rubber duck');
  OpenAI._CreateModeration('be nice');

  // Streaming: build a typed Request, set Stream := True, hook OnHTTPAPISSE
  OpenAI.OnHTTPAPISSE := HandleSSE;
end;

procedure TForm1.HandleSSE(Sender: TObject;
  const aEvent, aData: string;
  var Cancel: Boolean);
begin
  Memo1.Lines.Add(aData);
end;
using esegece.sgcWebSockets;

var openai = new TsgcHTTPAPI_OpenAI();
openai.OpenAIOptions.ApiKey = "sk-...";

// One-shot chat completion (raw JSON body)
Console.WriteLine(openai._CreateChatCompletion("gpt-4o-mini", "Hello, world."));

// Streamed responses surface through OnHTTPAPISSE
openai.OnHTTPAPISSE += (s, ev, data, c) => Console.Write(data);

What's inside

5 published properties, 78 methods, 2 events — pulled from the component reference.

Reliability

Published properties: CircuitBreaker.

HTTP

Published properties: ReadTimeout, TLSOptions.

Configuration

Published properties: OpenAIOptions.

Diagnostics

Published properties: Version.

Chat Completions

Methods: CreateChatCompletion, CreateCompletion, CreateEdit.

Responses

Methods: CreateResponse, RetrieveResponse, DeleteResponse.

Specifications & references

Authoritative sources for the protocols this component implements.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help — OpenAI Full property, method and event reference for this component.
Demo Project — Demos\AI\OpenAI Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi, C++ Builder and .NET and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Frequently Asked Questions

Drop a TsgcHTTP_API_OpenAI component, set OpenAIOptions.ApiKey to your OpenAI key, then call a one-liner helper such as _CreateChatCompletion('gpt-4o-mini', 'Hello, world.') which returns the raw JSON body. Typed Create*() methods like CreateChatCompletion are also available for full control.
The component ships with sgcWebSockets, which supports Delphi 7 through Delphi 13 and the matching C++ Builder versions, plus a .NET edition. It runs on Windows, macOS, Linux, iOS and Android.
Yes. The component is the OpenAI REST client, so you supply your own API key from your OpenAI account and assign it to OpenAIOptions.ApiKey. Usage is billed by OpenAI against that key.
Yes. Build a typed request, set Stream := True, and hook the OnHTTPAPISSE event. Tokens arrive as Server-Sent Events and are delivered incrementally through that handler as they are generated.
It wraps Chat Completions, Responses, Images (DALL-E via _CreateImage), Audio (TTS and Whisper), Embeddings (_CreateEmbeddings), Files, Fine-tuning, Moderation (_CreateModeration), and Assistants and Threads. In total it exposes 78 methods pulled from the component reference.

Ready to Integrate OpenAI?

Download the free trial and start building in minutes.