File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Agent } from 'undici'
2+
13import { PROFIT_MARGIN } from '@codebuff/common/constants/limits'
24import { getErrorObject } from '@codebuff/common/util/error'
35import { env } from '@codebuff/internal/env'
@@ -23,6 +25,15 @@ import type {
2325
2426type StreamState = { responseText : string ; reasoningText : string }
2527
28+ // Extended timeout for deep-thinking models (e.g., gpt-5) that can take
29+ // a long time to start streaming.
30+ const OPENROUTER_HEADERS_TIMEOUT_MS = 10 * 60 * 1000
31+
32+ const openrouterAgent = new Agent ( {
33+ headersTimeout : OPENROUTER_HEADERS_TIMEOUT_MS ,
34+ bodyTimeout : 0 , // No body timeout for streaming responses
35+ } )
36+
2637/** Result from processing a line, including optional billed credits for final chunk */
2738type LineResult = {
2839 state : StreamState
@@ -44,6 +55,9 @@ function createOpenRouterRequest(params: {
4455 'Content-Type' : 'application/json' ,
4556 } ,
4657 body : JSON . stringify ( body ) ,
58+ // Use custom agent with extended headers timeout for deep-thinking models
59+ // @ts -expect-error - dispatcher is a valid undici option not in fetch types
60+ dispatcher : openrouterAgent ,
4761 } )
4862}
4963
You can’t perform that action at this time.
0 commit comments