Skip to content

Commit 6bfef9b

Browse files
feat(api): update via SDK Studio
1 parent 6e54eec commit 6bfef9b

File tree

5 files changed

+214
-64
lines changed

5 files changed

+214
-64
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: 32
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/patronus-ai%2Fpatronus-api-55e335c613870dd79fd7b7befbb5e6647b74d5fe1fc709f9b641ea6f49df7cca.yml
33
openapi_spec_hash: 83c391682f5b5d436f81f71546973693
4-
config_hash: f4cbb4c1370980725cf379baf8c3e165
4+
config_hash: 99aa414b208e38a9932004491d073c72

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ The full API of this library can be found in [api.md](api.md).
2626
```python
2727
from patronus_api import PatronusAPI
2828

29-
client = PatronusAPI()
29+
client = PatronusAPI(
30+
access_token="My Access Token",
31+
)
3032

3133
response = client.evaluations.evaluate(
3234
evaluators=[
@@ -43,11 +45,6 @@ response = client.evaluations.evaluate(
4345
print(response.results)
4446
```
4547

46-
While you can provide an `api_key` keyword argument,
47-
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
48-
to add `PATRONUS_API_KEY="My API Key"` to your `.env` file
49-
so that your API Key is not stored in source control.
50-
5148
## Async usage
5249

5350
Simply import `AsyncPatronusAPI` instead of `PatronusAPI` and use `await` with each API call:
@@ -56,7 +53,9 @@ Simply import `AsyncPatronusAPI` instead of `PatronusAPI` and use `await` with e
5653
import asyncio
5754
from patronus_api import AsyncPatronusAPI
5855

59-
client = AsyncPatronusAPI()
56+
client = AsyncPatronusAPI(
57+
access_token="My Access Token",
58+
)
6059

6160

6261
async def main() -> None:

src/patronus_api/_client.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ def qs(self) -> Querystring:
143143
@property
144144
@override
145145
def auth_headers(self) -> dict[str, str]:
146-
api_key = self.api_key
147-
if api_key is None:
146+
access_token = self.access_token
147+
if access_token is None:
148148
return {}
149-
return {"X-API-KEY": api_key}
149+
return {"Authorization": f"Bearer {access_token}"}
150150

151151
@property
152152
@override
@@ -159,13 +159,13 @@ def default_headers(self) -> dict[str, str | Omit]:
159159

160160
@override
161161
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
162-
if self.api_key and headers.get("X-API-KEY"):
162+
if self.access_token and headers.get("Authorization"):
163163
return
164-
if isinstance(custom_headers.get("X-API-KEY"), Omit):
164+
if isinstance(custom_headers.get("Authorization"), Omit):
165165
return
166166

167167
raise TypeError(
168-
'"Could not resolve authentication method. Expected the api_key to be set. Or for the `X-API-KEY` headers to be explicitly omitted"'
168+
'"Could not resolve authentication method. Expected the access_token to be set. Or for the `Authorization` headers to be explicitly omitted"'
169169
)
170170

171171
def copy(
@@ -344,10 +344,10 @@ def qs(self) -> Querystring:
344344
@property
345345
@override
346346
def auth_headers(self) -> dict[str, str]:
347-
api_key = self.api_key
348-
if api_key is None:
347+
access_token = self.access_token
348+
if access_token is None:
349349
return {}
350-
return {"X-API-KEY": api_key}
350+
return {"Authorization": f"Bearer {access_token}"}
351351

352352
@property
353353
@override
@@ -360,13 +360,13 @@ def default_headers(self) -> dict[str, str | Omit]:
360360

361361
@override
362362
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
363-
if self.api_key and headers.get("X-API-KEY"):
363+
if self.access_token and headers.get("Authorization"):
364364
return
365-
if isinstance(custom_headers.get("X-API-KEY"), Omit):
365+
if isinstance(custom_headers.get("Authorization"), Omit):
366366
return
367367

368368
raise TypeError(
369-
'"Could not resolve authentication method. Expected the api_key to be set. Or for the `X-API-KEY` headers to be explicitly omitted"'
369+
'"Could not resolve authentication method. Expected the access_token to be set. Or for the `Authorization` headers to be explicitly omitted"'
370370
)
371371

372372
def copy(

tests/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ def pytest_collection_modifyitems(items: list[pytest.Function]) -> None:
2828

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

31+
access_token = "My Access Token"
32+
3133

3234
@pytest.fixture(scope="session")
3335
def client(request: FixtureRequest) -> Iterator[PatronusAPI]:
3436
strict = getattr(request, "param", True)
3537
if not isinstance(strict, bool):
3638
raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}")
3739

38-
with PatronusAPI(base_url=base_url, _strict_response_validation=strict) as client:
40+
with PatronusAPI(base_url=base_url, access_token=access_token, _strict_response_validation=strict) as client:
3941
yield client
4042

4143

@@ -45,5 +47,7 @@ async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncPatronusAP
4547
if not isinstance(strict, bool):
4648
raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}")
4749

48-
async with AsyncPatronusAPI(base_url=base_url, _strict_response_validation=strict) as client:
50+
async with AsyncPatronusAPI(
51+
base_url=base_url, access_token=access_token, _strict_response_validation=strict
52+
) as client:
4953
yield client

0 commit comments

Comments
 (0)