cloudflare / cloudflare/ai

Unified provider sends `max_tokens` to OpenAI reasoning models

Đang mở
#653 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
1.2k
Fork
345
Merge trung bình
13 giờ 31 phút
Pull request đã merge (30 ngày)
1

Mô tả

`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`.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start at createUnified() and its createOpenAICompatible instance, then trace how transformRequestBody receives Cloudflare’s model-capability metadata and maps standardized maxOutputTokens. Reproduce the openai/o1-mini request and verify that reasoning models send max_completion_tokens while other models retain their existing parameter behavior.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
typescript
Lĩnh vực
ai, api
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
70/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.