From 1d297d167398a994caa5764e63454be4c0c83799 Mon Sep 17 00:00:00 2001 From: Vladimir Ivic Date: Mon, 3 Feb 2025 21:18:52 -0800 Subject: [PATCH] Sync updates from stainless branch: main --- src/llama_stack_client/_client.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/llama_stack_client/_client.py b/src/llama_stack_client/_client.py index 1f0c1d4e..584da069 100644 --- a/src/llama_stack_client/_client.py +++ b/src/llama_stack_client/_client.py @@ -103,6 +103,7 @@ def __init__( self, *, base_url: str | httpx.URL | None = None, + api_key: str | None = None, timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, max_retries: int = DEFAULT_MAX_RETRIES, default_headers: Mapping[str, str] | None = None, @@ -128,7 +129,13 @@ def __init__( if base_url is None: base_url = f"http://any-hosted-llama-stack.com" + if api_key is None: + api_key = os.environ.get("LLAMA_STACK_CLIENT_API_KEY") + self.api_key = api_key + custom_headers = default_headers or {} + if api_key is not None: + custom_headers["Authorization"] = f"Bearer {api_key}" custom_headers["X-LlamaStack-Client-Version"] = __version__ if provider_data is not None: custom_headers["X-LlamaStack-Provider-Data"] = json.dumps(provider_data) @@ -188,6 +195,7 @@ def copy( self, *, base_url: str | httpx.URL | None = None, + api_key: str | None = None, timeout: float | Timeout | None | NotGiven = NOT_GIVEN, http_client: httpx.Client | None = None, max_retries: int | NotGiven = NOT_GIVEN, @@ -221,6 +229,7 @@ def copy( http_client = http_client or self._client return self.__class__( base_url=base_url or self.base_url, + api_key=api_key or self.api_key, timeout=self.timeout if isinstance(timeout, NotGiven) else timeout, http_client=http_client, max_retries=max_retries if is_given(max_retries) else self.max_retries, @@ -300,6 +309,7 @@ def __init__( self, *, base_url: str | httpx.URL | None = None, + api_key: str | None = None, timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, max_retries: int = DEFAULT_MAX_RETRIES, default_headers: Mapping[str, str] | None = None, @@ -325,7 +335,13 @@ def __init__( if base_url is None: base_url = f"http://any-hosted-llama-stack.com" + if api_key is None: + api_key = os.environ.get("LLAMA_STACK_CLIENT_API_KEY") + self.api_key = api_key + custom_headers = default_headers or {} + if api_key is not None: + custom_headers["Authorization"] = f"Bearer {api_key}" custom_headers["X-LlamaStack-Client-Version"] = __version__ if provider_data is not None: custom_headers["X-LlamaStack-Provider-Data"] = json.dumps(provider_data) @@ -385,6 +401,7 @@ def copy( self, *, base_url: str | httpx.URL | None = None, + api_key: str | None = None, timeout: float | Timeout | None | NotGiven = NOT_GIVEN, http_client: httpx.AsyncClient | None = None, max_retries: int | NotGiven = NOT_GIVEN, @@ -418,6 +435,7 @@ def copy( http_client = http_client or self._client return self.__class__( base_url=base_url or self.base_url, + api_key=api_key or self.api_key, timeout=self.timeout if isinstance(timeout, NotGiven) else timeout, http_client=http_client, max_retries=max_retries if is_given(max_retries) else self.max_retries,