3636
3737import requests
3838
39+ from ..exception import FoundryLocalException
3940from .responses_types import (
4041 DeleteResponseResult ,
4142 InputItemsListResponse ,
@@ -105,20 +106,11 @@ def _serialize(self) -> Dict[str, Any]:
105106 return {k : v for k , v in raw .items () if v is not None }
106107
107108
108- class ResponsesAPIError (Exception ):
109- """Raised for HTTP/transport errors against the Responses API."""
110-
111- def __init__ (self , message : str , status_code : Optional [int ] = None , body : Optional [str ] = None ):
112- super ().__init__ (message )
113- self .status_code = status_code
114- self .body = body
115-
116-
117109class ResponsesClient :
118110 """Client for the OpenAI Responses API served by Foundry Local.
119111
120112 Construct via ``manager.create_responses_client(model_id)`` or
121- ``model.create_responses_client (base_url)``.
113+ ``model.get_responses_client (base_url)``.
122114 """
123115
124116 def __init__ (self , base_url : str , model_id : Optional [str ] = None ):
@@ -294,7 +286,7 @@ def _request_json(self, method: str, path: str, body: Optional[Dict[str, Any]] =
294286 timeout = timeout ,
295287 )
296288 except requests .RequestException as e :
297- raise ResponsesAPIError (f"Network error calling { method } { path } : { e } " ) from e
289+ raise FoundryLocalException (f"Network error calling { method } { path } : { e } " ) from e
298290
299291 return self ._handle_json_response (resp , method , path )
300292
@@ -305,15 +297,13 @@ def _post_json(self, path: str, body: Dict[str, Any]) -> Dict[str, Any]:
305297 def _handle_json_response (resp : requests .Response , method : str , path : str ) -> Dict [str , Any ]:
306298 text = resp .text
307299 if not resp .ok :
308- raise ResponsesAPIError (
309- f"Responses API error ({ resp .status_code } ) for { method } { path } : { text [:500 ]} " ,
310- status_code = resp .status_code ,
311- body = text ,
300+ raise FoundryLocalException (
301+ f"Responses API error ({ resp .status_code } ) for { method } { path } : { text [:500 ]} "
312302 )
313303 try :
314304 return json .loads (text ) if text else {}
315305 except json .JSONDecodeError as e :
316- raise ResponsesAPIError (
306+ raise FoundryLocalException (
317307 f"Failed to parse response JSON from { method } { path } : { text [:200 ]} "
318308 ) from e
319309
@@ -332,15 +322,13 @@ def _post_stream(
332322 timeout = (connect_timeout , None ),
333323 )
334324 except requests .RequestException as e :
335- raise ResponsesAPIError (f"Network error calling POST { path } : { e } " ) from e
325+ raise FoundryLocalException (f"Network error calling POST { path } : { e } " ) from e
336326
337327 if not resp .ok :
338328 body_text = resp .text
339329 resp .close ()
340- raise ResponsesAPIError (
341- f"Responses API error ({ resp .status_code } ) for POST { path } : { body_text [:500 ]} " ,
342- status_code = resp .status_code ,
343- body = body_text ,
330+ raise FoundryLocalException (
331+ f"Responses API error ({ resp .status_code } ) for POST { path } : { body_text [:500 ]} "
344332 )
345333
346334 return _iter_sse_events (resp )
@@ -409,7 +397,7 @@ def _parse_sse_block(block: str) -> Any:
409397 try :
410398 parsed = json .loads (data )
411399 except json .JSONDecodeError as e :
412- raise ResponsesAPIError (f"Failed to parse streaming event JSON: { e } " ) from e
400+ raise FoundryLocalException (f"Failed to parse streaming event JSON: { e } " ) from e
413401 if not isinstance (parsed , dict ):
414402 return None
415403 return parse_streaming_event (parsed )
@@ -418,5 +406,4 @@ def _parse_sse_block(block: str) -> Any:
418406__all__ = [
419407 "ResponsesClient" ,
420408 "ResponsesClientSettings" ,
421- "ResponsesAPIError" ,
422409]
0 commit comments