Catalog · How the catalog works
DELPHI
- ★ 1 on GitHub
Anyone may press Interesting, signed in or not. It helps others find this project.
README
Claude Components for Delphi
A native Embarcadero Delphi component that lets you call Anthropic's Claude API (the Messages API) directly from your VCL or FireMonkey apps.
- Target: Delphi 10.2 Tokyo (CompilerVersion 32) and later.
- Dependencies: RTL only (
System.Net.HttpClient,System.JSON). No third-party libraries. Works in both VCL and FMX projects, Win32 and Win64. - Default model:
claude-opus-4-8.
Anthropic does not ship an official Delphi SDK, so this component talks to the
REST endpoint POST /v1/messages over HTTPS using the built-in THTTPClient.
Repository layout
source/ Claude.Client.pas The TClaudeClient component (runtime, framework-agnostic)
Claude.Register.pas Design-time palette registration
packages/ ClaudeComponents.dpk Design-time package (.dpk + .dproj)
examples/ ConsoleDemo.dpr Minimal console demoInstalling the component into the IDE
- Open
packages/ClaudeComponents.dprojin the RAD Studio IDE (10.2 Tokyo+). - Right-click the package in the Project Manager → Build, then Install.
TClaudeClientnow appears on the Claude tab of the Tool Palette.- Add the
sourcefolder to your project's search path (Project → Options → Building → Delphi Compiler → Search path) so apps can compileClaude.Client.
You can also skip the IDE palette entirely and just add source\Claude.Client.pas
to your project — the component works fine created in code.
Quick start (in code)
uses
Claude.Client;
var
Client: TClaudeClient;
begin
Client := TClaudeClient.Create(nil);
try
Client.APIKey := GetEnvironmentVariable('ANTHROPIC_API_KEY');
// Client.Model is 'claude-opus-4-8' by default.
ShowMessage(Client.Ask('Say hello in Korean.'));
finally
Client.Free;
end;
end;Dropped on a form, set the APIKey property (or, better, assign it at run time
from an environment variable / secure store rather than persisting it in the
.dfm/.fmx).
API overview
Stateless calls
function SendMessage(const APrompt: string): TClaudeResponse; // full result record
function SendMessages(const AMessages: array of TClaudeMessage): TClaudeResponse;
function Ask(const APrompt: string): string; // text only; raises EClaudeError on failureTClaudeResponse carries Success, Text, StopReason, Model, Usage
(InputTokens / OutputTokens), StatusCode, RawJSON, and on failure
ErrorType / ErrorMessage.
Multi-turn conversation
The component keeps an in-memory message history:
Client.SystemPrompt := 'You are a helpful assistant.';
Writeln(Client.Chat('My name is Ada.')); // history is preserved
Writeln(Client.Chat('What is my name?')); // -> "Ada"
Client.ClearConversation;Chat adds the user turn, sends the whole conversation, appends the assistant
reply to the history, and returns its text. Lower-level building blocks:
AddUserMessage, AddAssistantMessage, Send, ClearConversation,
MessageCount.
Streaming
// OnStreamText is a method pointer ("of object"), so assign a method, e.g.:
procedure TForm1.HandleDelta(Sender: TObject; const Delta: string);
begin
Memo1.Text := Memo1.Text + Delta;
end;
// ...
Client.OnStreamText := HandleDelta;
Client.SendStreaming('Write a short poem.');OnStreamText fires for each text delta as it arrives (server-sent events are
parsed internally). SendStreaming returns the fully assembled TClaudeResponse
when complete.
Note:
SendStreamingblocks the calling thread until the stream finishes. In a GUI app, call it from a background thread (e.g.TTask.Run) and marshalOnStreamTextupdates back to the main thread withTThread.Queue.
Published properties
| Property | Default | Notes |
|---|---|---|
APIKey |
(empty) | Your Anthropic API key. |
Model |
claude-opus-4-8 |
Any valid Claude model id. |
MaxTokens |
16000 |
Max output tokens. |
SystemPrompt |
(empty) | Optional system prompt. |
AnthropicVersion |
2023-06-01 |
anthropic-version header. |
BaseURL |
https://api.anthropic.com |
Override for proxies/gateways. |
TimeoutMS |
600000 |
Applied on Delphi 10.3+ (Tokyo's THTTPClient has no timeout API). |
Running the demo
set ANTHROPIC_API_KEY=sk-ant-...
cd examples
dcc32 -U..\source ConsoleDemo.dpr
ConsoleDemo.exeNotes
- The default model
claude-opus-4-8rejectstemperature/top_p/top_kandbudget_tokens, so this component does not send them. Adaptive thinking is controlled server-side; omit it for normal use. - Always check
Result.Success(or catchEClaudeErrorfromAsk/Chat).StopReason = 'refusal'indicates a safety refusal rather than a transport error.

