|
18 | 18 |
|
19 | 19 |
|
20 | 20 | class AsyncClient: |
| 21 | + @classmethod |
| 22 | + def from_env( |
| 23 | + cls, |
| 24 | + verify_ssl: bool = True, |
| 25 | + timeout: float = 120, |
| 26 | + max_retries: int = 3, |
| 27 | + retry_delay: float = 1.0, |
| 28 | + ): |
| 29 | + """Initialize AsyncClient using API key from environment variable. |
| 30 | +
|
| 31 | + Args: |
| 32 | + verify_ssl: Whether to verify SSL certificates |
| 33 | + timeout: Request timeout in seconds |
| 34 | + max_retries: Maximum number of retry attempts |
| 35 | + retry_delay: Delay between retries in seconds |
| 36 | + """ |
| 37 | + from os import getenv |
| 38 | + |
| 39 | + api_key = getenv("SGAI_API_KEY") |
| 40 | + if not api_key: |
| 41 | + raise ValueError("SGAI_API_KEY environment variable not set") |
| 42 | + return cls( |
| 43 | + api_key=api_key, |
| 44 | + verify_ssl=verify_ssl, |
| 45 | + timeout=timeout, |
| 46 | + max_retries=max_retries, |
| 47 | + retry_delay=retry_delay, |
| 48 | + ) |
| 49 | + |
21 | 50 | def __init__( |
22 | 51 | self, |
23 | 52 | api_key: str, |
@@ -54,34 +83,6 @@ def __init__( |
54 | 83 |
|
55 | 84 | logger.info("✅ AsyncClient initialized successfully") |
56 | 85 |
|
57 | | - @classmethod |
58 | | - def from_env( |
59 | | - cls, |
60 | | - verify_ssl: bool = True, |
61 | | - timeout: float = 120, |
62 | | - max_retries: int = 3, |
63 | | - retry_delay: float = 1.0, |
64 | | - ): |
65 | | - """Initialize AsyncClient using API key from environment variable. |
66 | | -
|
67 | | - Args: |
68 | | - verify_ssl: Whether to verify SSL certificates |
69 | | - timeout: Request timeout in seconds |
70 | | - max_retries: Maximum number of retry attempts |
71 | | - retry_delay: Delay between retries in seconds |
72 | | - """ |
73 | | - from os import getenv |
74 | | - api_key = getenv("SGAI_API_KEY") |
75 | | - if not api_key: |
76 | | - raise ValueError("SGAI_API_KEY environment variable not set") |
77 | | - return cls( |
78 | | - api_key=api_key, |
79 | | - verify_ssl=verify_ssl, |
80 | | - timeout=timeout, |
81 | | - max_retries=max_retries, |
82 | | - retry_delay=retry_delay, |
83 | | - ) |
84 | | - |
85 | 86 | async def _make_request(self, method: str, url: str, **kwargs) -> Any: |
86 | 87 | """Make HTTP request with retry logic.""" |
87 | 88 | for attempt in range(self.max_retries): |
|
0 commit comments