# alle-ai/anthropic-api-php architecture

> Architecture diagram of the GitHub repository alle-ai/anthropic-api-php, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alle-ai/anthropic-api-php
- Repository: https://github.com/alle-ai/anthropic-api-php

## Overview

This is a PHP SDK for calling Anthropic’s Messages API and related services. The main workflow is application code configuring a client, submitting typed message requests, sending them through authenticated HTTP transport, and receiving typed responses or streamed events. Additional documented branches cover tool execution, model discovery, Files, and Batches; deployment authentication also supports Bedrock and Vertex AI. The graph uses README statements and shown source references; Files and Batches internals are not sampled, so their links are documented rather than implementation-level.

Main entry points: [`src/Anthropic/Client.php`](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Client.php) (Client), [`src/Anthropic/Resources/Messages.php`](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Resources/Messages.php) (Messages resource), [`src/Anthropic/Http/Transport.php`](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Http/Transport.php) (HTTP transport), [`src/Anthropic/ClientBuilder.php`](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/ClientBuilder.php) (Client builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Client setup"]
  node_client["Client<br/>[Client.php]"]
  node_builder["Client builder<br/>[ClientBuilder.php]"]
  node_options["Client options<br/>[ClientOptions.php]"]
end

subgraph group_api["API resources"]
  node_messages["Messages resource<br/>[Messages.php]"]
  node_models["Models resource<br/>[Models.php]"]
  node_files["Files resource<br/>[Files.php]"]
  node_batches["Batches resource<br/>[Batches.php]"]
  node_response["Message response"]
  node_stream["SSE stream<br/>[EventStream.php]"]
  node_parser["Event parser<br/>[EventParser.php]"]
end

subgraph group_runtime["Request runtime"]
  node_transport["HTTP transport<br/>[Transport.php]"]
  node_auth["Auth middleware<br/>[AuthMiddleware.php]"]
  node_authproviders["Auth providers<br/>[AuthProvider.php]"]
  node_bedrock["Bedrock auth<br/>[BedrockAuth.php]"]
  node_vertex["Vertex auth<br/>[VertexAuth.php]"]
end

subgraph group_capabilities["Model features"]
  node_modelcatalog["Model catalog<br/>[Model.php]"]
  node_content["Content blocks<br/>[ContentBlock.php]"]
  node_tools["Tool loop<br/>[ToolLoop.php]"]
  node_tooldefs["Tool definitions"]
end

node_app(("PHP application"))
node_anthropic(("Anthropic API"))

node_app -->|"configures"| node_client
node_client -->|"creates"| node_builder
node_builder -->|"builds"| node_options
node_builder -->|"builds"| node_client
node_client -->|"provides"| node_messages
node_client -->|"provides"| node_models
node_client -->|"provides"| node_files
node_client -->|"provides"| node_batches
node_messages -->|"sends requests"| node_transport
node_models -->|"sends requests"| node_transport
node_files -.->|"sends requests"| node_transport
node_batches -.->|"sends requests"| node_transport
node_transport -->|"runs middleware"| node_auth
node_auth -->|"uses provider"| node_authproviders
node_transport -.->|"sends HTTP"| node_anthropic
node_messages -->|"returns"| node_response
node_messages -->|"creates stream"| node_stream
node_stream -->|"parses events"| node_parser
node_models -->|"returns catalog"| node_modelcatalog
node_messages -->|"normalizes content"| node_content
node_messages -->|"creates loop"| node_tools
node_tools -->|"repeats requests"| node_messages
node_tools -.->|"executes tools"| node_tooldefs
node_bedrock -->|"implements"| node_authproviders
node_vertex -->|"implements"| node_authproviders
node_client -.->|"accepts auth"| node_bedrock
node_client -.->|"accepts auth"| node_vertex

click node_client "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Client.php"
click node_builder "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/ClientBuilder.php"
click node_options "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/ClientOptions.php"
click node_messages "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Resources/Messages.php"
click node_models "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Resources/Models.php"
click node_files "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Resources/Files.php"
click node_batches "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Resources/Batches.php"
click node_response "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Messages/MessageResponse.php"
click node_stream "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Streaming/EventStream.php"
click node_parser "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Streaming/EventParser.php"
click node_transport "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Http/Transport.php"
click node_auth "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Http/Middleware/AuthMiddleware.php"
click node_authproviders "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Auth/AuthProvider.php"
click node_bedrock "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Auth/BedrockAuth.php"
click node_vertex "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Auth/VertexAuth.php"
click node_modelcatalog "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Models/Model.php"
click node_content "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Messages/Content/ContentBlock.php"
click node_tools "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Tools/ToolLoop.php"
click node_tooldefs "https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Tools/Schema/SchemaGenerator.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client,node_builder,node_options toneBlue
class node_messages,node_models,node_files,node_batches,node_response,node_stream,node_parser toneAmber
class node_transport,node_auth,node_authproviders,node_bedrock,node_vertex,node_anthropic toneMint
class node_modelcatalog,node_content,node_tools,node_tooldefs toneRose
class node_app toneIndigo
```

## Components

### Client setup

- [Client](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Client.php): `src/Anthropic/Client.php`
- [Client builder](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/ClientBuilder.php): `src/Anthropic/ClientBuilder.php`
- [Client options](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/ClientOptions.php): `src/Anthropic/ClientOptions.php`

### API resources

- [Messages resource](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Resources/Messages.php): `src/Anthropic/Resources/Messages.php`
- [Models resource](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Resources/Models.php): `src/Anthropic/Resources/Models.php`
- [Files resource](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Resources/Files.php): `src/Anthropic/Resources/Files.php`
- [Batches resource](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Resources/Batches.php): `src/Anthropic/Resources/Batches.php`
- [Message response](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Messages/MessageResponse.php): `src/Anthropic/Messages/MessageResponse.php`
- [SSE stream](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Streaming/EventStream.php): `src/Anthropic/Streaming/EventStream.php`
- [Event parser](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Streaming/EventParser.php): `src/Anthropic/Streaming/EventParser.php`

### Request runtime

- [HTTP transport](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Http/Transport.php): `src/Anthropic/Http/Transport.php`
- [Auth middleware](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Http/Middleware/AuthMiddleware.php): `src/Anthropic/Http/Middleware/AuthMiddleware.php`
- [Auth providers](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Auth/AuthProvider.php): `src/Anthropic/Auth/AuthProvider.php`
- [Bedrock auth](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Auth/BedrockAuth.php): `src/Anthropic/Auth/BedrockAuth.php`
- [Vertex auth](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Auth/VertexAuth.php): `src/Anthropic/Auth/VertexAuth.php`

### Model features

- [Model catalog](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Models/Model.php): `src/Anthropic/Models/Model.php`
- [Content blocks](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Messages/Content/ContentBlock.php): `src/Anthropic/Messages/Content/ContentBlock.php`
- [Tool loop](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Tools/ToolLoop.php): `src/Anthropic/Tools/ToolLoop.php`
- [Tool definitions](https://github.com/alle-ai/anthropic-api-php/blob/main/src/Anthropic/Tools/Schema/SchemaGenerator.php): `src/Anthropic/Tools/Schema/SchemaGenerator.php`

### Other components

- **PHP application**
- **Anthropic API**

## Connections

- PHP application → Client: configures (evidence: `README.md`)
- Client → Client builder: creates (evidence: `src/Anthropic/Client.php`)
- Client builder → Client options: builds (evidence: `src/Anthropic/ClientBuilder.php`)
- Client builder → Client: builds (evidence: `src/Anthropic/ClientBuilder.php`)
- Client → Messages resource: provides (evidence: `src/Anthropic/Client.php`)
- Client → Models resource: provides (evidence: `src/Anthropic/Client.php`)
- Client → Files resource: provides (evidence: `src/Anthropic/Client.php`)
- Client → Batches resource: provides (evidence: `src/Anthropic/Client.php`)
- Messages resource → HTTP transport: sends requests (evidence: `src/Anthropic/Resources/Messages.php`)
- Models resource → HTTP transport: sends requests (evidence: `src/Anthropic/Resources/Models.php`)
- Files resource → HTTP transport: sends requests (evidence: `README.md`)
- Batches resource → HTTP transport: sends requests (evidence: `README.md`)
- HTTP transport → Auth middleware: runs middleware (evidence: `src/Anthropic/Client.php`)
- Auth middleware → Auth providers: uses provider (evidence: `src/Anthropic/Http/Middleware/AuthMiddleware.php`)
- HTTP transport → Anthropic API: sends HTTP (evidence: `README.md`)
- Messages resource → Message response: returns (evidence: `src/Anthropic/Resources/Messages.php`)
- Messages resource → SSE stream: creates stream (evidence: `src/Anthropic/Resources/Messages.php`)
- SSE stream → Event parser: parses events (evidence: `src/Anthropic/Streaming/EventParser.php`)
- Models resource → Model catalog: returns catalog (evidence: `src/Anthropic/Resources/Models.php`)
- Messages resource → Content blocks: normalizes content (evidence: `src/Anthropic/Resources/Messages.php`)
- Messages resource → Tool loop: creates loop (evidence: `src/Anthropic/Resources/Messages.php`)
- Tool loop → Messages resource: repeats requests (evidence: `src/Anthropic/Tools/ToolLoop.php`)
- Tool loop → Tool definitions: executes tools (evidence: `README.md`)
- Bedrock auth → Auth providers: implements (evidence: `src/Anthropic/Auth/BedrockAuth.php`)
- Vertex auth → Auth providers: implements (evidence: `src/Anthropic/Auth/VertexAuth.php`)
- Client → Bedrock auth: accepts auth (evidence: `README.md`)
- Client → Vertex auth: accepts auth (evidence: `README.md`)
