TsgcHTTP_API_AnthropicMethods › CreateMessage

CreateMessage Method

Sends a chat request to Claude and returns the generated message

Syntax

function CreateMessage(const aRequest: TsgcAnthropicClass_Request_Messages) : TsgcAnthropicClass_Response_Messages;

Parameters

NameTypeDescription
aRequestconst TsgcAnthropicClass_Request_MessagesRequest object with Model, Messages, MaxTokens, System prompt, Tools and Stream flag.

Return Value

Response object containing the assistant message, stop reason and token usage (TsgcAnthropicClass_Response_Messages)

Remarks

Performs a POST /v1/messages against the Anthropic API to generate a response from a Claude model. The anthropic-version header is set automatically from AnthropicOptions.AnthropicVersion. When aRequest.Stream is True the response is delivered incrementally through the OnHTTPAPISSE event; when False the full response is returned synchronously. The returned object must be freed by the caller.

Example

oRequest := TsgcAnthropicClass_Request_Messages.Create;
oRequest.Model := 'claude-sonnet-4-5';
oRequest.MaxTokens := 1024;
oRequest.Messages.Add('user', 'Explain websockets in one sentence.');
oResponse := oAPI.CreateMessage(oRequest);
try ShowMessage(oResponse.Content[0].Text); finally oResponse.Free; end;

Back to Methods