33from __future__ import annotations
44
55import os
6- from typing import Any , Dict , Union , Mapping , cast
7- from typing_extensions import Self , Literal , override
6+ from typing import Any , Union , Mapping
7+ from typing_extensions import Self , override
88
99import httpx
1010
3333)
3434
3535__all__ = [
36- "ENVIRONMENTS" ,
3736 "Timeout" ,
3837 "Transport" ,
3938 "ProxiesTypes" ,
4544 "AsyncClient" ,
4645]
4746
48- ENVIRONMENTS : Dict [str , str ] = {
49- "production" : "https://api.browserbase.com" ,
50- "development" : "https://api.dev.browserbase.com" ,
51- "local" : "http://api.localhost" ,
52- }
53-
5447
5548class Browserbase (SyncAPIClient ):
5649 contexts : resources .ContextsResource
@@ -63,14 +56,11 @@ class Browserbase(SyncAPIClient):
6356 # client options
6457 api_key : str
6558
66- _environment : Literal ["production" , "development" , "local" ] | NotGiven
67-
6859 def __init__ (
6960 self ,
7061 * ,
7162 api_key : str | None = None ,
72- environment : Literal ["production" , "development" , "local" ] | NotGiven = NOT_GIVEN ,
73- base_url : str | httpx .URL | None | NotGiven = NOT_GIVEN ,
63+ base_url : str | httpx .URL | None = None ,
7464 timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
7565 max_retries : int = DEFAULT_MAX_RETRIES ,
7666 default_headers : Mapping [str , str ] | None = None ,
@@ -89,7 +79,7 @@ def __init__(
8979 # part of our public interface in the future.
9080 _strict_response_validation : bool = False ,
9181 ) -> None :
92- """Construct a new synchronous browserbase client instance.
82+ """Construct a new synchronous Browserbase client instance.
9383
9484 This automatically infers the `api_key` argument from the `BROWSERBASE_API_KEY` environment variable if it is not provided.
9585 """
@@ -101,31 +91,10 @@ def __init__(
10191 )
10292 self .api_key = api_key
10393
104- self ._environment = environment
105-
106- base_url_env = os .environ .get ("BROWSERBASE_BASE_URL" )
107- if is_given (base_url ) and base_url is not None :
108- # cast required because mypy doesn't understand the type narrowing
109- base_url = cast ("str | httpx.URL" , base_url ) # pyright: ignore[reportUnnecessaryCast]
110- elif is_given (environment ):
111- if base_url_env and base_url is not None :
112- raise ValueError (
113- "Ambiguous URL; The `BROWSERBASE_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None" ,
114- )
115-
116- try :
117- base_url = ENVIRONMENTS [environment ]
118- except KeyError as exc :
119- raise ValueError (f"Unknown environment: { environment } " ) from exc
120- elif base_url_env is not None :
121- base_url = base_url_env
122- else :
123- self ._environment = environment = "production"
124-
125- try :
126- base_url = ENVIRONMENTS [environment ]
127- except KeyError as exc :
128- raise ValueError (f"Unknown environment: { environment } " ) from exc
94+ if base_url is None :
95+ base_url = os .environ .get ("BROWSERBASE_BASE_URL" )
96+ if base_url is None :
97+ base_url = f"https://api.browserbase.com"
12998
13099 super ().__init__ (
131100 version = __version__ ,
@@ -169,7 +138,6 @@ def copy(
169138 self ,
170139 * ,
171140 api_key : str | None = None ,
172- environment : Literal ["production" , "development" , "local" ] | None = None ,
173141 base_url : str | httpx .URL | None = None ,
174142 timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
175143 http_client : httpx .Client | None = None ,
@@ -205,7 +173,6 @@ def copy(
205173 return self .__class__ (
206174 api_key = api_key or self .api_key ,
207175 base_url = base_url or self .base_url ,
208- environment = environment or self ._environment ,
209176 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
210177 http_client = http_client ,
211178 max_retries = max_retries if is_given (max_retries ) else self .max_retries ,
@@ -263,14 +230,11 @@ class AsyncBrowserbase(AsyncAPIClient):
263230 # client options
264231 api_key : str
265232
266- _environment : Literal ["production" , "development" , "local" ] | NotGiven
267-
268233 def __init__ (
269234 self ,
270235 * ,
271236 api_key : str | None = None ,
272- environment : Literal ["production" , "development" , "local" ] | NotGiven = NOT_GIVEN ,
273- base_url : str | httpx .URL | None | NotGiven = NOT_GIVEN ,
237+ base_url : str | httpx .URL | None = None ,
274238 timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
275239 max_retries : int = DEFAULT_MAX_RETRIES ,
276240 default_headers : Mapping [str , str ] | None = None ,
@@ -289,7 +253,7 @@ def __init__(
289253 # part of our public interface in the future.
290254 _strict_response_validation : bool = False ,
291255 ) -> None :
292- """Construct a new async browserbase client instance.
256+ """Construct a new async Browserbase client instance.
293257
294258 This automatically infers the `api_key` argument from the `BROWSERBASE_API_KEY` environment variable if it is not provided.
295259 """
@@ -301,31 +265,10 @@ def __init__(
301265 )
302266 self .api_key = api_key
303267
304- self ._environment = environment
305-
306- base_url_env = os .environ .get ("BROWSERBASE_BASE_URL" )
307- if is_given (base_url ) and base_url is not None :
308- # cast required because mypy doesn't understand the type narrowing
309- base_url = cast ("str | httpx.URL" , base_url ) # pyright: ignore[reportUnnecessaryCast]
310- elif is_given (environment ):
311- if base_url_env and base_url is not None :
312- raise ValueError (
313- "Ambiguous URL; The `BROWSERBASE_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None" ,
314- )
315-
316- try :
317- base_url = ENVIRONMENTS [environment ]
318- except KeyError as exc :
319- raise ValueError (f"Unknown environment: { environment } " ) from exc
320- elif base_url_env is not None :
321- base_url = base_url_env
322- else :
323- self ._environment = environment = "production"
324-
325- try :
326- base_url = ENVIRONMENTS [environment ]
327- except KeyError as exc :
328- raise ValueError (f"Unknown environment: { environment } " ) from exc
268+ if base_url is None :
269+ base_url = os .environ .get ("BROWSERBASE_BASE_URL" )
270+ if base_url is None :
271+ base_url = f"https://api.browserbase.com"
329272
330273 super ().__init__ (
331274 version = __version__ ,
@@ -369,7 +312,6 @@ def copy(
369312 self ,
370313 * ,
371314 api_key : str | None = None ,
372- environment : Literal ["production" , "development" , "local" ] | None = None ,
373315 base_url : str | httpx .URL | None = None ,
374316 timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
375317 http_client : httpx .AsyncClient | None = None ,
@@ -405,7 +347,6 @@ def copy(
405347 return self .__class__ (
406348 api_key = api_key or self .api_key ,
407349 base_url = base_url or self .base_url ,
408- environment = environment or self ._environment ,
409350 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
410351 http_client = http_client ,
411352 max_retries = max_retries if is_given (max_retries ) else self .max_retries ,
0 commit comments