{"record":{"id":"03b108d38d3f6c1d","repo":"earendil-works/pi","slug":"output-errormessage-provider-returned-an-error","errorCode":null,"errorMessage":"output.errorMessage || \"Provider returned an error stop reason\"","messagePattern":"output\\.errorMessage \\|\\| \"Provider returned an error stop reason\"","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ai/src/api/openai-completions.ts","lineNumber":649,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const block of blocks) {\n\t\t\t\tfinishBlock(block);\n\t\t\t}\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"aborted\") {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\t\t\tif (!hasFinishReason && !compat.supportsFinishReason) {\n\t\t\t\toutput.stopReason = output.content.some((block) => block.type === \"toolCall\") ? \"toolUse\" : \"stop\";\n\t\t\t}\n\t\t\tif (output.stopReason === \"error\") {\n\t\t\t\tthrow new Error(output.errorMessage || \"Provider returned an error stop reason\");\n\t\t\t}\n\t\t\tif ((compat.supportsFinishReason && !hasFinishReason) || output.stopReason === \"pending\") {\n\t\t\t\tthrow new Error(\"Stream ended without finish_reason\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\tfor (const block of output.content) {\n\t\t\t\tdelete (block as { index?: number }).index;\n\t\t\t\t// Streaming scratch buffers are only used during parsing; never persist them.\n\t\t\t\tdelete (block as { partialArgs?: string }).partialArgs;\n\t\t\t\tdelete (block as { customInput?: unknown }).customInput;\n\t\t\t\tdelete (block as { streamIndex?: number }).streamIndex;\n\t\t\t}\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = formatProviderError(normalizeProviderError(error));\n\t\t\t// Some providers via OpenRouter give additional information in this field.","sourceCodeStart":631,"sourceCodeEnd":667,"githubUrl":"https://github.com/earendil-works/pi/blob/4af9d21d3b4d664e4a29fcabfec85171077248e3/packages/ai/src/api/openai-completions.ts#L631-L667","documentation":"Error \"output.errorMessage || \"Provider returned an error stop reason\"\" thrown in earendil-works/pi.","triggerScenarios":"Thrown at packages/ai/src/api/openai-completions.ts:649 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect output.errorMessage for the provider error detail."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4af9d21d3b4d664e4a29fcabfec85171077248e3","analyzedAt":"2026-08-24T13:07:14.692Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}