Appearance
Anthropic兼容接口
接口示例
所有请求主需要替换域名,然后增加一个额外的/anthropic前缀即可,以下为示例
官方接口
shell
curl --location 'https://api.anthropic.com/v1/messages' \
--header 'x-api-key: sk-ant-apixxxxxxx' \
--header 'anthropic-version: 2023-06-01' \
--header 'content-type: application/json' \
--data '{
"model": "claude-3-opus-20240229",
"max_tokens": 1024,
"stream":true,
"messages": [
{"role": "user", "content": "hi"}
]
}'
兼容接口
shell
curl --location 'https://api.openai-proxy.org/anthropic/v1/messages' \
--header 'x-api-key: sk-xxxx' \
--header 'anthropic-version: 2023-06-01' \
--header 'content-type: application/json' \
--data '{
"model": "claude-3-opus-20240229",
"max_tokens": 1024,
"stream":false,
"messages": [
{"role": "user", "content": "hi"}
]
}'
Python使用
python
from anthropic import Anthropic
if __name__ == '__main__':
client = Anthropic(
base_url='https://api.openai-proxy.org/anthropic',
api_key='sk-xxxx',
)
message = client.messages.create(
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Hello, Claude",
}
],
model="claude-3-opus-20240229",
)
print(message.content)
客户端使用
支持Anthropic的客户端都可以直接使用我们的兼容接口,配置方式如下: