Access to Anthropic's safety-first language model APIs in PHP
// momentum
// why it's here
- Active: last commit today
- Built almost entirely by one person
// how to help
// readme
Anthropic SDK for PHP
The Anthropic SDK for PHP provides access to the Claude API from PHP applications.
Documentation
Full documentation is available at platform.claude.com/docs/en/api/sdks/php.
Installation
composer require "anthropic-ai/sdk:^1.15.0"
The SDK needs a PSR-18 HTTP client. If you donβt have one installed, add Guzzle:
composer require guzzlehttp/guzzle
Getting started
<?php
use Anthropic\Client;
use Anthropic\Messages\Model;
$client = new Client(
apiKey: getenv('ANTHROPIC_API_KEY') ?: 'my-anthropic-api-key'
);
$message = $client->messages->create(
maxTokens: 1024,
messages: [['role' => 'user', 'content' => 'Hello, Claude']],
model: Model::CLAUDE_OPUS_5_5,
);
var_dump($message->content);
Requirements
PHP 8.1.0+
Contributing
See CONTRIBUTING.md.