Download the PHP package mozex/anthropic-php without Composer
On this page you can find all versions of the php package mozex/anthropic-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mozex/anthropic-php
More information about mozex/anthropic-php
Files in mozex/anthropic-php
Package anthropic-php
Short Description Anthropic PHP is a supercharged community-maintained PHP API client that allows you to interact with Anthropic API.
License MIT
Informations about the package anthropic-php
Anthropic PHP is a community-maintained PHP API client that allows you to interact with the Anthropic API. This package is based on the excellent work of Nuno Maduro and Sandro Gehri.
Note: If you want to use the Anthropic PHP in Laravel, take a look at the mozex/anthropic-laravel repository.
Table of Contents
- Support Us
- Get Started
- Usage
- Completions Resource
- Messages Resource
- Meta Information
- Troubleshooting
- Testing
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
Support us
Creating and maintaining open-source projects requires significant time and effort. Your support will help enhance the project and enable further contributions to the PHP community.
Sponsorship can be made through the GitHub Sponsors program. Just click the "Sponsor" button at the top of this repository. Any amount is greatly appreciated, even a contribution as small as $1 can make a big difference and will go directly towards developing and improving this package.
Thank you for considering sponsoring. Your support truly makes a difference!
Get Started
Requires PHP 8.1+
First, install Anthropic via the Composer package manager:
Ensure that the php-http/discovery
composer plugin is allowed to run or install a client manually if your project does not already have a PSR-18 client integrated.
Then, interact with Anthropic's API:
If necessary, it is possible to configure and create a separate client.
Usage
Completions
Resource
create
Creates a completion for the provided prompt and parameters.
create streamed
Creates a streamed completion for the provided prompt and parameters.
Messages
Resource
create
Creates a completion for structured list of input messages.
create streamed
Creates a streamed completion for structured list of input messages.
Meta Information
On messages response object you can access the meta information returned by the API via the meta()
method.
The toArray()
method returns the meta information in the form originally returned by the API.
On streaming responses you can access the meta information on the reponse stream object.
For further details about the rates limits and what to do if you hit them visit the Anthropic documentation.
Troubleshooting
Timeout
You may run into a timeout when sending requests to the API. The default timeout depends on the HTTP client used.
You can increase the timeout by configuring the HTTP client and passing in to the factory.
This example illustrates how to increase the timeout using Guzzle.
Testing
The package provides a fake implementation of the Anthropic\Client
class that allows you to fake the API responses.
To test your code ensure you swap the Anthropic\Client
class with the Anthropic\Testing\ClientFake
class in your test case.
The fake responses are returned in the order they are provided while creating the fake client.
All responses are having a fake()
method that allows you to easily create a response object by only providing the parameters relevant for your test case.
In case of a streamed response you can optionally provide a resource holding the fake response data.
After the requests have been sent there are various methods to ensure that the expected requests were sent:
To write tests expecting the API request to fail you can provide a Throwable
object as the response.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Mozex
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of anthropic-php with dependencies
php-http/discovery Version ^1.20.0
php-http/multipart-stream-builder Version ^1.4.2
psr/http-client Version ^1.0.3
psr/http-client-implementation Version ^1.0.1
psr/http-factory-implementation Version *
psr/http-message Version ^1.1.0|^2.0.0