@@ -113,6 +113,8 @@ func (h *ResponsesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
113113 switch {
114114 case r .Method == http .MethodPost && (r .URL .Path == "/v1/responses" || r .URL .Path == "/responses" ):
115115 h .handleResponses (w , r )
116+ case r .Method == http .MethodPost && isTransparentResponsesSubpath (r .URL .Path ):
117+ h .handleResponsesTransparentSubpath (w , r )
116118 case r .Method == http .MethodGet && (r .URL .Path == "/v1/models" || r .URL .Path == "/models" ):
117119 h .handleModels (w , r )
118120 case r .Method == http .MethodGet && isModelDetailPath (r .URL .Path ):
@@ -137,6 +139,49 @@ func (h *ResponsesHandler) handleResponses(w http.ResponseWriter, r *http.Reques
137139 h .handleResponsesThin (w , r , req , rawBody )
138140}
139141
142+ func (h * ResponsesHandler ) handleResponsesTransparentSubpath (w http.ResponseWriter , r * http.Request ) {
143+ account , err := h .selectThinGatewayAccount ()
144+ if err != nil {
145+ if errors .Is (err , errThinGatewayRequiresResponsesAccount ) || errors .Is (err , errThinGatewayActiveAccountUnsupported ) {
146+ writeThinGatewayUnsupported (w , err .Error ())
147+ return
148+ }
149+ http .Error (w , err .Error (), http .StatusBadGateway )
150+ return
151+ }
152+
153+ if err := ensureOfficialAccountSession (r .Context (), h .client , h .accounts , & account ); err != nil {
154+ http .Error (w , err .Error (), http .StatusBadGateway )
155+ return
156+ }
157+ credential , err := resolveCredential (account )
158+ if err != nil {
159+ http .Error (w , err .Error (), http .StatusBadGateway )
160+ return
161+ }
162+
163+ rawBody , err := io .ReadAll (r .Body )
164+ if err != nil {
165+ http .Error (w , err .Error (), http .StatusBadRequest )
166+ return
167+ }
168+ upstreamReq , err := h .buildThinResponsesProxySubpathRequest (r .Context (), account , credential , normalizedResponsesSubpath (r .URL .Path ), rawBody )
169+ if err != nil {
170+ http .Error (w , err .Error (), http .StatusBadGateway )
171+ return
172+ }
173+ resp , err := h .client .Do (upstreamReq )
174+ if err != nil {
175+ http .Error (w , err .Error (), http .StatusBadGateway )
176+ return
177+ }
178+ defer resp .Body .Close ()
179+
180+ copyResponseHeaders (w .Header (), resp .Header )
181+ w .WriteHeader (resp .StatusCode )
182+ _ , _ = io .Copy (w , resp .Body )
183+ }
184+
140185func (h * ResponsesHandler ) handleResponsesThin (w http.ResponseWriter , r * http.Request , req gatewayopenai.ResponsesRequest , rawBody []byte ) {
141186 candidates , err := h .orderedThinGatewayCandidates ()
142187 if err != nil {
@@ -380,6 +425,22 @@ func (h *ResponsesHandler) buildThinResponsesProxyRequest(ctx context.Context, a
380425 })
381426}
382427
428+ func (h * ResponsesHandler ) buildThinResponsesProxySubpathRequest (ctx context.Context , account accounts.Account , credential string , endpointPath string , rawBody []byte ) (* http.Request , error ) {
429+ if usesOfficialCodexAdapter (account ) {
430+ accountID , err := resolveLocalAccountID (account )
431+ if err != nil {
432+ return nil , err
433+ }
434+ return providercodex .NewAdapter (resolveAccountBaseURL (account )).BuildResponsesEndpointRequest (ctx , credential , accountID , endpointPath , rawBody , false )
435+ }
436+ return provideropenai .NewAdapter (resolveAccountBaseURL (account )).BuildRequest (ctx , providers.Request {
437+ Path : endpointPath ,
438+ Method : http .MethodPost ,
439+ APIKey : credential ,
440+ Body : rawBody ,
441+ })
442+ }
443+
383444func shouldRetryOfficialResponsesTransportError (account accounts.Account , err error ) bool {
384445 return usesOfficialCodexAdapter (account ) && errors .Is (err , io .EOF )
385446}
@@ -560,6 +621,17 @@ func isEventStreamResponse(headers http.Header) bool {
560621 return strings .Contains (strings .ToLower (headers .Get ("Content-Type" )), "text/event-stream" )
561622}
562623
624+ func isTransparentResponsesSubpath (path string ) bool {
625+ return path == "/responses/compact" || path == "/v1/responses/compact"
626+ }
627+
628+ func normalizedResponsesSubpath (path string ) string {
629+ if strings .HasPrefix (path , "/v1/" ) {
630+ return strings .TrimPrefix (path , "/v1" )
631+ }
632+ return path
633+ }
634+
563635func (h * ResponsesHandler ) startThinAudit (r * http.Request , req gatewayopenai.ResponsesRequest , accountID int64 , inputItems []gatewayopenai.ResponsesInputItem ) (int64 , int ) {
564636 conversationID , err := h .conversations .CreateConversation (conversations.Conversation {
565637 ClientID : r .RemoteAddr ,
0 commit comments