{"record":{"id":"79ba8160aa66129c","repo":"can1357/oh-my-pi","slug":"anthropic-messages-data-summary","errorCode":null,"errorMessage":"anthropic-messages: ${data.summary}","messagePattern":"anthropic-messages: (.+?)","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/providers/anthropic-messages-server.ts","lineNumber":329,"sourceCode":"}\n\n/**\n * Inbound `output_config.effort` wire literal → catalog `Effort` (1:1).\n * Values outside this table (none exist in the schema today) are ignored\n * rather than guessed at.\n */\nconst REASONING_EFFORT_BY_WIRE: Partial<Record<string, Effort>> = {\n\tlow: Effort.Low,\n\tmedium: Effort.Medium,\n\thigh: Effort.High,\n\txhigh: Effort.XHigh,\n\tmax: Effort.Max,\n};\n\nexport function parseRequest(body: unknown, headers?: Headers): ParsedRequest {\n\tconst data = anthropicMessagesRequestSchema(body);\n\tif (data instanceof type.errors) {\n\t\tthrow new AIError.ValidationError(`anthropic-messages: ${data.summary}`);\n\t}\n\n\tconst now = Date.now();\n\tconst messages: Message[] = [];\n\tfor (const message of data.messages as AnthropicMessage[]) {\n\t\tif (message.role === \"user\") {\n\t\t\tfor (const m of walkUserContent(message.content, now)) messages.push(m);\n\t\t} else {\n\t\t\tconst assistant: AssistantMessage = {\n\t\t\t\trole: \"assistant\",\n\t\t\t\tcontent: walkAssistantContent(message.content),\n\t\t\t\tapi: \"anthropic-messages\",\n\t\t\t\tprovider: \"anthropic\",\n\t\t\t\tmodel: data.model,\n\t\t\t\tusage: emptyUsage(),\n\t\t\t\tstopReason: \"stop\",\n\t\t\t\ttimestamp: now,\n\t\t\t};","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/ai/src/providers/anthropic-messages-server.ts#L311-L347","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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)"],"exampleFix":"// before: unvalidated hand-rolled body\nawait fetch(endpoint, { method: \"POST\", body: JSON.stringify({ messages, model }) });\n// after: required fields enforced up front\nconst body = { model, max_tokens: 1024, messages };\nconst parsed = anthropicMessagesRequestSchema(body);\nif (parsed instanceof type.errors) throw new Error(parsed.summary);\nawait fetch(endpoint, { method: \"POST\", body: JSON.stringify(body) });","handlingStrategy":"validation","validationCode":"import { type } from \"arktype\";\n// reuse the server's schema client-side before sending\nconst parsed = anthropicMessagesRequestSchema(body);\nif (parsed instanceof type.errors) {\n  throw new Error(`Invalid anthropic-messages request: ${parsed.summary}`);\n}","typeGuard":"function isArkTypeError<T>(v: unknown | T, err: unknown): err is type.errors {\n  return err instanceof type.errors;\n}","tryCatchPattern":"try {\n  const res = await fetch(endpoint, { method: \"POST\", body: JSON.stringify(body) });\n} catch (err) {\n  if (err instanceof AIError.ValidationError && err.message.startsWith(\"anthropic-messages:\")) {\n    // message body embeds arktype summary listing each offending field\n    logger.error(\"request rejected by anthropic-messages server\", { detail: err.message });\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["validation","schema","anthropic","api-server"],"backgroundTag":"schema-validation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}