{"record":{"id":"e398bde0068df818","repo":"alibaba/page-agent","slug":"config-error","errorCode":"CONFIG_ERROR","errorMessage":"transformRequestBody failed: ${(error as Error).message}","messagePattern":"transformRequestBody failed: (.+?)","errorType":"exception","errorClass":"InvokeError","httpStatus":null,"severity":"error","filePath":"packages/llms/src/OpenAIClient.ts","lineNumber":65,"sourceCode":"\t\tconst requestBody: Record<string, unknown> = {\n\t\t\tmodel: this.config.model,\n\t\t\tmessages,\n\t\t\ttools: openaiTools,\n\t\t\tparallel_tool_calls: false,\n\t\t\ttool_choice: toolChoice,\n\t\t}\n\t\t// Only sent if the caller explicitly set it. Most new models throw if this is set.\n\t\tif (this.config.temperature !== undefined) {\n\t\t\trequestBody.temperature = this.config.temperature\n\t\t}\n\n\t\tmodelPatch(requestBody, this.config.baseURL)\n\n\t\tlet transformedBody: Record<string, unknown> | undefined\n\t\ttry {\n\t\t\ttransformedBody = this.config.transformRequestBody(requestBody)\n\t\t} catch (error) {\n\t\t\tthrow new InvokeError(\n\t\t\t\tInvokeErrorTypes.CONFIG_ERROR,\n\t\t\t\t`transformRequestBody failed: ${(error as Error).message}`,\n\t\t\t\terror\n\t\t\t)\n\t\t}\n\t\tconst finalRequestBody = transformedBody ?? requestBody\n\n\t\t// 2. Call API\n\t\tlet response: Response\n\t\ttry {\n\t\t\tresponse = await this.fetch(`${this.config.baseURL}/chat/completions`, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t...(this.config.apiKey && { Authorization: `Bearer ${this.config.apiKey}` }),\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify(finalRequestBody),\n\t\t\t\tsignal: abortSignal,","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/alibaba/page-agent/blob/d02db1ee7c41f5315beda88bab2fe935c580f662/packages/llms/src/OpenAIClient.ts#L47-L83","documentation":"Thrown when the user-supplied transformRequestBody config callback raises an exception while transforming the outgoing request body. The library treats a failing request transformer as a configuration problem, not a runtime model failure. The original error is preserved as the cause.","triggerScenarios":"Setting config.transformRequestBody to a function that throws — e.g. it assumes a field exists on the body (requestBody.messages[0].content.replace(...)), mutates a frozen object, or contains a typo'd property access. It runs on every invoke() before the HTTP call, after modelPatch().","commonSituations":"A transformer written for one provider's schema (e.g. OpenAI 'messages') is used against a body shape another provider produces; transformer accesses undefined nested fields; transformer uses JSON.parse on an already-object value; SDK upgrade changes requestBody shape the transformer relied on.","solutions":["Inspect the preserved cause: catch (e) { e.cause } — the stack points at the exact line in your transformRequestBody that threw","Make the transformer defensive: use optional chaining and only patch fields that exist","Log or assert the requestBody shape once in dev to confirm the transformer's assumptions","If no transformation is needed, omit transformRequestBody from the config entirely"],"exampleFix":"// before\nnew OpenAIClient({ ..., transformRequestBody: (body) => {\n  body.messages[0].content = body.messages[0].content.toUpperCase() // throws if content is undefined\n}})\n\n// after\nnew OpenAIClient({ ..., transformRequestBody: (body) => {\n  if (Array.isArray(body.messages) && typeof body.messages[0]?.content === 'string') {\n    body.messages[0].content = body.messages[0].content.toUpperCase()\n  }\n  return body\n}})","handlingStrategy":"validation","validationCode":"const body = { model: 'gpt-4o', messages: [{ role: 'user', content: 'hi' }] }\n// dry-run the transformer before wiring it in\nconst out = config.transformRequestBody(body)\nif (!out || typeof out !== 'object') throw new Error('transformRequestBody must return an object')","typeGuard":"const isInvokeConfigError = (e: unknown): e is InvokeError =>\n  e instanceof InvokeError && e.code === 'CONFIG_ERROR'","tryCatchPattern":"try {\n  await client.invoke(req)\n} catch (e) {\n  if (isInvokeConfigError(e)) {\n    console.error('Transformer bug:', (e as InvokeError).cause)\n    throw e // config bugs are deterministic — do not retry\n  }\n  throw e\n}","preventionTips":["Write a unit test that runs transformRequestBody against a representative request body","Use optional chaining and early returns inside transformers","Never assume nested fields exist on the provider-shaped body"],"tags":["config","request-transform","openai-client"],"backgroundTag":"request-transform-failed","analyzedSha":"d02db1ee7c41f5315beda88bab2fe935c580f662","analyzedAt":"2026-08-28T19:39:48.634Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}