Skip to main content
LibreChat is joining ClickHouse to power the open-source Agentic Data Stack 🎉 Learn more
LibreChat

Portkey AI

将 Portkey AI 配置为 LibreChat 中的自定义 endpoint。

Portkey 是一个 AI 网关,通过兼容 OpenAI 的 endpoint 为 250 多种模型提供前端支持,并增加了可观测性、50 多种护栏、缓存以及带有回退和重试机制的条件路由。请在 Portkey docs 中查看完整的提供商列表。

获取 API key

app.portkey.ai 创建一个密钥并将其添加到您的 .env 文件中。您还需要一个网关 URL,Portkey 为自托管或托管网关提供了该 URL:

PORTKEY_API_KEY=your-api-key
PORTKEY_GATEWAY_URL=your-gateway-url

配置

LibreChat 需要 apiKey 字段,但 Portkey 不使用它,因此请传入字符串 dummy。身份验证通过 x-portkey-* 请求头进行。根据您是通过 Virtual Keys 还是 Configs 进行路由,有两种连接方式。请在 librechat.yaml 中的 endpoints.custom 下添加以下内容之一。

虚拟密钥 (Virtual Keys)

    - name: "Portkey"
      apiKey: "dummy"
      baseURL: ${PORTKEY_GATEWAY_URL}
      headers:
        x-portkey-api-key: "${PORTKEY_API_KEY}"
        x-portkey-virtual-key: "PORTKEY_OPENAI_VIRTUAL_KEY"
      models:
        default: ["gpt-4o-mini"]
        fetch: true
      titleConvo: true
      titleModel: "current_model"
      summarize: false
      summaryModel: "current_model"
      modelDisplayLabel: "Portkey:OpenAI"
      iconURL: https://images.crunchbase.com/image/upload/c_pad,f_auto,q_auto:eco,dpr_1/rjqy7ghvjoiu4cd1xjbf

配置

    - name: "Portkey"
      apiKey: "dummy"
      baseURL: ${PORTKEY_GATEWAY_URL}
      headers:
        x-portkey-api-key: "${PORTKEY_API_KEY}"
        x-portkey-config: "pc-libre-xxx"
      models:
        default: ["llama-3.2"]
        fetch: true
      titleConvo: true
      titleModel: "current_model"
      summarize: false
      summaryModel: "current_model"
      modelDisplayLabel: "Portkey:Llama"
      iconURL: https://images.crunchbase.com/image/upload/c_pad,f_auto,q_auto:eco,dpr_1/rjqy7ghvjoiu4cd1xjbf

注意事项

  • Configs 允许您在 Portkey 端设置特定于模型的参数,例如 top_pmax_tokens。请参阅 Configs docs
  • PORTKEY_OPENAI_VIRTUAL_KEYpc-libre-xxx 替换为您 Portkey 仪表板中的虚拟密钥或配置 ID。

这篇指南怎么样?