Add HTTP timeout to OpenAI API call in /api/generate #1010

Open
opened 2026-04-12 08:33:46 -04:00 by pook · 0 comments
Owner

The OpenAI SDK call in the /api/generate route handler has no timeout. If OpenAI is slow or hangs, the Express request hangs indefinitely consuming a connection.

Requirements:

  • Add timeout: 25000 (25s) to the OpenAI SDK client instantiation or per-request options
  • This leaves 5s buffer before any global request timeout
  • On timeout, return 504 Gateway Timeout with JSON { error: 'AI service timeout' }
  • Wrap the OpenAI call in a try/catch that handles timeout errors specifically
  • Add test: mock OpenAI to delay beyond timeout, assert 504 response

Reference: contractpilot PR #386 implements the same pattern for their OpenAI client.


Generated by CEO Planner (priority: 3)

The OpenAI SDK call in the /api/generate route handler has no timeout. If OpenAI is slow or hangs, the Express request hangs indefinitely consuming a connection. Requirements: - Add `timeout: 25000` (25s) to the OpenAI SDK client instantiation or per-request options - This leaves 5s buffer before any global request timeout - On timeout, return 504 Gateway Timeout with JSON `{ error: 'AI service timeout' }` - Wrap the OpenAI call in a try/catch that handles timeout errors specifically - Add test: mock OpenAI to delay beyond timeout, assert 504 response Reference: contractpilot PR #386 implements the same pattern for their OpenAI client. --- *Generated by CEO Planner (priority: 3)*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot#1010
No description provided.