Skip to content

Commit 08524e0

Browse files
feat(api): make kwargs match the env vars
1 parent 6853d05 commit 08524e0

File tree

4 files changed

+217
-219
lines changed

4 files changed

+217
-219
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 170
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/digitalocean%2Fgradient-9aca3802735e1375125412aa28ac36bf2175144b8218610a73d2e7f775694dff.yml
33
openapi_spec_hash: e29d14e3e4679fcf22b3e760e49931b1
4-
config_hash: 136e1973eb6297e6308a165594bd00a3
4+
config_hash: 99e3cd5dde0beb796f4547410869f726

src/gradient/_client.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ def __init__(
105105
"""Construct a new synchronous Gradient client instance.
106106
107107
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
108-
- `api_key` from `DIGITALOCEAN_ACCESS_TOKEN`
109-
- `inference_key` from `GRADIENT_MODEL_ACCESS_KEY`
110-
- `agent_key` from `GRADIENT_AGENT_ACCESS_KEY`
108+
- `access_token` from `DIGITALOCEAN_ACCESS_TOKEN`
109+
- `model_access_key` from `GRADIENT_MODEL_ACCESS_KEY`
110+
- `agent_access_key` from `GRADIENT_AGENT_ACCESS_KEY`
111111
"""
112112
if api_key is None:
113113
api_key = os.environ.get("DIGITALOCEAN_ACCESS_TOKEN")
@@ -229,10 +229,10 @@ def qs(self) -> Querystring:
229229
@property
230230
@override
231231
def auth_headers(self) -> dict[str, str]:
232-
api_key = self.api_key
233-
if api_key is None:
232+
access_token = self.access_token
233+
if access_token is None:
234234
return {}
235-
return {"Authorization": f"Bearer {api_key}"}
235+
return {"Authorization": f"Bearer {access_token}"}
236236

237237
@property
238238
@override
@@ -245,15 +245,15 @@ def default_headers(self) -> dict[str, str | Omit]:
245245

246246
@override
247247
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
248-
if (self.api_key or self.agent_key or self.inference_key) and headers.get(
249-
"Authorization"
250-
):
248+
if (
249+
self.access_token or self.agent_access_key or self.model_access_key
250+
) and headers.get("Authorization"):
251251
return
252252
if isinstance(custom_headers.get("Authorization"), Omit):
253253
return
254254

255255
raise TypeError(
256-
'"Could not resolve authentication method. Expected api_key, agent_key, or inference_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
256+
'"Could not resolve authentication method. Expected access_token, agent_access_key, or model_access_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
257257
)
258258

259259
def copy(
@@ -397,9 +397,9 @@ def __init__(
397397
"""Construct a new async AsyncGradient client instance.
398398
399399
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
400-
- `api_key` from `DIGITALOCEAN_ACCESS_TOKEN`
401-
- `inference_key` from `GRADIENT_MODEL_ACCESS_KEY`
402-
- `agent_key` from `GRADIENT_AGENT_ACCESS_KEY`
400+
- `access_token` from `DIGITALOCEAN_ACCESS_TOKEN`
401+
- `model_access_key` from `GRADIENT_MODEL_ACCESS_KEY`
402+
- `agent_access_key` from `GRADIENT_AGENT_ACCESS_KEY`
403403
"""
404404
if api_key is None:
405405
api_key = os.environ.get("DIGITALOCEAN_ACCESS_TOKEN")
@@ -521,10 +521,10 @@ def qs(self) -> Querystring:
521521
@property
522522
@override
523523
def auth_headers(self) -> dict[str, str]:
524-
api_key = self.api_key
525-
if api_key is None:
524+
access_token = self.access_token
525+
if access_token is None:
526526
return {}
527-
return {"Authorization": f"Bearer {api_key}"}
527+
return {"Authorization": f"Bearer {access_token}"}
528528

529529
@property
530530
@override
@@ -537,15 +537,15 @@ def default_headers(self) -> dict[str, str | Omit]:
537537

538538
@override
539539
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
540-
if (self.api_key or self.agent_key or self.inference_key) and headers.get(
541-
"Authorization"
542-
):
540+
if (
541+
self.access_token or self.agent_access_key or self.model_access_key
542+
) and headers.get("Authorization"):
543543
return
544544
if isinstance(custom_headers.get("Authorization"), Omit):
545545
return
546546

547547
raise TypeError(
548-
'"Could not resolve authentication method. Expected api_key, agent_key, or inference_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
548+
'"Could not resolve authentication method. Expected access_token, agent_access_key, or model_access_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
549549
)
550550

551551
def copy(

tests/conftest.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ def pytest_collection_modifyitems(items: list[pytest.Function]) -> None:
4545

4646
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
4747

48-
api_key = "My API Key"
49-
inference_key = "My Inference Key"
50-
agent_key = "My Agent Key"
51-
agent_endpoint = "https://inference.do-ai.run"
48+
access_token = "My Access Token"
49+
model_access_key = "My Model Access Key"
50+
agent_access_key = "My Agent Access Key"
5251

5352

5453
@pytest.fixture(scope="session")
@@ -59,10 +58,9 @@ def client(request: FixtureRequest) -> Iterator[Gradient]:
5958

6059
with Gradient(
6160
base_url=base_url,
62-
api_key=api_key,
63-
inference_key=inference_key,
64-
agent_key=agent_key,
65-
agent_endpoint=agent_endpoint,
61+
access_token=access_token,
62+
model_access_key=model_access_key,
63+
agent_access_key=agent_access_key,
6664
_strict_response_validation=strict,
6765
) as client:
6866
yield client
@@ -90,9 +88,9 @@ async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncGradient]:
9088

9189
async with AsyncGradient(
9290
base_url=base_url,
93-
api_key=api_key,
94-
inference_key=inference_key,
95-
agent_key=agent_key,
91+
access_token=access_token,
92+
model_access_key=model_access_key,
93+
agent_access_key=agent_access_key,
9694
_strict_response_validation=strict,
9795
http_client=http_client,
9896
) as client:

0 commit comments

Comments
 (0)