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 3
3
4
4
sgai_logger .set_logging (level = "INFO" )
5
5
6
- # Initialize the client
6
+ # Initialize the client with explicit API key
7
7
sgai_client = SyncClient (api_key = "your-api-key-here" )
8
8
9
9
# SmartScraper request
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ def from_env(
49
49
50
50
def __init__ (
51
51
self ,
52
- api_key : str ,
52
+ api_key : str = None ,
53
53
verify_ssl : bool = True ,
54
54
timeout : float = 120 ,
55
55
max_retries : int = 3 ,
@@ -58,13 +58,24 @@ def __init__(
58
58
"""Initialize AsyncClient with configurable parameters.
59
59
60
60
Args:
61
- api_key: API key for authentication
61
+ api_key: API key for authentication. If None, will try to load from environment
62
62
verify_ssl: Whether to verify SSL certificates
63
63
timeout: Request timeout in seconds
64
64
max_retries: Maximum number of retry attempts
65
65
retry_delay: Delay between retries in seconds
66
66
"""
67
67
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
+
68
79
validate_api_key (api_key )
69
80
logger .debug (
70
81
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(
35
35
retry_delay: Delay between retries in seconds
36
36
"""
37
37
from os import getenv
38
+
38
39
api_key = getenv ("SGAI_API_KEY" )
39
40
if not api_key :
40
41
raise ValueError ("SGAI_API_KEY environment variable not set" )
@@ -48,7 +49,7 @@ def from_env(
48
49
49
50
def __init__ (
50
51
self ,
51
- api_key : str ,
52
+ api_key : str = None ,
52
53
verify_ssl : bool = True ,
53
54
timeout : float = 120 ,
54
55
max_retries : int = 3 ,
@@ -57,13 +58,24 @@ def __init__(
57
58
"""Initialize SyncClient with configurable parameters.
58
59
59
60
Args:
60
- api_key: API key for authentication
61
+ api_key: API key for authentication. If None, will try to load from environment
61
62
verify_ssl: Whether to verify SSL certificates
62
63
timeout: Request timeout in seconds
63
64
max_retries: Maximum number of retry attempts
64
65
retry_delay: Delay between retries in seconds
65
66
"""
66
67
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
+
67
79
validate_api_key (api_key )
68
80
logger .debug (
69
81
f"🛠️ Configuration: verify_ssl={ verify_ssl } , timeout={ timeout } , max_retries={ max_retries } "
You can’t perform that action at this time.
0 commit comments