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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package claude-php-sdk

Claude PHP SDK

GitHub Stars

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:

Laravel Package →

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:


Development


Contributing

  1. Fork and clone the repo
  2. Run composer install
  3. Make your changes, add tests
  4. Ensure composer test, composer lint, and composer stan all pass
  5. 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

PHP Build Version
Package Version
Requires php Version ^8.1
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
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package claude-php/claude-php-sdk contains the following files

Loading the files please wait ...