POST
/
chat
/
completions
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.