Asynchronously checks if an API key is required and valid. Args: None Returns: bool or tuple: Returns True if API key is valid and ready. Returns a tuple (None, "error message") otherwise. Notes: - Fetc
(self)
| 312 | return |
| 313 | |
| 314 | async def require_api_key(self): |
| 315 | """ |
| 316 | Asynchronously checks if an API key is required and valid. |
| 317 | |
| 318 | Args: |
| 319 | None |
| 320 | |
| 321 | Returns: |
| 322 | bool or tuple: Returns True if API key is valid and ready. |
| 323 | Returns a tuple (None, "error message") otherwise. |
| 324 | |
| 325 | Notes: |
| 326 | - Fetches the API key from the configuration. |
| 327 | - Calls the 'ping()' method to test API accessibility. |
| 328 | - Sets the API key readiness status accordingly. |
| 329 | """ |
| 330 | self.api_key = self.config.get("api_key", "") |
| 331 | if self.auth_secret: |
| 332 | try: |
| 333 | await self.ping() |
| 334 | self.hugesuccess("API is ready") |
| 335 | return True, "" |
| 336 | except Exception as e: |
| 337 | self.trace(traceback.format_exc()) |
| 338 | return None, f"Error with API ({str(e).strip()})" |
| 339 | else: |
| 340 | return None, "No API key set" |
| 341 | |
| 342 | @property |
| 343 | def api_key(self): |