Download the PHP package claude-php/claude-php-sdk without Composer
On this page you can find all versions of the php package claude-php/claude-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package claude-php-sdk
Claude PHP SDK
If this saves you time, a star on GitHub helps other PHP developers find it.
The unofficial PHP client for the Anthropic Claude API. Requires PHP 8.1+, Composer, and an Anthropic API key.
Quick start
The SDK reads ANTHROPIC_API_KEY from the environment automatically if you don't pass apiKey explicitly.
Sending messages
Streaming
For helper methods over raw events, wrap the stream in MessageStream:
See examples/streaming_comprehensive.php for all event types.
Multi-turn conversations
Tool use
Define tools with a name, description, and JSON Schema input definition. Claude calls them; your code runs them.
For automatic tool loop execution, use the built-in tool runner:
See examples/tool_use_overview.php for the full workflow.
Extended thinking
Claude can reason step-by-step before answering. Three modes are available:
| Mode | Behaviour | When to use |
|---|---|---|
disabled |
No internal reasoning | Fast responses, simple prompts |
enabled |
Always reasons; set budget_tokens |
Deep analysis, guaranteed reasoning |
adaptive |
Model decides based on the prompt | Mixed workloads, cost-conscious |
See examples/adaptive_thinking.php.
Vision and documents
Pass images as base64 or by URL. Pass PDFs or files via the Files API.
See examples/files_api.php.
Batch processing
Process large numbers of requests at 50% of the standard cost, asynchronously.
See examples/batch_processing.php for the full workflow.
Structured outputs
Get guaranteed JSON that matches a schema, without prompt engineering:
See examples/structured_outputs.php.
Server-side tools
These tools are executed by Anthropic's infrastructure — no handler code needed on your side.
Code execution
Claude writes and runs sandboxed code, returning stdout, stderr, and generated files.
Use code_execution_20260120 (beta) for REPL-state persistence across multiple tool calls.
Memory tool
Persistent file-based storage that survives across conversations.
Supports view, create, str_replace, insert, delete, and rename commands.
Web fetch
Retrieve live URL content with domain restrictions and token caps.
See examples/web_fetch.php.
Models
| Constant | Model ID | Best for |
|---|---|---|
MODEL_CLAUDE_OPUS_4_6 |
claude-opus-4-6 |
Frontier reasoning, adaptive thinking |
MODEL_CLAUDE_SONNET_4_6 |
claude-sonnet-4-6 |
Balanced capability and speed |
MODEL_CLAUDE_SONNET_4_5 |
claude-sonnet-4-5-20250929 |
Coding, complex reasoning |
MODEL_CLAUDE_HAIKU_4_5 |
claude-haiku-4-5-20251001 |
Speed and cost efficiency |
MODEL_CLAUDE_3_7_SONNET_LATEST |
claude-3-7-sonnet-latest |
Hybrid reasoning |
MODEL_CLAUDE_3_5_HAIKU_LATEST |
claude-3-5-haiku-latest |
Ultra-fast responses |
Use *_LATEST aliases for automatic updates, or dated IDs (e.g. MODEL_CLAUDE_SONNET_4_5) for pinned deployments. See src/Types/ModelParam.php for the full list.
Client configuration
Alternative authentication
See examples/authentication_flexibility.php.
Error handling
Retries on 429 and 5xx responses happen automatically (configurable via maxRetries). See examples/error_handling.php.
Framework integration
Laravel
Install the first-party package for service provider, facade, and config publishing:
For manual registration without the package:
Symfony
Cloud platforms
| Platform | Class | Example |
|---|---|---|
| Microsoft Azure AI Foundry | ClaudePhp\Lib\Foundry\AnthropicFoundry |
examples/foundry.php |
| AWS Bedrock | ClaudePhp\Lib\Bedrock\AnthropicBedrock |
— |
| Google Vertex AI | ClaudePhp\Lib\Vertex\AnthropicVertex |
— |
Examples and tutorials
85+ runnable examples organised by topic — streaming, vision, tool use, batching, prompt caching, context management, and more:
Highlights:
- examples/quickstart.php — 10-line hello world
- examples/streaming_comprehensive.php — all streaming patterns
- examples/tool_use_overview.php — full tool use workflow
- examples/extended_thinking.php — thinking budgets and modes
- examples/prompt_caching.php — 90% cost reduction on repeated context
- examples/batch_processing.php — 50% cost savings at scale
- tutorials/README.md — start the agentic AI tutorial series
Development
Contributing
- Fork and clone the repo
- Run
composer install - Make your changes, add tests
- Ensure
composer test,composer lint, andcomposer stanall pass - Open a pull request
A note to Anthropic
This SDK was built independently by Dale Hurley to give the PHP community a first-class Claude integration — the same one the Python and TypeScript communities already enjoy. It tracks the official API closely, ships 85+ examples covering every docs page, and has a full tutorial series for building agentic systems.
If you work at Anthropic and would like to sponsor, officially adopt, or collaborate on this project, I'd love to hear from you. Reach out via GitHub Discussions or the email in my profile.
License
MIT — see LICENSE
Support
All versions of claude-php-sdk with dependencies
psr/http-client Version ^1.0
psr/http-message Version ^1.0 || ^2.0
psr/http-factory Version ^1.1
psr/container Version ^1.1 || ^2.0
amphp/amp Version ^3.1
guzzlehttp/guzzle Version ^7.10
nyholm/psr7 Version ^1.8