File tree Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 33
44sgai_logger .set_logging (level = "INFO" )
55
6- # Initialize the client
6+ # Initialize the client with explicit API key
77sgai_client = SyncClient (api_key = "your-api-key-here" )
88
99# SmartScraper request
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ def from_env(
4949
5050 def __init__ (
5151 self ,
52- api_key : str ,
52+ api_key : str = None ,
5353 verify_ssl : bool = True ,
5454 timeout : float = 120 ,
5555 max_retries : int = 3 ,
@@ -58,13 +58,24 @@ def __init__(
5858 """Initialize AsyncClient with configurable parameters.
5959
6060 Args:
61- api_key: API key for authentication
61+ api_key: API key for authentication. If None, will try to load from environment
6262 verify_ssl: Whether to verify SSL certificates
6363 timeout: Request timeout in seconds
6464 max_retries: Maximum number of retry attempts
6565 retry_delay: Delay between retries in seconds
6666 """
6767 logger .info ("🔑 Initializing AsyncClient" )
68+
69+ # Try to get API key from environment if not provided
70+ if api_key is None :
71+ from os import getenv
72+
73+ api_key = getenv ("SGAI_API_KEY" )
74+ if not api_key :
75+ raise ValueError (
76+ "SGAI_API_KEY not provided and not found in environment"
77+ )
78+
6879 validate_api_key (api_key )
6980 logger .debug (
7081 f"🛠️ Configuration: verify_ssl={ verify_ssl } , timeout={ timeout } , max_retries={ max_retries } "
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ def from_env(
3535 retry_delay: Delay between retries in seconds
3636 """
3737 from os import getenv
38+
3839 api_key = getenv ("SGAI_API_KEY" )
3940 if not api_key :
4041 raise ValueError ("SGAI_API_KEY environment variable not set" )
@@ -48,7 +49,7 @@ def from_env(
4849
4950 def __init__ (
5051 self ,
51- api_key : str ,
52+ api_key : str = None ,
5253 verify_ssl : bool = True ,
5354 timeout : float = 120 ,
5455 max_retries : int = 3 ,
@@ -57,13 +58,24 @@ def __init__(
5758 """Initialize SyncClient with configurable parameters.
5859
5960 Args:
60- api_key: API key for authentication
61+ api_key: API key for authentication. If None, will try to load from environment
6162 verify_ssl: Whether to verify SSL certificates
6263 timeout: Request timeout in seconds
6364 max_retries: Maximum number of retry attempts
6465 retry_delay: Delay between retries in seconds
6566 """
6667 logger .info ("🔑 Initializing SyncClient" )
68+
69+ # Try to get API key from environment if not provided
70+ if api_key is None :
71+ from os import getenv
72+
73+ api_key = getenv ("SGAI_API_KEY" )
74+ if not api_key :
75+ raise ValueError (
76+ "SGAI_API_KEY not provided and not found in environment"
77+ )
78+
6779 validate_api_key (api_key )
6880 logger .debug (
6981 f"🛠️ Configuration: verify_ssl={ verify_ssl } , timeout={ timeout } , max_retries={ max_retries } "
You can’t perform that action at this time.
0 commit comments