Cloudflare AI Gateway provider 测试失败 - 未正确使用 /compat 端点和认证头

环境

  • Alma Version: 0.0.698

  • OS: macOS

  • 日期: 2026-03-16

问题描述

Alma 内置的 cloudflare-ai-gateway provider 存在以下问题:

  1. 可以获取模型列表,但在测试模型连接时失败

  2. 错误: Internal Server Error

根本原因

根据 Cloudflare 官方文档,使用 BYOK (Bring Your Own Keys) 时:

  • 路径应该是 /compat/chat/completions(不是 /openai/chat/completions

  • 需要 header: cf-aig-authorization: Bearer {CF_TOKEN}

  • Model 名称需要带提供商前缀,如 openai/gpt-5(不是 gpt-5

  • 不需要 Authorization header(因为 key 已存在 CF)

Alma 的 cloudflare-ai-gateway provider 可能:

  • 没有使用 /compat 端点

  • 没有正确发送 cf-aig-authorization header

  • 没有给 model 名称加提供商前缀

复现步骤

  1. 在 Cloudflare Dashboard → AI Gateway → Provider Keys 添加 OpenAI API Key

  2. 在 Alma 配置 cloudflare-ai-gateway provider,填写 CF 认证 token

  3. 点击测试 OpenAI 模型 → 失败

  4. 手动用 curl 测试可以成功:

curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/my-gateway/compat/chat/completions \
  --header "cf-aig-authorization: Bearer $CF_TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "openai/gpt-5",
    "messages": [{"role": "user", "content": "Hi"}]
  }'

Please authenticate to join the conversation.

Upvoters
Status

In Review

Board
🐛

Bug Reports

Date

About 3 hours ago

Author

Coffee

Subscribe to post

Get notified by email when there are changes.