Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/llama_stack_client/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down