Anthropic Claude AI

Integrate Anthropic Claude AI models into Delphi applications. Chat completions with Claude 3.5 Sonnet, Haiku, and Opus.

TsgcHTTP_API_Anthropic

Anthropic REST API client for Claude Messages, Files, Batches and token counting.

Component class

TsgcHTTP_API_Anthropic

Protocol

Anthropic 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 AnthropicOptions, then call typed helper methods such as _CreateMessage or build a TsgcAnthropicClass_Request_Messages and call CreateMessage.

uses
  sgcHTTP_API_Anthropic;

var
  Anthropic: TsgcHTTP_API_Anthropic;
begin
  Anthropic := TsgcHTTP_API_Anthropic.Create(nil);
  Anthropic.AnthropicOptions.ApiKey := 'sk-ant-...';
  Anthropic.AnthropicOptions.AnthropicVersion := '2023-06-01';

  // Simple one-shot message
  Memo1.Lines.Text := Anthropic._CreateMessage(
    'claude-3-5-sonnet-latest',
    'What are the benefits of WebSockets?',
    4096);

  // Streaming — handle OnHTTPAPISSE per delta
  Anthropic.OnHTTPAPISSE := HandleSSE;
  Anthropic._CreateMessageStream(
    'claude-3-5-sonnet-latest',
    'Summarise RFC 6455',
    1024);
end;

procedure TForm1.HandleSSE(Sender: TObject;
  const aEvent, aData: string;
  var Cancel: Boolean);
begin
  Memo1.Lines.Add(aEvent + ': ' + aData);
end;
// uses: sgcHTTP_API_Anthropic
TsgcHTTP_API_Anthropic *Anthropic = new TsgcHTTP_API_Anthropic(this);
Anthropic->AnthropicOptions->ApiKey = "sk-ant-...";
Anthropic->AnthropicOptions->AnthropicVersion = "2023-06-01";

// Simple one-shot message
Memo1->Lines->Text = Anthropic->_CreateMessage(
  "claude-3-5-sonnet-latest",
  "What are the benefits of WebSockets?",
  4096);

// Streaming — OnHTTPAPISSE fires per delta
Anthropic->OnHTTPAPISSE = HandleSSE;
Anthropic->_CreateMessageStream(
  "claude-3-5-sonnet-latest",
  "Summarise RFC 6455",
  1024);
using esegece.sgcWebSockets;

var anthropic = new TsgcHTTPAPI_Anthropic();
anthropic.AnthropicOptions.ApiKey = "sk-ant-...";
anthropic.AnthropicOptions.AnthropicVersion = "2023-06-01";

// Simple one-shot message
Console.WriteLine(anthropic._CreateMessage(
  "claude-3-5-sonnet-latest",
  "What are the benefits of WebSockets?",
  4096));

// Streaming via Server-Sent Events
anthropic.OnHTTPAPISSE += (sender, ev, data, cancel) => Console.Write(data);
anthropic._CreateMessageStream(
  "claude-3-5-sonnet-latest",
  "Summarise RFC 6455",
  1024);

What's inside

5 properties, 7 public methods and 2 events. Typed request / response classes for Messages, Files and Batches.

Messages

CreateMessage sends a typed TsgcAnthropicClass_Request_Messages and returns a parsed response. _CreateMessage, _CreateMessageWithSystem, _CreateMessageStream and _CreateMessageWithThinking are JSON-string shortcuts.

Helper methods _CreateVisionMessage (image base64), _CreateDocumentMessage (PDF base64) and _CreateMessageWithWebSearch wrap the multimodal and Claude server-side tools.

Tool use & structured output

Build TsgcAnthropicClass_Request_Tool entries to expose function-calling tools to Claude. _CreateMessageJSON applies an inline JSON schema for structured outputs.

Files API

UploadFile, ListFiles, DeleteFile and helpers _GetFile, _DownloadFile manage attachments through the Anthropic Files endpoint.

Batches API

ListBatches, CancelBatch and helpers _GetBatch, _GetBatchResults drive the Message Batches workflow for high-volume offline processing.

Reliability & diagnostics

CircuitBreaker short-circuits requests when the API is unhealthy; 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 — Anthropic Full property, method and event reference for this component.
Demo Project — Demos\AI\Anthropic Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi, C++ Builder and .NET and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Frequently Asked Questions

Drop a TsgcHTTP_API_Anthropic component, set AnthropicOptions.ApiKey to your Claude key, then call _CreateMessage('claude-3-5-sonnet-latest', 'your prompt', 4096). For full control, build a typed TsgcAnthropicClass_Request_Messages and call CreateMessage.
The component ships with sgcWebSockets, which supports Delphi 7 through Delphi 13 and the matching C++ Builder versions, plus a .NET edition. The page includes ready-to-run Delphi, C++ Builder and .NET samples, and it runs on Windows, macOS, Linux, iOS and Android.
Yes. The component is the Anthropic REST client, so you supply your own API key from your Anthropic account and assign it to AnthropicOptions.ApiKey (you also set AnthropicVersion, e.g. '2023-06-01'). Usage is billed by Anthropic against that key.
Yes. Call _CreateMessageStream and handle the OnHTTPAPISSE event, which fires per delta. Claude streams the response as Server-Sent Events so text arrives incrementally as it is generated.
Yes. Build TsgcAnthropicClass_Request_Tool entries to expose function-calling tools to Claude, and use _CreateVisionMessage for image input, _CreateDocumentMessage for PDFs and _CreateMessageWithWebSearch for server-side web search. The samples target Claude 3.5 Sonnet, Haiku and Opus, and any model id Anthropic exposes can be passed.

Ready to Integrate Anthropic Claude?

Download the free trial and start building in minutes.