4141 async_to_streamed_response_wrapper ,
4242)
4343from ._streaming import Stream as Stream , AsyncStream as AsyncStream
44- from ._exceptions import APIStatusError , BeeperDesktopError
44+ from ._exceptions import APIStatusError
4545from ._base_client import (
4646 DEFAULT_MAX_RETRIES ,
4747 SyncAPIClient ,
7676
7777class BeeperDesktop (SyncAPIClient ):
7878 # client options
79- access_token : str
79+ access_token : str | None
8080
8181 def __init__ (
8282 self ,
@@ -107,10 +107,6 @@ def __init__(
107107 """
108108 if access_token is None :
109109 access_token = os .environ .get ("BEEPER_ACCESS_TOKEN" )
110- if access_token is None :
111- raise BeeperDesktopError (
112- "The access_token client option must be set either by passing access_token to the client or by setting the BEEPER_ACCESS_TOKEN environment variable"
113- )
114110 self .access_token = access_token
115111
116112 if base_url is None :
@@ -219,6 +215,8 @@ def _auth_headers(self, security: SecurityOptions) -> dict[str, str]:
219215 @property
220216 def _bearer_auth (self ) -> dict [str , str ]:
221217 access_token = self .access_token
218+ if access_token is None :
219+ return {}
222220 return {"Authorization" : f"Bearer { access_token } " }
223221
224222 @property
@@ -230,6 +228,15 @@ def default_headers(self) -> dict[str, str | Omit]:
230228 ** self ._custom_headers ,
231229 }
232230
231+ @override
232+ def _validate_headers (self , headers : Headers , custom_headers : Headers ) -> None :
233+ if headers .get ("Authorization" ) or isinstance (custom_headers .get ("Authorization" ), Omit ):
234+ return
235+
236+ raise TypeError (
237+ '"Could not resolve authentication method. Expected the access_token to be set. Or for the `Authorization` headers to be explicitly omitted"'
238+ )
239+
233240 def copy (
234241 self ,
235242 * ,
@@ -409,7 +416,7 @@ def _make_status_error(
409416
410417class AsyncBeeperDesktop (AsyncAPIClient ):
411418 # client options
412- access_token : str
419+ access_token : str | None
413420
414421 def __init__ (
415422 self ,
@@ -440,10 +447,6 @@ def __init__(
440447 """
441448 if access_token is None :
442449 access_token = os .environ .get ("BEEPER_ACCESS_TOKEN" )
443- if access_token is None :
444- raise BeeperDesktopError (
445- "The access_token client option must be set either by passing access_token to the client or by setting the BEEPER_ACCESS_TOKEN environment variable"
446- )
447450 self .access_token = access_token
448451
449452 if base_url is None :
@@ -552,6 +555,8 @@ def _auth_headers(self, security: SecurityOptions) -> dict[str, str]:
552555 @property
553556 def _bearer_auth (self ) -> dict [str , str ]:
554557 access_token = self .access_token
558+ if access_token is None :
559+ return {}
555560 return {"Authorization" : f"Bearer { access_token } " }
556561
557562 @property
@@ -563,6 +568,15 @@ def default_headers(self) -> dict[str, str | Omit]:
563568 ** self ._custom_headers ,
564569 }
565570
571+ @override
572+ def _validate_headers (self , headers : Headers , custom_headers : Headers ) -> None :
573+ if headers .get ("Authorization" ) or isinstance (custom_headers .get ("Authorization" ), Omit ):
574+ return
575+
576+ raise TypeError (
577+ '"Could not resolve authentication method. Expected the access_token to be set. Or for the `Authorization` headers to be explicitly omitted"'
578+ )
579+
566580 def copy (
567581 self ,
568582 * ,
0 commit comments