From 45b9efbce20c5f7637a7f68ef823d34f98754ecb Mon Sep 17 00:00:00 2001 From: Theo Conrads Date: Thu, 9 Jan 2025 08:45:25 +0100 Subject: [PATCH] feat: enhance RESTClient to support optional token and password for authorization - Updated the constructor to accept an optional parameter alongside the existing . - Modified the header setup to use for token-based authentication and for password-based authentication. - Added error handling to ensure either a token or password is provided. --- letta/client/client.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/letta/client/client.py b/letta/client/client.py index a3f0f256..3e46d16f 100644 --- a/letta/client/client.py +++ b/letta/client/client.py @@ -408,7 +408,8 @@ class RESTClient(AbstractClient): def __init__( self, base_url: str, - token: str, + token: Optional[str] = None, + password: Optional[str] = None, api_prefix: str = "v1", debug: bool = False, default_llm_config: Optional[LLMConfig] = None, @@ -424,11 +425,18 @@ class RESTClient(AbstractClient): default_llm_config (Optional[LLMConfig]): The default LLM configuration. default_embedding_config (Optional[EmbeddingConfig]): The default embedding configuration. headers (Optional[Dict]): The additional headers for the REST API. + token (Optional[str]): The token for the REST API when using managed letta service. + password (Optional[str]): The password for the REST API when using self hosted letta service. """ super().__init__(debug=debug) self.base_url = base_url self.api_prefix = api_prefix - self.headers = {"accept": "application/json", "X-BARE-PASSWORD": f"password {token}"} + if token: + self.headers = {"accept": "application/json", "Authorization": f"Bearer {token}"} + elif password: + self.headers = {"accept": "application/json", "X-BARE-PASSWORD": f"password {password}"} + else: + raise ValueError("Either token or password must be provided") if headers: self.headers.update(headers) self._default_llm_config = default_llm_config