diff --git a/src/openai/_exceptions.py b/src/openai/_exceptions.py index 350fd2584b..074752c8a1 100644 --- a/src/openai/_exceptions.py +++ b/src/openai/_exceptions.py @@ -8,6 +8,7 @@ import httpx from ._utils import is_dict +from ._models import construct_type __all__ = [ "BadRequestError", @@ -51,9 +52,9 @@ def __init__(self, message: str, request: httpx.Request, *, body: object | None) self.body = body if is_dict(body): - self.code = cast(Any, body.get("code")) - self.param = cast(Any, body.get("param")) - self.type = cast(Any, body.get("type")) + self.code = cast(Any, construct_type(type_=Optional[str], value=body.get("code"))) + self.param = cast(Any, construct_type(type_=Optional[str], value=body.get("param"))) + self.type = cast(Any, construct_type(type_=str, value=body.get("type"))) else: self.code = None self.param = None