xAI Grok
Integrate xAI Grok models into Delphi, C++ Builder and .NET applications, with chat completions, streaming, vision and model listing.
Integrate xAI Grok models into Delphi, C++ Builder and .NET applications, with chat completions, streaming, vision and model listing.
xAI REST API client for Grok chat completions, streaming, vision and model listing.
TsgcHTTP_API_Grok
xAI REST API over HTTPS
Windows, macOS, Linux, iOS, Android
Enterprise (AI add-on)
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.");
Typed request / response classes for chat completions, plus streaming, vision and model listing helpers.
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.
_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.
_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.
CircuitBreaker short-circuits requests after repeated failures; ReadTimeout and TLSOptions tune the HTTPS layer; OnHTTPAPIException surfaces failures; OnHTTPAPISSE streams server-sent events.
Authoritative sources for the protocols this component implements.
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. | Open | |
| Demo Project — Demos\AI\Grok Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |