1. Go to this page and download the library: Download do-it-s/claude-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use DoITs\ClaudeClient\ClaudeMessages;
$response = app(ClaudeMessages::class)->send(
feature: 'lyrics',
purpose: 'song-name-normalizer', // which call within the feature; recorded in the log
body: [
'model' => 'claude-sonnet-5-5',
'max_tokens' => 1024,
'messages' => [['role' => 'user', 'content' => 'Hello']],
],
timeoutSeconds: 30,
);
if ($response->failed()) {
report($response->errorMessage());
}
$response->text(); // text blocks, concatenated
$response->toolInput('name'); // input the model filled into a tool, or null
$response->usage();
$response->model();
$response->stopReason();
$response->requestId();
$response->json('content.0.type');
use DoITs\ClaudeClient\Vision\ClaudeVisionClient;
$result = app(ClaudeVisionClient::class)->read(
image: $bytes, // JPEG, PNG, GIF or WebP
prompt: 'Read the chart.',
inputSchema: $jsonSchema, // JSON Schema of the result
feature: 'chart-reading',
model: 'claude-sonnet-5-5',
maxTokens: 24000,
timeoutSeconds: 540,
);
$result['input']; // what the model recorded, matching $inputSchema
$result['usage'];
$result['model'];
use DoITs\ClaudeClient\Support\JsonExtractor;
JsonExtractor::object($text); // outermost {...} decoded, or null
JsonExtractor::list($text); // outermost [...] decoded, or null