Anthropic publishes an official PHP SDK on Packagist as anthropic-ai/sdk. If your customer portals, CMS integrations, or e-commerce backends are PHP, this is the supported route to Claude. It requires PHP 8.1.0 or newer — new enough to use modern language features like named arguments, old enough that most actively maintained applications already qualify. If you are still on 8.0 or earlier, plan the runtime upgrade first.
Step 1: Install with Composer
composer require "anthropic-ai/sdk:^0.36.0"
The caret constraint takes compatible updates without surprise jumps. Note the version number: a pre-1.0 constraint signals the SDK's interface may still evolve between minor versions, so read release notes before upgrading and pin exact versions in composer.lock as you would for any dependency in production. The version shown is current as of this writing; the official repository lists the latest.
Step 2: Create the client
use Anthropic\Client;
$client = new Client(apiKey: getenv('ANTHROPIC_API_KEY'));
The client class is Anthropic\Client, and the constructor uses PHP 8's named arguments. Passing the key from getenv() keeps it out of source code; calling new Client() with no arguments does the same thing implicitly, reading ANTHROPIC_API_KEY from the environment. The key itself is created in the Claude Console under Settings → API keys. It is long-lived — no expiry — so keep it in your platform's secret store or a dedicated secrets manager, rotate periodically, and revoke on suspected exposure. For workloads on cloud platforms or CI/CD, Anthropic recommends Workload Identity Federation (short-lived tokens exchanged from your identity provider) instead of long-lived keys.
Step 3: First call
$message = $client->messages->create(
maxTokens: 1024,
messages: [['role' => 'user', 'content' => 'Hello, Claude']],
model: 'claude-sonnet-5',
);
The parameters mirror the underlying Messages API, camelCased for PHP: model picks the Claude model (claude-sonnet-5 for balanced work, claude-opus-4-8 for complex enterprise and agentic tasks, claude-haiku-4-5 for fast, high-volume calls), maxTokens caps the reply length in tokens — the unit you are billed in — and messages carries the conversation as role/content pairs.
The return value is a structured message object, not a string: reply content arrives as a list of content blocks (responses can mix text with tool-use requests), alongside the stop reason and input/output token counts. In a typical PHP application, wrap this in a small service class so there is one place to select the model, log token usage for cost attribution, and fake responses in tests.
HTTP transport and middleware
The SDK ships working HTTP out of the box — no transport assembly required for the common case. It also exposes a middleware pipeline for teams that need to observe or shape requests (logging, custom headers, proxies); notably, backend adaptation such as OAuth token refresh and cloud-platform request signing runs in the innermost middleware layer, so your middleware sees requests before that machinery. For the current details of HTTP-client interoperability and customization, rely on the official repository's README rather than assumptions carried over from other PHP HTTP libraries.
PHP and the third-party platforms
The anthropic-ai/sdk package targets Anthropic's first-party Claude API. For Claude Platform on AWS — Anthropic-operated, inside AWS — a beta AWS client is available (installed alongside the AWS SDK for PHP, with a dedicated client class handling SigV4 signing and workspace configuration). For Amazon Bedrock, Google Vertex AI, or Microsoft Foundry from PHP, check each platform's own documentation for supported clients; the platform concepts in the Bedrock, Vertex AI, and Foundry guides apply in any language.
Where to go next
Harden credentials with API key authentication and secrets-out-of-code patterns, then see the SDK language overview or the platform quickstart.