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

Response

200
application/json

成功响应

The response is of type object.