Google Gemini AI

Integrate Google Gemini multimodal AI models into your Delphi, C++ Builder and .NET applications, with content generation, vision, structured outputs, embeddings and streaming.

TsgcHTTP_API_Gemini

Google Gemini REST API client for content generation, vision, structured outputs, token counting and embeddings.

Component class

TsgcHTTP_API_Gemini

Protocol

Gemini 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 API key in GeminiOptions, then build a TsgcGeminiClass_Request_GenerateContent and call CreateContent, or use the _CreateContent string helper for a quick one-shot prompt.

uses
  sgcHTTP_API_Gemini;

var
  Gemini: TsgcHTTP_API_Gemini;
  Request: TsgcGeminiClass_Request_GenerateContent;
  Response: TsgcGeminiClass_Response_GenerateContent;
begin
  Gemini := TsgcHTTP_API_Gemini.Create(nil);
  Gemini.GeminiOptions.ApiKey := 'YOUR_API_KEY';

  // Typed content-generation request
  Request := TsgcGeminiClass_Request_GenerateContent.Create;
  Request.Model := 'gemini-2.0-flash';
  Request.AddUserContent('What are the benefits of WebSockets?');
  Response := Gemini.CreateContent(Request);

  // Simple one-shot prompt via string helper
  Memo1.Lines.Text := Gemini._CreateContent(
    'gemini-2.0-flash',
    'Summarise RFC 6455',
    4096);

  // Streaming — handle OnHTTPAPISSE per delta
  Gemini.OnHTTPAPISSE := HandleSSE;
  Gemini._CreateContentStream(
    'gemini-2.0-flash',
    'Explain quantum entanglement',
    1024);
end;

procedure TForm1.HandleSSE(Sender: TObject;
  const aEvent, aData: string;
  var Cancel: Boolean);
begin
  Memo1.Lines.Add(aEvent + ': ' + aData);
end;
// uses: sgcHTTP_API_Gemini
TsgcHTTP_API_Gemini *Gemini = new TsgcHTTP_API_Gemini(this);
Gemini->GeminiOptions->ApiKey = "YOUR_API_KEY";

// Typed content-generation request
TsgcGeminiClass_Request_GenerateContent *Request =
  new TsgcGeminiClass_Request_GenerateContent();
Request->Model = "gemini-2.0-flash";
Request->AddUserContent("What are the benefits of WebSockets?");
TsgcGeminiClass_Response_GenerateContent *Response = Gemini->CreateContent(Request);

// Simple one-shot prompt via string helper
Memo1->Lines->Text = Gemini->_CreateContent(
  "gemini-2.0-flash",
  "Summarise RFC 6455",
  4096);

// Streaming — OnHTTPAPISSE fires per delta
Gemini->OnHTTPAPISSE = HandleSSE;
Gemini->_CreateContentStream(
  "gemini-2.0-flash",
  "Explain quantum entanglement",
  1024);
using esegece.sgcWebSockets;

var gemini = new TsgcHTTPAPI_Gemini();
gemini.GeminiOptions.ApiKey = "YOUR_API_KEY";

// Typed content-generation request
var request = new TsgcGeminiClass_Request_GenerateContent();
request.Model = "gemini-2.0-flash";
request.AddUserContent("What are the benefits of WebSockets?");
var response = gemini.CreateContent(request);

// Simple one-shot prompt via string helper
Console.WriteLine(gemini._CreateContent(
  "gemini-2.0-flash",
  "Summarise RFC 6455",
  4096));

// Streaming via Server-Sent Events
gemini.OnHTTPAPISSE += (sender, ev, data, cancel) => Console.Write(data);
gemini._CreateContentStream(
  "gemini-2.0-flash",
  "Explain quantum entanglement",
  1024);

What's inside

Typed request / response classes for content generation, vision, structured outputs, token counting and embeddings, plus streaming and reliability controls.

Messages

CreateContent sends a typed TsgcGeminiClass_Request_GenerateContent and returns a parsed response. _CreateContent, _CreateContentWithSystem and _CreateContentStream are JSON-string shortcuts for quick prompts and streaming.

Vision

_CreateVisionContent sends a base64-encoded image with a text prompt, supporting image/jpeg, image/png, image/gif and image/webp media types for multimodal understanding.

Tool use & function calling

Add function declarations and tools to TsgcGeminiClass_Request_GenerateContent so Gemini can invoke your functions and return structured tool calls inside the same generation request.

Structured outputs

_CreateContentJSON applies a JSON schema to the request so the model returns structured JSON that matches your expected output format.

Token counting

CountTokens sends a TsgcGeminiClass_Request_CountTokens to estimate quota usage and truncate prompts before generation. No text is produced by this call.

Embeddings

EmbedContent generates a dense floating-point vector for a piece of text using an embedding model such as text-embedding-004, for semantic search and retrieval pipelines.

Models

_GetModels lists every available Gemini model and _GetModel retrieves details for a specific model identifier, so you can discover capabilities at runtime.

Reliability & diagnostics

CircuitBreaker short-circuits requests after repeated failures; ReadTimeout and TLSOptions tune the HTTPS layer; OnHTTPAPIException surfaces failures; OnHTTPAPISSE streams server-sent events.

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 — Gemini Full property, method and event reference for this component.
Demo Project — Demos\AI\Gemini Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
User Manual (PDF) Comprehensive manual covering every component in the library.

Ready to Integrate Google Gemini?

Download the free trial and start building in minutes.