2626from ._version import __version__
2727from .resources import editors , projects , automations_files , environment_classes , personal_access_tokens
2828from ._streaming import Stream as Stream , AsyncStream as AsyncStream
29- from ._exceptions import APIStatusError
29+ from ._exceptions import GitpodError , APIStatusError
3030from ._base_client import (
3131 DEFAULT_MAX_RETRIES ,
3232 SyncAPIClient ,
@@ -54,10 +54,12 @@ class Gitpod(SyncAPIClient):
5454 with_streaming_response : GitpodWithStreamedResponse
5555
5656 # client options
57+ auth_token : str
5758
5859 def __init__ (
5960 self ,
6061 * ,
62+ auth_token : str | None = None ,
6163 base_url : str | httpx .URL | None = None ,
6264 timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
6365 max_retries : int = DEFAULT_MAX_RETRIES ,
@@ -77,7 +79,18 @@ def __init__(
7779 # part of our public interface in the future.
7880 _strict_response_validation : bool = False ,
7981 ) -> None :
80- """Construct a new synchronous gitpod client instance."""
82+ """Construct a new synchronous gitpod client instance.
83+
84+ This automatically infers the `auth_token` argument from the `GITPOD_API_KEY` environment variable if it is not provided.
85+ """
86+ if auth_token is None :
87+ auth_token = os .environ .get ("GITPOD_API_KEY" )
88+ if auth_token is None :
89+ raise GitpodError (
90+ "The auth_token client option must be set either by passing auth_token to the client or by setting the GITPOD_API_KEY environment variable"
91+ )
92+ self .auth_token = auth_token
93+
8194 if base_url is None :
8295 base_url = os .environ .get ("GITPOD_BASE_URL" )
8396 if base_url is None :
@@ -123,6 +136,7 @@ def default_headers(self) -> dict[str, str | Omit]:
123136 def copy (
124137 self ,
125138 * ,
139+ auth_token : str | None = None ,
126140 base_url : str | httpx .URL | None = None ,
127141 timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
128142 http_client : httpx .Client | None = None ,
@@ -156,6 +170,7 @@ def copy(
156170
157171 http_client = http_client or self ._client
158172 return self .__class__ (
173+ auth_token = auth_token or self .auth_token ,
159174 base_url = base_url or self .base_url ,
160175 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
161176 http_client = http_client ,
@@ -217,10 +232,12 @@ class AsyncGitpod(AsyncAPIClient):
217232 with_streaming_response : AsyncGitpodWithStreamedResponse
218233
219234 # client options
235+ auth_token : str
220236
221237 def __init__ (
222238 self ,
223239 * ,
240+ auth_token : str | None = None ,
224241 base_url : str | httpx .URL | None = None ,
225242 timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
226243 max_retries : int = DEFAULT_MAX_RETRIES ,
@@ -240,7 +257,18 @@ def __init__(
240257 # part of our public interface in the future.
241258 _strict_response_validation : bool = False ,
242259 ) -> None :
243- """Construct a new async gitpod client instance."""
260+ """Construct a new async gitpod client instance.
261+
262+ This automatically infers the `auth_token` argument from the `GITPOD_API_KEY` environment variable if it is not provided.
263+ """
264+ if auth_token is None :
265+ auth_token = os .environ .get ("GITPOD_API_KEY" )
266+ if auth_token is None :
267+ raise GitpodError (
268+ "The auth_token client option must be set either by passing auth_token to the client or by setting the GITPOD_API_KEY environment variable"
269+ )
270+ self .auth_token = auth_token
271+
244272 if base_url is None :
245273 base_url = os .environ .get ("GITPOD_BASE_URL" )
246274 if base_url is None :
@@ -286,6 +314,7 @@ def default_headers(self) -> dict[str, str | Omit]:
286314 def copy (
287315 self ,
288316 * ,
317+ auth_token : str | None = None ,
289318 base_url : str | httpx .URL | None = None ,
290319 timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
291320 http_client : httpx .AsyncClient | None = None ,
@@ -319,6 +348,7 @@ def copy(
319348
320349 http_client = http_client or self ._client
321350 return self .__class__ (
351+ auth_token = auth_token or self .auth_token ,
322352 base_url = base_url or self .base_url ,
323353 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
324354 http_client = http_client ,
0 commit comments