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.

Ready to Integrate OpenAI?

Download the free trial and start building in minutes.