cloudflare / cloudflare/ai

Unified provider sends `max_tokens` to OpenAI reasoning models

Aperta
#653 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
1.2k
Fork
345
Merge medio
13h 31m
PR unite (30g)
1

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
ai, api
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
70/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.