聊天接口
POST
/claude/v1/messages这里只列出部分常用参数,完整参数说明参考 Claude 官方文档:https://docs.anthropic.com/claude/reference/messages_post
模型定价均为官方定价的 1.5 倍。
支持用同样的方式设置和使用 API2D 提供的【搜索】、【知识库】、【联网】功能。
Claude 入口已经兼容 OpenAI 应用,直接在 OpenAI 应用中使用地址 https://oa.api2d.net/claude 即可使用 Claude。所有 GPT-3 模型会被映射为 claude-3-5-sonnet-20240620,所有 GPT-4 模型会被映射为 claude-3-opus-20240229。
请求参数
Header Params
x-api-key
string
required
x-api-key和Authorization作用相同,选一个使用即可。x-api-key主要是为了兼容Claude的参数格式。
Example:
fk186009-...
Body Params application/json
model
enum<string>
required
Allowed values:
claude-3-opus-20240229claude-3-sonnet-20240229claude-3-haiku-20240307claude-2.1claude-2.0claude-instant-1.2
messages
array [object {2}]
required
<= 1 items
role
string
required
content
string
required
stream
boolean
optional
是否启用流式返回
Default:
false
max_tokens
integer
optional
如果不指定,每次请求会预先冻结模型支持的最大生成 Token(目前是 4096),在请求完成后按 usage 字段多退少补。如果账户余额不够冻结就会报错,此时可以指定一个比较小的 max_tokens,这样就会按 max_tokens 来冻结
Example
{
"model": "claude-3-opus-20240229",
"messages": [
{
"role": "user",
"content": "讲个笑话"
}
],
"stream": true,
"max_tokens": 100
}
示例代码
Responses
OK(200)
HTTP 状态码: 200
内容格式: JSONapplication/json
Data Schema
object {0}
Example
event: message_start
data: {"type":"message_start","message":{"id":"msg_01GbTJMWgepqJMBQedFmZybG","type":"message","role":"assistant","content":[],"model":"claude-instant-1.2","stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":16,"output_tokens":1}}}
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}
event: ping
data: {"type":"ping"}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"今"}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"年"}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"是"}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"2022"}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"年"}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"。"}}
event: content_block_stop
data: {"type":"content_block_stop","index":0}
event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"output_tokens":11}}
event: message_stop
data: {"type":"message_stop"}
Last modified: 5 个月前