-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathquickstart.php
More file actions
executable file
·42 lines (36 loc) · 1.05 KB
/
quickstart.php
File metadata and controls
executable file
·42 lines (36 loc) · 1.05 KB
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
42
#!/usr/bin/env php
<?php
/**
* Quickstart Example - Matches the exact example from:
* https://docs.claude.com/en/docs/get-started
*
* This is the simplest possible example to get started with Claude.
*/
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/helpers.php';
use ClaudePhp\ClaudePhp;
// Set up your API key
loadEnv(__DIR__ . '/../.env');
$client = new ClaudePhp(apiKey: getApiKey());
// Make your first API call
$response = $client->messages()->create([
'model' => 'claude-sonnet-4-5',
'max_tokens' => 1000,
'messages' => [
[
'role' => 'user',
'content' => 'What should I search for to find the latest developments in renewable energy?'
]
]
]);
// Output the response
echo "Response:\n";
foreach ($response->content as $block) {
if ($block['type'] === 'text') {
echo $block['text'] . "\n";
}
}
// Show usage information
echo "\nUsage:\n";
echo " Input tokens: {$response->usage->input_tokens}\n";
echo " Output tokens: {$response->usage->output_tokens}\n";