MCPcopy
hub / github.com/openai/openai-python / APIError

Class APIError

src/openai/_exceptions.py:48–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46
47
48class APIError(OpenAIError):
49 message: str
50 request: httpx.Request
51
52 body: object | None
53 """The API response body.
54
55 If the API responded with a valid JSON structure then this property will be the
56 decoded result.
57
58 If it isn't a valid JSON structure then this will be the raw response.
59
60 If there was no response associated with this error then it will be `None`.
61 """
62
63 code: Optional[str] = None
64 param: Optional[str] = None
65 type: Optional[str]
66
67 def __init__(self, message: str, request: httpx.Request, *, body: object | None) -> None:
68 super().__init__(message)
69 self.request = request
70 self.message = message
71 self.body = body
72
73 if is_dict(body):
74 self.code = cast(Any, construct_type(type_=Optional[str], value=body.get("code")))
75 self.param = cast(Any, construct_type(type_=Optional[str], value=body.get("param")))
76 self.type = cast(Any, construct_type(type_=str, value=body.get("type")))
77 else:
78 self.code = None
79 self.param = None
80 self.type = None
81
82
83class APIResponseValidationError(APIError):

Callers 2

__stream__Method · 0.85
__stream__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected