Claude 图片分析 API 文档
接口地址
POST https://www.dmxapi.cn/v1/chat/completions
请求头
参数 | 类型 | 说明 |
---|---|---|
Accept | string | 必须为 application/json |
Authorization | string | Bearer令牌,格式: Bearer ****** |
Content-Type | string | 必须为 application/json |
请求参数
python
{
"model": "claude-3-5-sonnet-20240620", # 模型名称
"messages": [
{
"role": "system",
"content": "You are a helpful assistant." # 系统提示
},
{
"role": "user",
"content": [
{"type": "text", "text": "这张图片里有什么?请详细描述。"}, # 文本内容
{
"type": "image_url",
"image_url": {"url": "https://dmxapi.com/111.jpg"}, # 图片URL
},
],
},
],
"stream": True # 是否启用流式输出
}
Python调用示例
python
import json
import requests
# 配置API密钥和URL
API_KEY = "sk-******" # 替换为你的API密钥
url = "https://www.dmxapi.cn/v1/chat/completions"
# 准备请求数据
payload = json.dumps({
"model": "claude-3-5-sonnet-20240620",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{
"role": "user",
"content": [
{"type": "text", "text": "这张图片里有什么?请详细描述。"},
{
"type": "image_url",
"image_url": {"url": "https://dmxapi.com/111.jpg"},
},
],
},
],
"stream": True
})
# 设置请求头
headers = {
"Accept": "application/json",
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
}
# 发送POST请求
response = requests.post(url, headers=headers, data=payload)
# 打印响应结果
print(response.text)
注意事项
- 请妥善保管API密钥,不要泄露
- 图片URL需要可公开访问,图片网站没有做防盗链。
- 流式输出适合需要实时显示结果的场景