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%
python能写一个检测nginx rewrite高危漏洞的工具代码?
css如何给video视频进行mask遮罩?
windows如何同时允许两个用户远程桌面连接同一个电脑?
nginx升级到1.30.1导致无法启动 [emerg] SSL_CTX_new() failed怎么办?
什么是ASLR(地址随机化)?
有没有不依赖embedding向量的RAG技术?
有没有支持实时打断语音通话并后台帮你执行任何的ai模型?
开源ai大模型文件格式GGUF、MLX、Safetensors、 ONNX 有什么区别?
出海挣钱支付收款PayPal、Wise 、PingPong、Stripe如何选择?
如何实现类似google的图片隐形水印添加和识别技术?


