{"record":{"id":"b869fdca816265e0","repo":"linshenkx/prompt-optimizer","slug":"responses-api-request-failed","errorCode":null,"errorMessage":"Responses API request failed","messagePattern":"Responses API request failed","errorType":"exception","errorClass":"APIError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/llm/adapters/openai-adapter.ts","lineNumber":593,"sourceCode":"              callbacks.onToolCall(currentToolCall)\n            } catch {\n              // Ignore incomplete JSON deltas until the payload becomes valid.\n            }\n          }\n          break\n        }\n        case 'response.completed': {\n          const completedResponse = event.response\n          if (!accumulatedContent && completedResponse?.output_text) {\n            accumulatedContent = completedResponse.output_text\n          }\n          if (!accumulatedReasoning) {\n            accumulatedReasoning = this.extractResponsesReasoning(completedResponse?.output)\n          }\n          break\n        }\n        case 'response.failed': {\n          throw new APIError('Responses API request failed')\n        }\n        case 'response.error': {\n          throw new APIError(event.error?.message || 'Responses API request failed')\n        }\n        default:\n          break\n      }\n    }\n\n    callbacks.onComplete({\n      content: accumulatedContent,\n      reasoning: accumulatedReasoning || undefined,\n      toolCalls: toolCalls.size > 0 ? Array.from(toolCalls.values()) : undefined,\n      metadata: {\n        model: config.modelMeta.id\n      }\n    })\n  }","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/llm/adapters/openai-adapter.ts#L575-L611","documentation":"During Responses API streaming, the terminal 'response.failed' event fired: OpenAI accepted the request but the response generation failed server-side, so the adapter aborts with a generic APIError (response.failed carries no usable message here).","triggerScenarios":"Server-side failures during generation: internal errors, content-filter/system issues, or model crashes mid-response; happens after streaming has begun.","commonSituations":"OpenAI incidents, overloaded models, long generations timing out server-side, rarely reproducible transient failures.","solutions":["Simply retry the request — most response.failed events are transient","If recurring, check status.openai.com and try a different model ID","Inspect event.response.error in raw SSE for detail (adapter discards it)","Add a fallback path to the chat-completions API if Responses is unstable for your workload"],"exampleFix":"// before\nconst stream = await adapter.sendMessageStream(msgs)\n\n// after\nasync function robustStream(adapter, msgs, tries = 3) {\n  for (let i = 0; ; i++) {\n    try { return await adapter.sendMessageStream(msgs) }\n    catch (e) {\n      if (i < tries - 1 && e instanceof APIError && /Responses API request failed/.test(e.message)) continue\n      throw e\n    }\n  }\n}","handlingStrategy":"retry","validationCode":"null","typeGuard":"function isResponsesFailed(e: unknown): boolean {\n  return e instanceof APIError && e.message === 'Responses API request failed'\n}","tryCatchPattern":"try { return await consume(adapter.sendMessageStream(msgs)) }\ncatch (e) {\n  if (isResponsesFailed(e) && retriesLeft) { await sleep(backoffMs); return retry() }\n  throw e\n}","preventionTips":["Build retry-with-backoff around all streaming calls","Have a chat-completions fallback path","Watch provider status pages during incidents"],"tags":["openai","responses-api","streaming","server-error"],"backgroundTag":"stream-generation-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}