Skip to content

Commit

Permalink
fix(client): correctly handle arguments with env vars (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Oct 12, 2023
1 parent a5f87ad commit 91a0e2a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/anthropic/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class Anthropic(SyncAPIClient):
def __init__(
self,
*,
api_key: str | None = os.environ.get("ANTHROPIC_API_KEY", None),
auth_token: str | None = os.environ.get("ANTHROPIC_AUTH_TOKEN", None),
api_key: str | None = None,
auth_token: str | None = None,
base_url: Optional[str] = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
Expand Down Expand Up @@ -93,8 +93,12 @@ def __init__(
- `api_key` from `ANTHROPIC_API_KEY`
- `auth_token` from `ANTHROPIC_AUTH_TOKEN`
"""
if api_key is None:
api_key = os.environ.get("ANTHROPIC_API_KEY") or None
self.api_key = api_key

if auth_token is None:
auth_token = os.environ.get("ANTHROPIC_AUTH_TOKEN") or None
self.auth_token = auth_token

if base_url is None:
Expand Down Expand Up @@ -310,8 +314,8 @@ class AsyncAnthropic(AsyncAPIClient):
def __init__(
self,
*,
api_key: str | None = os.environ.get("ANTHROPIC_API_KEY", None),
auth_token: str | None = os.environ.get("ANTHROPIC_AUTH_TOKEN", None),
api_key: str | None = None,
auth_token: str | None = None,
base_url: Optional[str] = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
Expand Down Expand Up @@ -341,8 +345,12 @@ def __init__(
- `api_key` from `ANTHROPIC_API_KEY`
- `auth_token` from `ANTHROPIC_AUTH_TOKEN`
"""
if api_key is None:
api_key = os.environ.get("ANTHROPIC_API_KEY") or None
self.api_key = api_key

if auth_token is None:
auth_token = os.environ.get("ANTHROPIC_AUTH_TOKEN") or None
self.auth_token = auth_token

if base_url is None:
Expand Down

0 comments on commit 91a0e2a

Please sign in to comment.