php如何调用claude的api接口?
网友回复
首先也要登录claude的后台申请key
https://console.anthropic.com/settings/keys
php
<?php
$ANTHROPIC_API_KEY = 'your_api_key'; // Replace with your actual API key
$url = 'https://api.anthropic.com/v1/messages';
$data = array(
"model" => "claude-3-5-sonnet-20240620",
"max_tokens" => 1024,
"messages" => array(
array("role" => "user", "content" => "Hello, Claude")
)
);
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'x-api-key: ' . $ANTHROPIC_API_KEY,
'anthropic-version: 2023-06-01',
'content-type: application/json',
'Content-Length: ' . strlen($data_string))
);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$json_response = json_decode($r...点击查看剩余70%
如何让ai帮我自动在小红书或抖音上自动根据需求截流与潜在客户聊天拉客?
如果用go编写一个在virtualbox中启动的简单操作系统?
go如何搭建一个零信任网络?
如何用python实现一个公网代理访问软件?
如何用go实现一个公网代理访问软件?
如何用python实现一个内网穿透打洞程序,实现内网的80端口暴露到公网上可以访问?
如何用go实现一个内网穿透打洞程序,实现内网的80端口暴露到公网上可以访问?
何为Shadowsocks 代理?
python如何实现类似php的opendir目录相互隔离的fastcgi多租户虚拟空间?
nodejs如何实现类似php的opendir目录相互隔离的fastcgi多租户虚拟空间?


