POST
/
chat
/
completions
Python
from openai import OpenAI

client = OpenAI(
    base_url="https://aihubmix.com/v1",
    api_key="AIHUBMIX_API_KEY"
)

completion = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "你好"}]
)

print(completion.choices[0].message)
{
  "choices": [
    {
      "message": {
        "role": "<string>",
        "content": "<string>"
      },
      "finish_reason": "<string>"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  }
}
API 沙盒环境支持实时请求调试,直观查看接口返回数据。
为了代码安全,建议:
  1. 通过环境变量管理敏感信息(如 API Key),比如对于 Python 调用,使用 os.getenv("AIHUBMIX_API_KEY")
  2. 不要在日志/输出中打印敏感信息。
  3. 不要将密钥提交到代码仓库,可以通过将 .env 添加到 .gitignore 来防止泄漏。

Authorizations

Authorization
string
header
required

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

Body

application/json

Response

200
application/json

成功响应

The response is of type object.