Grok | Messages

Send a structured list of input messages with text content, and the model will generate the next message in the conversation.

Simple Example

Send a Hello message to Grok.


Grok := TsgcHTTP_API_Grok.Create(nil);
Grok.GrokOptions.ApiKey := 'API_KEY';
WriteLn(Grok._CreateMessage('grok-3', 'Hello!'));

System Prompt Example

Send a message with a system prompt to control Grok's behavior.


Grok := TsgcHTTP_API_Grok.Create(nil);
Grok.GrokOptions.ApiKey := 'API_KEY';
WriteLn(Grok._CreateMessageWithSystem('grok-3',
  'You are a helpful assistant that responds in Spanish.',
  'What is the capital of France?'));

Streaming Example

Use Server-Sent Events (SSE) to stream the response in real-time. Assign the OnHTTPAPISSE event handler to receive streaming events.


Grok := TsgcHTTP_API_Grok.Create(nil);
Grok.GrokOptions.ApiKey := 'API_KEY';
Grok.OnHTTPAPISSE := OnSSEEvent;
Grok._CreateMessageStream('grok-3', 'Tell me a story.');

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