跳到主要内容

Portkey

Portkey 是 GenAI 构建者的生产技术栈。 官方网站:portkey.ai

1.1 使用方法

方式一:通过模型目录添加自定义提供商(推荐)

  1. 登录 Portkey 仪表板,进入 Model Catalog

  2. 选择 Add ProviderSelf-hosted / Custom

  3. 输入 API 端点和 API Key

  4. 添加自定义模型并设置 Model Slug

  5. 使用 @luchentech/minimax/minimax-m2.5 调用

方式二:透传模式

from portkey_ai import Portkey

client = Portkey(
api_key="PORTKEY_API_KEY",
provider="passthrough",
custom_host="https://api.luchentech.com/inference/v1",
default_headers={
"authorization": "Bearer YOUR_HPC_AI_API_KEY"
}
)

response = client.chat.completions.create(
model="minimax/minimax-m2.5",
messages=[{"role": "user", "content": "Hello!"}]
)

方式三:cURL

curl https://api.portkey.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "x-portkey-api-key: $PORTKEY_API_KEY" \
-H "x-portkey-provider: passthrough" \
-H "x-portkey-custom-host: https://api.luchentech.com/inference/v1" \
-H "authorization: Bearer YOUR_HPC_AI_API_KEY" \
-d '{
"model": "minimax/minimax-m2.5",
"messages": [{"role": "user", "content": "Hello!"}]
}'

方式四:OpenAI SDK 兼容

from openai import OpenAI

client = OpenAI(
api_key="PORTKEY_API_KEY",
base_url="https://api.portkey.ai/v1"
)

# 通过请求头指定提供商
response = client.chat.completions.create(
model="minimax/minimax-m2.5",
messages=[{"role": "user", "content": "Hello!"}],
extra_headers={
"x-portkey-provider": "passthrough",
"x-portkey-custom-host": "https://api.luchentech.com/inference/v1"
}
)

1.2 故障排除

常见问题解决方案
请求失败验证 custom_host URL 格式
授权失败确保正确传递 authorization 请求头
模型未找到确保 Model Slug 与添加的自定义模型匹配

1.3 参考