createAI: numeric stream deltas from Workers AI are dropped · Issue #2627 · cloudflare/agents · GitHub
Skip to content

createAI: numeric stream deltas from Workers AI are dropped #2627

Open

Description

@mattzcarey

Workers AI sometimes streams a numeric-looking token as a JSON number instead of a string, e.g. {"choices":[{"delta":{"content":0.005}}]}. createAI drops it silently, so $0.005 comes out as $ and [1] as [].

const ai = createAI({ binding: env.AI });
const { text } = streamText({ model: ai("@cf/meta/llama-3.3-70b-instruct-fp8-fast"), prompt });
// stream chunks: "Costs $", 0.005, " each"  ->  text is "Costs $ each"

normalizeDelta in packages/agents/src/models/core/chat-completions/stream.ts passes a numeric content through unchanged, and the wires then read it with typeof === "string" (text() in ai-sdk/wires/shared.ts, pushText in pi-ai/wires/chat-completions.ts). Numeric reasoning / reasoning_content and a numeric native response are dropped the same way. Coercing numbers to strings in the normalizer fixes all of them; the non-streaming path already does this (contentText in response.ts).

Confirmed with a fake-binding test on main.

From cloudflare/ai#655.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions