can1357/oh-my-pi · error · ValidationError
anthropic-messages: ${data.summary}
Error message
anthropic-messages: ${data.summary} What it means
The anthropic-messages server endpoint validates incoming request bodies with an ArkType schema (anthropicMessagesRequestSchema). If the body fails validation, parseRequest throws a ValidationError whose message embeds ArkType's data.summary — a structured description of exactly which fields were wrong. This is a 4xx-class contract failure: the client sent a request that does not match the Anthropic Messages API shape this server accepts.
Source
Thrown at packages/ai/src/providers/anthropic-messages-server.ts:329
}
/**
* Inbound `output_config.effort` wire literal → catalog `Effort` (1:1).
* Values outside this table (none exist in the schema today) are ignored
* rather than guessed at.
*/
const REASONING_EFFORT_BY_WIRE: Partial<Record<string, Effort>> = {
low: Effort.Low,
medium: Effort.Medium,
high: Effort.High,
xhigh: Effort.XHigh,
max: Effort.Max,
};
export function parseRequest(body: unknown, headers?: Headers): ParsedRequest {
const data = anthropicMessagesRequestSchema(body);
if (data instanceof type.errors) {
throw new AIError.ValidationError(`anthropic-messages: ${data.summary}`);
}
const now = Date.now();
const messages: Message[] = [];
for (const message of data.messages as AnthropicMessage[]) {
if (message.role === "user") {
for (const m of walkUserContent(message.content, now)) messages.push(m);
} else {
const assistant: AssistantMessage = {
role: "assistant",
content: walkAssistantContent(message.content),
api: "anthropic-messages",
provider: "anthropic",
model: data.model,
usage: emptyUsage(),
stopReason: "stop",
timestamp: now,
};View on GitHub (pinned to 9690622007)
Solutions
- Read data.summary in the thrown ValidationError — it enumerates each field that failed and why; fix those fields
- Validate the request body against the Anthropic Messages API schema before sending (use the official SDK's types or zod/arktype)
- Pin/upgrade the client SDK version so its request shape matches what this server expects
- Log the raw request body on failure to spot rewrites by intermediate proxies or serialization bugs (strings where numbers are expected)
Example fix
// before: unvalidated hand-rolled body
await fetch(endpoint, { method: "POST", body: JSON.stringify({ messages, model }) });
// after: required fields enforced up front
const body = { model, max_tokens: 1024, messages };
const parsed = anthropicMessagesRequestSchema(body);
if (parsed instanceof type.errors) throw new Error(parsed.summary);
await fetch(endpoint, { method: "POST", body: JSON.stringify(body) }); Defensive patterns
Strategy: validation
Validate before calling
import { type } from "arktype";
// reuse the server's schema client-side before sending
const parsed = anthropicMessagesRequestSchema(body);
if (parsed instanceof type.errors) {
throw new Error(`Invalid anthropic-messages request: ${parsed.summary}`);
} Type guard
function isArkTypeError<T>(v: unknown | T, err: unknown): err is type.errors {
return err instanceof type.errors;
} Try / catch
try {
const res = await fetch(endpoint, { method: "POST", body: JSON.stringify(body) });
} catch (err) {
if (err instanceof AIError.ValidationError && err.message.startsWith("anthropic-messages:")) {
// message body embeds arktype summary listing each offending field
logger.error("request rejected by anthropic-messages server", { detail: err.message });
}
throw err;
} Prevention
- Validate request bodies against the Anthropic Messages schema before sending
- Pin SDK versions on both sides of the server boundary and upgrade them together
- Never hand-serialize required numeric fields (max_tokens) as strings
- Log failing request bodies (redacted) to catch proxy rewrites early
When it happens
Trigger: POSTing a body to the anthropic-messages endpoint with missing/ill-typed required fields (messages, model, max_tokens), wrong enum values for roles or stop sequences, or headers that fail optional header validation.
Common situations: Pointing an Anthropic SDK at this server with a version whose request shape diverges; hand-rolled HTTP clients omitting max_tokens or sending model as null; proxies rewriting the body; sending JSON with wrong types (max_tokens as string).
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- anthropic-messages: upstream ${message.stopReason}
- Anthropic cache refresh response omitted usage
- Anthropic thinking budget requires max_tokens greater than $
- Schema contains a circular object graph — cannot enforce str
- Schema node has no type, combinator, or $ref — cannot enforc
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/79ba8160aa66129c.
Report an issue: GitHub.