cloudflare / cloudflare/ai

Unified provider sends `max_tokens` to OpenAI reasoning models

オープン
#653 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
1.2k
フォーク
345
平均マージ
13時間 31分
マージ済み PR(30日)
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 を短くまとめたダイジェスト。