xAI Grok

Integrate xAI Grok models into Delphi, C++ Builder and .NET applications, with chat completions, streaming, vision and model listing.

TsgcHTTP_API_Grok

xAI REST API client for Grok chat completions, streaming, vision and model listing.

Component class

TsgcHTTP_API_Grok

Protocol

xAI 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 GrokOptions, then call typed helper methods such as _CreateMessage or build a TsgcGrokClass_Request_ChatCompletion and call CreateMessage.

uses
  sgcHTTP_API_Grok;

var
  Grok: TsgcHTTP_API_Grok;
begin
  Grok := TsgcHTTP_API_Grok.Create(nil);
  Grok.GrokOptions.ApiKey := 'YOUR_API_KEY';

  // Simple one-shot message
  Memo1.Lines.Text := Grok._CreateMessage(
    'grok-3',
    'What are the benefits of WebSockets?');

  // Streaming — handle OnHTTPAPISSE per delta
  Grok.OnHTTPAPISSE := OnSSEEvent;
  Grok._CreateMessageStream(
    'grok-3',
    'Tell me a story.');
end;

procedure TForm1.OnSSEEvent(Sender: TObject;
  const aEvent, aData: string;
  var Cancel: Boolean);
begin
  Memo1.Lines.Add(aData);
end;
// uses: sgcHTTP_API_Grok
TsgcHTTP_API_Grok *Grok = new TsgcHTTP_API_Grok(NULL);
Grok->GrokOptions->ApiKey = "YOUR_API_KEY";

// Simple one-shot message
Memo1->Lines->Text = Grok->_CreateMessage(
  "grok-3",
  "What are the benefits of WebSockets?");

// Streaming — OnHTTPAPISSE fires per delta
Grok->OnHTTPAPISSE = OnSSEEvent;
Grok->_CreateMessageStream(
  "grok-3",
  "Tell me a story.");
using esegece.sgcWebSockets;

var grok = new TsgcHTTP_API_Grok();
grok.GrokOptions.ApiKey = "YOUR_API_KEY";

// Simple one-shot message
Console.WriteLine(grok._CreateMessage(
  "grok-3",
  "What are the benefits of WebSockets?"));

// Streaming via Server-Sent Events
grok.OnHTTPAPISSE += (sender, ev, data, cancel) => Console.Write(data);
grok._CreateMessageStream(
  "grok-3",
  "Tell me a story.");

What's inside

Typed request / response classes for chat completions, plus streaming, vision and model listing helpers.

Messages

CreateMessage sends a typed TsgcGrokClass_Request_ChatCompletion and returns a parsed response. _CreateMessage, _CreateMessageWithSystem and _CreateMessageStream are JSON-string shortcuts for one-shot, system-prompt and streaming chats.

Vision

_CreateVisionMessage sends a base64-encoded image with a text prompt so Grok can describe or analyse it, accepting media types such as image/jpeg, image/png, image/gif and image/webp.

Models

_GetModels lists all available Grok models, so you can discover and target the right model name (for example grok-3 or grok-2-latest) 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 — Grok Full property, method and event reference for this component.
Demo Project — Demos\AI\Grok 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 xAI Grok?

Download the free trial and start building in minutes.