Anthropic Component
High-level Anthropic Claude API client — Messages, streaming, tool use, vision and structured-output JSON schema.
High-level Anthropic Claude API client — Messages, streaming, tool use, vision and structured-output JSON schema.
Anthropic REST API client for Claude Messages, Files, Batches and token counting.
TsgcHTTP_API_Anthropic| Standards & specs | Anthropic API — Getting started · Anthropic API — Messages |
| Component class | TsgcHTTP_API_Anthropic (unit sgcHTTP_API_Anthropic) |
| Frameworks | VCL, FireMonkey, Lazarus / FPC, .NET |
| Platforms | Windows, macOS, Linux, iOS, Android |
The principal published / public properties used to configure and drive the component. Consult the online help for the full list.
TLSOptions | Configures the TLS/SSL layer used for HTTPS connections to the Anthropic API |
AnthropicOptions | Holds connection settings for the Anthropic API, including API key, HTTP options, logging, retries and the anthropic-version header |
ReadTimeout | Maximum time in milliseconds to wait for a response from the Anthropic API before aborting the request |
CircuitBreaker | Protects the client from cascading failures by short-circuiting requests when the Anthropic API becomes unhealthy |
Version | Read-only string containing the current version of the sgc Anthropic API client component |
The principal public methods exposed by the component.
DeleteFile() | Deletes a previously uploaded file from the Anthropic Files API |
CreateMessage() | Sends a chat request to Claude and returns the generated message |
CountTokens() | Counts the number of input tokens a request would consume before sending it to Claude |
ListFiles() | Lists files previously uploaded to the Anthropic Files API, with optional pagination |
ListBatches() | Lists all Message Batches in the Anthropic workspace, with optional pagination |
CancelBatch() | Cancels an in-progress Message Batch on the Anthropic API |
UploadFile() | Uploads a local file to the Anthropic Files API for later use in messages |
The component exposes the following published events; consult the online help for full event-handler signatures.
OnHTTPAPIException | Fires when a call to the Anthropic API raises an unhandled exception |
OnHTTPAPISSE | Fires for every Server-Sent Event received from a streaming Anthropic response |
Drop the component on a form, configure the properties below and activate it. The snippet that follows shows the typical Anthropic Documents — Simple Example configuration sourced from the online help.
Anthropic := TsgcHTTP_API_Anthropic.Create(nil); Anthropic.AnthropicOptions.ApiKey := 'API_KEY'; // Load PDF file and encode to base64 vBase64 := sgcBase64Encode(LoadFileToBytes('document.pdf')); WriteLn(Anthropic._CreateDocumentMessage('claude-sonnet-4-20250514', 'Summarize this document.', vBase64, 'application/pdf'));
TsgcHTTP_API_Anthropic *Anthropic = new TsgcHTTP_API_Anthropic(NULL); Anthropic->AnthropicOptions->ApiKey = "API_KEY"; // Load PDF file and encode to base64 AnsiString vBase64 = sgcBase64Encode(LoadFileToBytes("document.pdf")); ShowMessage(Anthropic->_CreateDocumentMessage("claude-sonnet-4-20250514", "Summarize this document.", vBase64, "application/pdf"));
TsgcHTTP_API_Anthropic Anthropic = new TsgcHTTP_API_Anthropic(); Anthropic.AnthropicOptions.ApiKey = "API_KEY"; // Load PDF file and encode to base64 string vBase64 = sgcBase64Encode(LoadFileToBytes("document.pdf")); MessageBox.Show(Anthropic._CreateDocumentMessage("claude-sonnet-4-20250514", "Summarize this document.", vBase64, "application/pdf"));
The following scenarios are lifted verbatim from the online help. Each shows the configuration and method calls needed to drive the component through a specific real-world flow.
Send a message with extended thinking enabled using the convenience method. The temperature is automatically set to 1.0 (required by the API when thinking is enabled).
Anthropic := TsgcHTTP_API_Anthropic.Create(nil); Anthropic.AnthropicOptions.ApiKey := 'API_KEY'; WriteLn(Anthropic._CreateMessageWithThinking('claude-sonnet-4-20250514', 'How many r''s are in the word strawberry?', 10000));
TsgcHTTP_API_Anthropic *Anthropic = new TsgcHTTP_API_Anthropic(NULL); Anthropic->AnthropicOptions->ApiKey = "API_KEY"; ShowMessage(Anthropic->_CreateMessageWithThinking("claude-sonnet-4-20250514", "How many r's are in the word strawberry?", 10000));
TsgcHTTP_API_Anthropic Anthropic = new TsgcHTTP_API_Anthropic(); Anthropic.AnthropicOptions.ApiKey = "API_KEY"; MessageBox.Show(Anthropic._CreateMessageWithThinking("claude-sonnet-4-20250514", "How many r's are in the word strawberry?", 10000));
Use the convenience method to create a message with an MCP server.
Anthropic := TsgcHTTP_API_Anthropic.Create(nil); Anthropic.AnthropicOptions.ApiKey := 'API_KEY'; Anthropic.AnthropicOptions.BetaHeaders := 'mcp-client-2025-11-20'; WriteLn(Anthropic._CreateMessageWithMCP('claude-sonnet-4-20250514', 'What tools are available?', 'https://my-mcp-server.example.com/sse', 'my-mcp-server'));
TsgcHTTP_API_Anthropic *Anthropic = new TsgcHTTP_API_Anthropic(NULL); Anthropic->AnthropicOptions->ApiKey = "API_KEY"; Anthropic->AnthropicOptions->BetaHeaders = "mcp-client-2025-11-20"; ShowMessage(Anthropic->_CreateMessageWithMCP("claude-sonnet-4-20250514", "What tools are available?", "https://my-mcp-server.example.com/sse", "my-mcp-server"));
TsgcHTTP_API_Anthropic Anthropic = new TsgcHTTP_API_Anthropic(); Anthropic.AnthropicOptions.ApiKey = "API_KEY"; Anthropic.AnthropicOptions.BetaHeaders = "mcp-client-2025-11-20"; MessageBox.Show(Anthropic._CreateMessageWithMCP("claude-sonnet-4-20250514", "What tools are available?", "https://my-mcp-server.example.com/sse", "my-mcp-server"));
Send a Hello message to Claude.
Anthropic := TsgcHTTP_API_Anthropic.Create(nil); Anthropic.AnthropicOptions.ApiKey := 'API_KEY'; WriteLn(Anthropic._CreateMessage('claude-sonnet-4-20250514', 'Hello!'));
TsgcHTTP_API_Anthropic *Anthropic = new TsgcHTTP_API_Anthropic(NULL); Anthropic->AnthropicOptions->ApiKey = "API_KEY"; ShowMessage(Anthropic->_CreateMessage("claude-sonnet-4-20250514", "Hello!"));
TsgcHTTP_API_Anthropic Anthropic = new TsgcHTTP_API_Anthropic(); Anthropic.AnthropicOptions.ApiKey = "API_KEY"; MessageBox.Show(Anthropic._CreateMessage("claude-sonnet-4-20250514", "Hello!"));
Use the convenience method to create a message with JSON schema output.
Anthropic := TsgcHTTP_API_Anthropic.Create(nil); Anthropic.AnthropicOptions.ApiKey := 'API_KEY'; vSchema := '{"type":"object","properties":{"name":{"type":"string"},' + '"age":{"type":"integer"}},"required":["name","age"],' + '"additionalProperties":false}'; WriteLn(Anthropic._CreateMessageJSON('claude-sonnet-4-20250514', 'Extract the name and age: John is 30 years old.', vSchema));
TsgcHTTP_API_Anthropic *Anthropic = new TsgcHTTP_API_Anthropic(NULL); Anthropic->AnthropicOptions->ApiKey = "API_KEY"; String vSchema = "{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"}," "\"age\":{\"type\":\"integer\"}},\"required\":[\"name\",\"age\"]," "\"additionalProperties\":false}"; ShowMessage(Anthropic->_CreateMessageJSON("claude-sonnet-4-20250514", "Extract the name and age: John is 30 years old.", vSchema));
TsgcHTTP_API_Anthropic Anthropic = new TsgcHTTP_API_Anthropic(); Anthropic.AnthropicOptions.ApiKey = "API_KEY"; string vSchema = "{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"}," + "\"age\":{\"type\":\"integer\"}},\"required\":[\"name\",\"age\"]," + "\"additionalProperties\":false}"; MessageBox.Show(Anthropic._CreateMessageJSON("claude-sonnet-4-20250514", "Extract the name and age: John is 30 years old.", vSchema));
Send an image with a prompt asking Claude to describe it.
Anthropic := TsgcHTTP_API_Anthropic.Create(nil); Anthropic.AnthropicOptions.ApiKey := 'API_KEY'; // Load image and encode to base64 oStream := TFileStream.Create('photo.png', fmOpenRead); Try oBytes := TBytesStream.Create; Try oBytes.CopyFrom(oStream, 0); vBase64 := EncodeBase64(oBytes.Memory, oBytes.Size); Finally oBytes.Free; End; Finally oStream.Free; End; WriteLn(Anthropic._CreateVisionMessage('claude-sonnet-4-20250514', 'What is in this image?', vBase64, 'image/png'));
TsgcHTTP_API_Anthropic *Anthropic = new TsgcHTTP_API_Anthropic(NULL); Anthropic->AnthropicOptions->ApiKey = "API_KEY"; // Load image and encode to base64 TFileStream *oStream = new TFileStream("photo.png", fmOpenRead); try { TBytesStream *oBytes = new TBytesStream(); try { oBytes->CopyFrom(oStream, 0); vBase64 = EncodeBase64(oBytes->Memory, oBytes->Size); } __finally { oBytes->Free(); } } __finally { oStream->Free(); } ShowMessage(Anthropic->_CreateVisionMessage("claude-sonnet-4-20250514", "What is in this image?", vBase64, "image/png"));
TsgcHTTP_API_Anthropic Anthropic = new TsgcHTTP_API_Anthropic(); Anthropic.AnthropicOptions.ApiKey = "API_KEY"; // Load image and encode to base64 byte[] fileBytes = System.IO.File.ReadAllBytes("photo.png"); string vBase64 = Convert.ToBase64String(fileBytes); MessageBox.Show(Anthropic._CreateVisionMessage("claude-sonnet-4-20250514", "What is in this image?", vBase64, "image/png"));
Use the convenience method to create a message with web search enabled.
Anthropic := TsgcHTTP_API_Anthropic.Create(nil); Anthropic.AnthropicOptions.ApiKey := 'API_KEY'; WriteLn(Anthropic._CreateMessageWithWebSearch('claude-sonnet-4-20250514', 'What are the latest news about Delphi programming?'));
TsgcHTTP_API_Anthropic *Anthropic = new TsgcHTTP_API_Anthropic(NULL); Anthropic->AnthropicOptions->ApiKey = "API_KEY"; ShowMessage(Anthropic->_CreateMessageWithWebSearch("claude-sonnet-4-20250514", "What are the latest news about Delphi programming?"));
TsgcHTTP_API_Anthropic Anthropic = new TsgcHTTP_API_Anthropic(); Anthropic.AnthropicOptions.ApiKey = "API_KEY"; MessageBox.Show(Anthropic._CreateMessageWithWebSearch("claude-sonnet-4-20250514", "What are the latest news about Delphi programming?"));
Every external claim links back to a primary source. The online-help references decode the canonical deep-link the company maintains for this component.
Demos\15.AI\01.QuickStart\07.Anthropic
.net\demos\15.AI\01.QuickStart\07.Anthropic