SkillAgentSearch skills...

DelphiAnthropic

The Anthropic API wrapper for Delphi leverages cutting-edge models, including Anthropic's advanced Claude series, to deliver powerful features for chat interactions, vision processing, caching, efficient batch processing, connector MCP and skills

Install / Use

/learn @MaxiDonkey/DelphiAnthropic

README

DelphiAnthropic – Claude API Wrapper for Delphi

Delphi async/await supported GitHub GitHub


New


Two simple illustrative examples of synchronous text generation

[!TIP] To obtain an Anthropic API key, refer to https://platform.claude.com/account/keys

<br>
  • Non-streamed example:

    // uses Anthropic, Anthropic.Types, Anthropic.Helpers;
    // Client: IAnthropic;
    
    var Client := TAnthropicFactory.CreateInstance('ANTHROPIC_API_KEY');
    
    //JSON payload
    var Payload: TChatParamProc :=
      procedure (Params: TChatParams)
      begin
        Params
          .Model('claude-sonnet-4-6')
          .Messages( Generation.MessageParts
              .User('From which version of Delphi were multi-line strings introduced?')
          )
          .MaxTokens(1024);
      end;
    
    //Synchronous example
    var Chat := Client.Chat.Create(Payload);
    
    try
      for var Block in Chat.Content do
        if Block.&Type = TContentBlockType.text then
          Memo1.Lines.Text := Memo1.Text + Block.Text;
    finally
      Chat.Free;
    end;
    
    
<br>
  • Streamed example (SSE):

    // uses Anthropic, Anthropic.Types, Anthropic.Helpers;
    // Client: IAnthropic;
    
    //JSON payload
    var Payload: TChatParamProc :=
      procedure (Params: TChatParams)
      begin
        Params
          .Model('claude-opus-4-6')
          .Messages( Generation.MessageParts
              .User('Explain the discrete topology')
          )
          .Thinking( CreateThinkingConfig('adaptive') )
          .Stream;
      end;
    
    // Streaming callback
    var StreamEvent: TChatEvent :=
      procedure (var Event: TChatStream; IsDone: Boolean; var Cancel: Boolean)
      begin
        if not IsDone then
          if Event.Block.&Type = TContentBlockType.text then
            Memo1.Text := Memo1.Text + Event.Block.Text;
        Application.ProcessMessages;
      end;
    
    //Synchronous example
    Client.Chat.CreateStream(Payload, StreamEvent);
    
<br>

Summary

Introduction

Built with Delphi 12 Community Edition (v12.1 Patch 1) <br> The wrapper itself is MIT-licensed. <br> You can compile and test it free of charge with Delphi CE.

<br>

DelphiAnthropic is a native Delphi wrapper for the Anthropic Claude API, providing structured access to the Messages API, including:

  • synchronous and asynchronous execution
  • SSE streaming
  • tools and function calling
  • structured outputs (JSON schema)
  • multimodal inputs (image, PDF)
  • advanced reasoning modes (adaptive / extended thinking)
<br>

[!IMPORTANT] This is an unofficial library. <br> Anthropic does not provide an official Delphi SDK for Claude. <br> This project is a Delphi implementation over the public API

<br>

Philosophy and Scope

Anthropic exposes a single, unified Messages API. <br> Agent Skills extend Claude through implicit, model-selected execution, whereas Tools are explicitly invoked and fully client-orchestrated.

This wrapper therefore focuses on:

  • faithful mapping of the Messages API
  • explicit modeling of execution modes
  • clear separation between always-on API features and features gated by explicit Anthropic beta headers
  • Delphi-first ergonomics, not JSON-first usage

Core execution modes

  • Standard generation

    • blocking or promise-based
    • full response returned at once
    • suitable for background processing or batch workflows
  • SSE streaming

    • synchronous or asynchronous
    • session-level or event-level callbacks
    • fine-grained interception of Claude SSE events
  • Tool-driven workflows

    • function calling
    • server-side tools (beta)
    • client-side orchestration
    • strict schema validation for agent safety

These distinctions are applied consistently at the API level and in the documentation.

<br>

About the FMX Example project

[!IMPORTANT] The FMX Example project provided in the folder sample is not intended to demonstrate elegant or idiomatic architecture. <br> It is deliberately non-factorized to remain isomorphic to the documentation:

  • each code block corresponds directly to a section of the guides
  • the priority is documentation → code correspondence, not reuse or abstraction <br>

This trade-off favors "readability and traceability" over architectural refinement.

<br>

Documentation – Overview

The documentation is organized as focused Markdown guides, each covering one major capability.

Main entry points

Each section includes Delphi-first examples, not raw JSON.

[!WARNING] In Anthropic terminology, beta means "feature gated by explicit beta headers", not a prerelease SDK version.

<br>

Going Further

Advanced or cross-cutting topics are documented separately to keep the core readable:

Each topic has its own Markdown document, directly linked from the guides.

<br>

Functional Coverage

| Domain / Feature | Supported | Anthropic API (Beta) | |--------------------------------------------------|:---------:|:--------------------:| | Text generation | ● | | | Multimodal (image, PDF input) | ● | | | SSE / streaming | ● | | | Persistent conversations | ● | | | Agent skills | ● | ● | | Batch processing | ● | | | Structured outputs (JSON / strict tools) | ● | | | Function / tool calling | ● | | | Programmatic tool calling | ● | ● | | Tool search (dynamic discovery) | ● | ● | | Fine-grained tool streaming | ● | | | Code execution (Python sandbox) | ● | ● | | Computer use | ● | ● | | Memory (cross-conversation) | ● | ● | | Web search | ● | | | Web fetch (URL / PDF content) | ● | ● | | Citations | ● | | | Search results grounding | ● | | | Large context window (1M tokens) | ● | ● | | Adaptive thinking | ● | | | Extended thinking | ● | | | Effort control | ● | | | Context compaction | ● | ● | | Context editing | ● | ● | | Prompt caching (5 min) | ● | | | Prompt caching (1 hour) | ● | | | Token counting | ● | | | File management (Files API) | ● | ● | | Data residency (inference geo) | ● | | | Fast mode (research preview) | ● | ● |

  • Supported: support provided by DelphiAnthropic
  • Anthropic API (Beta): Feature available only via the Anthropic API (beta).
<br>

Project Status

  • The Anthropic API is evolving rapidly
  • Several advanced capabilities are still beta
  • The wrapper follows a pragmatic approach:
    • expose what exists
    • clearly label what is beta
    • avoid duplicating the official documentation
    • prefer correctness
View on GitHub
GitHub Stars47
CategoryDevelopment
Updated10d ago
Forks10

Languages

Pascal

Security Score

95/100

Audited on Mar 29, 2026

No findings