createAI (pi-ai): Anthropic catalog models may fail on /run when system is an array · Issue #2631 · cloudflare/agents · GitHub
Skip to content

createAI (pi-ai): Anthropic catalog models may fail on /run when system is an array #2631

Open

Description

@mattzcarey

cloudflare/ai#672 reports that AI Gateway's /run rejects an Anthropic Messages body whose system is an array of text blocks: 7003: Model execution failed (User Input Error): Invalid value at system: Invalid input: expected string, received array. createAI's pi-ai provider sends exactly that body for an Anthropic catalog id, so every request with a system prompt may fail.

import { createAI } from "agents/models/pi-ai";
const ai = createAI({ binding: env.AI });
ai.stream(ai("anthropic/claude-opus-4.8"), { systemPrompt: "Be terse.", messages });
// binding.run("anthropic/claude-opus-4.8", { system: [{ type: "text", text: "Be terse.", cache_control: { type: "ephemeral" } }], ... }, { openaiEndpoint: "/v1/messages" })

The body is pi-ai's own, passed through by packages/agents/src/models/pi-ai/wires/anthropic.ts. Not checked live: the old package didn't send openaiEndpoint, and createAI does, so /run may validate it differently. If it does fail, either /run should accept the array (it's valid Anthropic) or the wire should join text-only blocks into a string on /run only. The AI SDK provider isn't affected: string ids go over chat completions.

From cloudflare/ai#672.

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