Download the PHP package rkzack/akit without Composer
On this page you can find all versions of the php package rkzack/akit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package akit
akit — Anthropic Kit for PHP
Lightweight PHP 8.4 toolkit for building AI-powered applications with the Anthropic API.
Zero production dependencies. Uses only PHP's built-in curl and json extensions.
Fully typed with PHP 8.4 features: readonly classes, enums, named arguments, and array_find.
Requirements
- PHP 8.4+
ext-curlext-json- An Anthropic API key
Installation
Copy .env.example to .env and add your key:
vendor/is generated by Composer — keep it in.gitignoreand never edit it directly. Commitcomposer.lock; teammates runcomposer installto get identical versions.
Quick Start
Usage
Single Prompt
System Prompt
Multi-turn Conversation
The Conversation class tracks message history automatically — no need to manage arrays.
Streaming
Chunks arrive as they are generated rather than waiting for the full response. Ideal for long outputs, CLI tools, or real-time web UIs.
Model Selection
Available models:
| Enum constant | Model ID |
|---|---|
Model::OPUS_4_7 |
claude-opus-4-7 |
Model::SONNET_4_6 |
claude-sonnet-4-6 (default) |
Model::HAIKU_4_5 |
claude-haiku-4-5-20251001 |
Environment-based Configuration
Manual Message Arrays (Advanced)
Global Helper Functions
Helper functions wrap the shared singleton client seeded from ANTHROPIC_API_KEY.
They are the fastest way to add Claude to a script.
| Function | Description |
|---|---|
akit_prompt(string $prompt, ...) |
Send a prompt, get back the text string |
akit_stream(string $prompt, callable $onChunk, ...) |
Stream a response |
akit_chat(array $messages, ...) |
Multi-message array → Response |
akit_client(?string $apiKey, ?string $model) |
Get or create the shared Client |
API Reference
Client
| Method | Signature | Returns |
|---|---|---|
prompt |
(string $prompt, ?string $system, ?string $model, ?int $maxTokens) |
Response |
chat |
(Message[] $messages, ?string $system, ?string $model, ?int $maxTokens) |
Response |
stream |
(string\|Message[] $prompt, callable $onChunk, ?string $system, ?string $model, ?int $maxTokens) |
void |
conversation |
(?string $system) |
Conversation |
config |
() |
Config |
Response
| Method | Returns | Description |
|---|---|---|
text() |
string |
Primary text content |
model() |
string |
Model that generated the response |
stopReason() |
string |
end_turn, max_tokens, etc. |
usage() |
array |
{input_tokens, output_tokens} |
totalTokens() |
int |
Input + output tokens |
id() |
string |
Anthropic message ID |
content() |
array |
All raw content blocks |
raw() |
array |
Full decoded API payload |
asMessage() |
Message |
Convert to assistant Message |
__toString() |
string |
Alias for text() |
Conversation
| Method | Returns | Description |
|---|---|---|
say(string $message, ...) |
Response |
Send a turn, append history |
messages() |
Message[] |
Full history so far |
turns() |
int |
Number of user turns |
reset() |
void |
Clear history (keeps system prompt) |
Config
| Property | Type | Default |
|---|---|---|
apiKey |
string |
(required) |
model |
string |
claude-sonnet-4-6 |
maxTokens |
int |
1024 |
baseUrl |
string |
https://api.anthropic.com/v1 |
apiVersion |
string |
2023-06-01 |
timeout |
int |
30 (seconds) |
Error Handling
All exceptions extend Akit\Exceptions\AkitException.
| Exception | HTTP Status | Cause |
|---|---|---|
AuthException |
401 | Invalid or missing API key |
ApiException |
4xx / 5xx | Rate limit, overload, bad request, etc. |
Running the Examples
Running Tests
Contributing
- Fork the repo and create a branch from
main. - Add tests for any new behaviour.
- Run
./vendor/bin/phpunitand./vendor/bin/phpstan analysebefore opening a PR. - Keep it lightweight — no new production dependencies without strong justification.
License
MIT — see LICENSE.
All versions of akit with dependencies
ext-curl Version *
ext-json Version *