POST
/
chat
/
completions
import requests

url = 'https://aihubmix.com/v1/chat/completions'
headers = {
    'Authorization': 'Bearer AIHUBMIX_API_KEY',
    'Content-Type': 'application/json'
}
data = {
    'model': 'gpt-3.5-turbo',
    'messages': [
        {'role': 'user', 'content': '你好'}
    ]
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
{
  "choices": [
    {
      "message": {
        "role": "<string>",
        "content": "<string>"
      },
      "finish_reason": "<string>"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  }
}

The API Playground provides a sandbox environment for real-time request testing and intuitive response data visualization.

For code security, we recommend:

  1. Managing sensitive information (such as API Keys) through environment variables. For Python calls, use os.getenv("AIHUBMIX_API_KEY").
  2. Avoiding printing sensitive information in logs/outputs.
  3. Preventing key leakage by adding .env to .gitignore to keep secrets out of the code repository.

Authorizations

Authorization
string
header
required

Bearer 认证,需要在请求头中添加 Authorization: Bearer AIHUBMIX_API_KEY,可在 这里 获取 API 密钥

Body

application/json
model
string
required

要使用的模型 ID,可在 模型广场 查看可用模型列表

messages
object[]
required

对话消息列表,包含角色和内容信息

temperature
number
default:0.8

采样温度,控制输出的随机性,范围 0-2,值越大随机性越高

max_tokens
integer
default:1024

生成文本的最大长度,根据模型能力可设置不同值

top_p
number
default:1

核采样参数,控制输出文本的多样性

frequency_penalty
number
default:0

频率惩罚参数,避免重复生成相似内容

presence_penalty
number
default:0

存在惩罚参数,鼓励生成新的内容

stream
boolean
default:false

是否启用流式输出,实时返回生成内容

web_search_options
object

搜索模型的网络搜索选项,仅支持特定搜索模型

Response

200
application/json
成功响应
choices
object[]
usage
object