| 
6 | 6 | from typing import Any, Literal, Optional, Union  | 
7 | 7 | 
 
  | 
8 | 8 | import httpx  | 
9 |  | -from pydantic import BaseModel  | 
 | 9 | +from pydantic import BaseModel, SecretStr  | 
10 | 10 | 
 
  | 
11 | 11 | from ._errors import (  | 
12 | 12 |     LinkupAuthenticationError,  | 
@@ -42,16 +42,18 @@ class LinkupClient:  | 
42 | 42 | 
 
  | 
43 | 43 |     def __init__(  | 
44 | 44 |         self,  | 
45 |  | -        api_key: Optional[str] = None,  | 
 | 45 | +        api_key: Union[str, SecretStr, None] = None,  | 
46 | 46 |         base_url: str = "https://api.linkup.so/v1",  | 
47 | 47 |     ) -> None:  | 
48 | 48 |         if api_key is None:  | 
49 | 49 |             api_key = os.getenv("LINKUP_API_KEY")  | 
50 | 50 |         if not api_key:  | 
51 | 51 |             raise ValueError("The Linkup API key was not provided")  | 
 | 52 | +        if isinstance(api_key, str):  | 
 | 53 | +            api_key = SecretStr(api_key)  | 
52 | 54 | 
 
  | 
53 |  | -        self._api_key = api_key  | 
54 |  | -        self._base_url = base_url  | 
 | 55 | +        self._api_key: SecretStr = api_key  | 
 | 56 | +        self._base_url: str = base_url  | 
55 | 57 | 
 
  | 
56 | 58 |     def search(  | 
57 | 59 |         self,  | 
@@ -332,7 +334,7 @@ def _user_agent(self) -> str:  # pragma: no cover  | 
332 | 334 | 
 
  | 
333 | 335 |     def _headers(self) -> dict[str, str]:  # pragma: no cover  | 
334 | 336 |         return {  | 
335 |  | -            "Authorization": f"Bearer {self._api_key}",  | 
 | 337 | +            "Authorization": f"Bearer {self._api_key.get_secret_value()}",  | 
336 | 338 |             "User-Agent": self._user_agent(),  | 
337 | 339 |         }  | 
338 | 340 | 
 
  | 
 | 
0 commit comments