PHP code example of dikki / claude-sdk

1. Go to this page and download the library: Download dikki/claude-sdk 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/ */

    

dikki / claude-sdk example snippets




use Dikki\Claude\ClaudeBuilder;
use Dikki\Claude\Message\MessageBuilder;

// Initialize Claude client
$claude = (new ClaudeBuilder())
    ->withApiKey('your-api-key')
    ->build();
// Build message
$messages = (new MessageBuilder())
    ->assistant("You are a helpful AI assistant.")
    ->user("What is the meaning of life?")
    ->build();
// Send request and get response
$response = $claude->send($messages);
echo $response->getContent();
// Or use streaming for real-time responses
foreach ($claude->stream($messages) as $chunk) {
    echo $chunk->getContent();
}