-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstreaming_basic.php
More file actions
41 lines (30 loc) · 933 Bytes
/
streaming_basic.php
File metadata and controls
41 lines (30 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env php
<?php
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/helpers.php';
use ClaudePhp\ClaudePhp;
use ClaudePhp\Lib\Streaming\MessageStream;
// Basic streaming example - equivalent to Python SDK example
echo "=== Basic Streaming Example ===\n\n";
$client = createClient();
try {
$rawStream = $client->messages()->stream([
'model' => 'claude-sonnet-4-5',
'max_tokens' => 1024,
'messages' => [
[
'role' => 'user',
'content' => 'Hello',
],
],
]);
$stream = new MessageStream($rawStream);
// Stream text as it arrives (equivalent to Python's text_stream)
echo $stream->textStream();
echo "\n\n";
} catch (\Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
exit(1);
}
echo "✓ Basic streaming completed successfully\n";