2525)
2626from ._version import __version__
2727from ._streaming import Stream as Stream , AsyncStream as AsyncStream
28- from ._exceptions import APIStatusError
28+ from ._exceptions import LumaaiError , APIStatusError
2929from ._base_client import (
3030 DEFAULT_MAX_RETRIES ,
3131 SyncAPIClient ,
@@ -57,7 +57,7 @@ class Lumaai(SyncAPIClient):
5757 def __init__ (
5858 self ,
5959 * ,
60- auth_token : str ,
60+ auth_token : str | None = None ,
6161 base_url : str | httpx .URL | None = None ,
6262 timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
6363 max_retries : int = DEFAULT_MAX_RETRIES ,
@@ -77,7 +77,16 @@ def __init__(
7777 # part of our public interface in the future.
7878 _strict_response_validation : bool = False ,
7979 ) -> None :
80- """Construct a new synchronous lumaai client instance."""
80+ """Construct a new synchronous lumaai client instance.
81+
82+ This automatically infers the `auth_token` argument from the `LUMAAI_API_KEY` environment variable if it is not provided.
83+ """
84+ if auth_token is None :
85+ auth_token = os .environ .get ("LUMAAI_API_KEY" )
86+ if auth_token is None :
87+ raise LumaaiError (
88+ "The auth_token client option must be set either by passing auth_token to the client or by setting the LUMAAI_API_KEY environment variable"
89+ )
8190 self .auth_token = auth_token
8291
8392 if base_url is None :
@@ -218,7 +227,7 @@ class AsyncLumaai(AsyncAPIClient):
218227 def __init__ (
219228 self ,
220229 * ,
221- auth_token : str ,
230+ auth_token : str | None = None ,
222231 base_url : str | httpx .URL | None = None ,
223232 timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
224233 max_retries : int = DEFAULT_MAX_RETRIES ,
@@ -238,7 +247,16 @@ def __init__(
238247 # part of our public interface in the future.
239248 _strict_response_validation : bool = False ,
240249 ) -> None :
241- """Construct a new async lumaai client instance."""
250+ """Construct a new async lumaai client instance.
251+
252+ This automatically infers the `auth_token` argument from the `LUMAAI_API_KEY` environment variable if it is not provided.
253+ """
254+ if auth_token is None :
255+ auth_token = os .environ .get ("LUMAAI_API_KEY" )
256+ if auth_token is None :
257+ raise LumaaiError (
258+ "The auth_token client option must be set either by passing auth_token to the client or by setting the LUMAAI_API_KEY environment variable"
259+ )
242260 self .auth_token = auth_token
243261
244262 if base_url is None :
0 commit comments