cloudflare / cloudflare/ai

Unified provider sends `max_tokens` to OpenAI reasoning models

未关闭
#653 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
1.2k
派生
345
平均合并
13 小时 31 分钟
30 天内合并 PR
1

描述

`ai-gateway-provider`’s Unified route currently creates its models via `@ai-sdk/openai-compatible`:

```ts
const unified = createUnified();
const model = aigateway(unified('openai/o1-mini'));
```

When used with AI SDK’s standardized `maxOutputTokens`, the outgoing Chat Completions request contains:

```json
{
"model": "openai/o1-mini",
"max_tokens": 1000
}
```

OpenAI reasoning models reject this field and require `max_completion_tokens` instead:

```text
Unsupported parameter: 'max_tokens' is not supported with this model.
Use 'max_completion_tokens' instead.
```

The native Cloudflare OpenAI adapter does not have the issue:

```ts
const openai = createOpenAI();
const model = aigateway(openai.chat('o1-mini'));
```

That route uses `@ai-sdk/openai`, which performs the correct OpenAI-specific parameter mapping.

Suggested fix: have `createUnified()` supply `transformRequestBody` to its `createOpenAICompatible` instance. When Cloudflare’s model-capability metadata identifies an OpenAI reasoning model, move `max_tokens` to `max_completion_tokens`.

贡献指南

打开贡献指南

调研方向

从 createUnified() 及其 createOpenAICompatible 实例开始,然后跟踪 transformRequestBody 如何接收 Cloudflare 的模型能力元数据并映射标准化的 maxOutputTokens。复现 openai/o1-mini 请求,并验证推理模型会发送 max_completion_tokens,而其他模型保留其现有的参数行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
ai, api
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
70/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。