说明

Claude 系列模型支持通过官方原生接口调用,使用之前确保安装或升级 anthropic 依赖:

pip install -U anthropic

非 claude 模型请用 openai 的接口格式调用。

端点(Endpoint): POST /v1/messages

调用

curl https://aihubmix.com/v1/messages \
     --header "x-api-key: $ANTHROPIC_API_KEY" \ # 换成你在 AiHubMix 生成的密钥
     --header "anthropic-version: 2023-06-01" \
     --header "content-type: application/json" \
     --data \
'{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 1024,
    "messages": [
        {"role": "user", "content": "Hello, world"}
    ]
}'

Body 请求结构

{
  "model": "claude-3-5-sonnet-20241022",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "What is the meaning of life?"
    }
  ]
}

请求参数

名称位置类型必选说明
x-api-keyheaderstringBearer AIHUBMIX_API_KEY
Content-Typeheaderstringnone
bodybodyobjectnone
» modelbodystringnone
» messagesbody[object]none
»» rolebodystringnone
»» contentbodystringnone
» max_tokensbodynumbernone

返回示例

200 Response
{
  "id": "msg_013Uf6CwwyjSe35n3yVaPbLM",
  "type": "message",
  "role": "assistant",
  "model": "claude-3-5-sonnet-20241022",
  "content": [
    {
      "type": "text",
      "text": "That's one of humanity's most enduring and complex philosophical questions! While there's no universal answer, I aim to explore such questions thoughtfully while acknowledging their complexity. I try to focus on having meaningful conversations and helping where I can. What does meaning in life mean to you?"
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 14,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 61
  }
}

返回结果

状态码状态码含义说明数据模型
200OKnoneInline

在应用中使用(以 Lobe-Chat 为例)

  • 进入设置页面选择模型服务商 Claude
  • API key 输入本站的 Key
  • 接口代理地址,直接输入下方的网址:
https://aihubmix.com
  • 建议打开「使用客户端请求模式」

  • 最后在模型列表添加自己要使用的模型(建议从我们网站的设置页面复制粘贴模型名后选择)