Skip to content

Commit 3f85757

Browse files
feat(api): api update
1 parent 5bf31f7 commit 3f85757

File tree

13 files changed

+103
-44
lines changed

13 files changed

+103
-44
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
configured_endpoints: 42
2-
openapi_spec_hash: 8d2e7726c60bca0dcfc72b1e2df34ef1
2+
openapi_spec_hash: 71ff1de391293cdfb6dcb761ed89210d
33
config_hash: 2d88a0a41f5faca603ff2789a116d988

src/codex/_client.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ._types import (
1414
NOT_GIVEN,
1515
Omit,
16+
Headers,
1617
Timeout,
1718
NotGiven,
1819
Transport,
@@ -150,6 +151,25 @@ def __init__(
150151
def qs(self) -> Querystring:
151152
return Querystring(array_format="comma")
152153

154+
@property
155+
@override
156+
def auth_headers(self) -> dict[str, str]:
157+
return {**self._authenticated_api_key, **self._public_access_key}
158+
159+
@property
160+
def _authenticated_api_key(self) -> dict[str, str]:
161+
api_key = self.api_key
162+
if api_key is None:
163+
return {}
164+
return {"X-API-Key": api_key}
165+
166+
@property
167+
def _public_access_key(self) -> dict[str, str]:
168+
access_key = self.access_key
169+
if access_key is None:
170+
return {}
171+
return {"X-Access-Key": access_key}
172+
153173
@property
154174
@override
155175
def default_headers(self) -> dict[str, str | Omit]:
@@ -159,6 +179,22 @@ def default_headers(self) -> dict[str, str | Omit]:
159179
**self._custom_headers,
160180
}
161181

182+
@override
183+
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
184+
if self.api_key and headers.get("X-API-Key"):
185+
return
186+
if isinstance(custom_headers.get("X-API-Key"), Omit):
187+
return
188+
189+
if self.access_key and headers.get("X-Access-Key"):
190+
return
191+
if isinstance(custom_headers.get("X-Access-Key"), Omit):
192+
return
193+
194+
raise TypeError(
195+
'"Could not resolve authentication method. Expected either api_key or access_key to be set. Or for one of the `X-API-Key` or `X-Access-Key` headers to be explicitly omitted"'
196+
)
197+
162198
def copy(
163199
self,
164200
*,
@@ -343,6 +379,25 @@ def __init__(
343379
def qs(self) -> Querystring:
344380
return Querystring(array_format="comma")
345381

382+
@property
383+
@override
384+
def auth_headers(self) -> dict[str, str]:
385+
return {**self._authenticated_api_key, **self._public_access_key}
386+
387+
@property
388+
def _authenticated_api_key(self) -> dict[str, str]:
389+
api_key = self.api_key
390+
if api_key is None:
391+
return {}
392+
return {"X-API-Key": api_key}
393+
394+
@property
395+
def _public_access_key(self) -> dict[str, str]:
396+
access_key = self.access_key
397+
if access_key is None:
398+
return {}
399+
return {"X-Access-Key": access_key}
400+
346401
@property
347402
@override
348403
def default_headers(self) -> dict[str, str | Omit]:
@@ -352,6 +407,22 @@ def default_headers(self) -> dict[str, str | Omit]:
352407
**self._custom_headers,
353408
}
354409

410+
@override
411+
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
412+
if self.api_key and headers.get("X-API-Key"):
413+
return
414+
if isinstance(custom_headers.get("X-API-Key"), Omit):
415+
return
416+
417+
if self.access_key and headers.get("X-Access-Key"):
418+
return
419+
if isinstance(custom_headers.get("X-Access-Key"), Omit):
420+
return
421+
422+
raise TypeError(
423+
'"Could not resolve authentication method. Expected either api_key or access_key to be set. Or for one of the `X-API-Key` or `X-Access-Key` headers to be explicitly omitted"'
424+
)
425+
355426
def copy(
356427
self,
357428
*,

src/codex/resources/projects/access_keys.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def create(
5757
name: str,
5858
description: Optional[str] | NotGiven = NOT_GIVEN,
5959
expires_at: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
60-
x_access_key: str | NotGiven = NOT_GIVEN,
6160
x_client_library_version: str | NotGiven = NOT_GIVEN,
6261
x_integration_type: str | NotGiven = NOT_GIVEN,
6362
x_source: str | NotGiven = NOT_GIVEN,
@@ -86,7 +85,6 @@ def create(
8685
extra_headers = {
8786
**strip_not_given(
8887
{
89-
"x-access-key": x_access_key,
9088
"x-client-library-version": x_client_library_version,
9189
"x-integration-type": x_integration_type,
9290
"x-source": x_source,
@@ -348,7 +346,6 @@ async def create(
348346
name: str,
349347
description: Optional[str] | NotGiven = NOT_GIVEN,
350348
expires_at: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
351-
x_access_key: str | NotGiven = NOT_GIVEN,
352349
x_client_library_version: str | NotGiven = NOT_GIVEN,
353350
x_integration_type: str | NotGiven = NOT_GIVEN,
354351
x_source: str | NotGiven = NOT_GIVEN,
@@ -377,7 +374,6 @@ async def create(
377374
extra_headers = {
378375
**strip_not_given(
379376
{
380-
"x-access-key": x_access_key,
381377
"x-client-library-version": x_client_library_version,
382378
"x-integration-type": x_integration_type,
383379
"x-source": x_source,

src/codex/resources/projects/clusters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def list_variants(
115115
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
116116
) -> ClusterListVariantsResponse:
117117
"""
118-
Get Cluster Variants
118+
Get Cluster Variants Route
119119
120120
Args:
121121
extra_headers: Send extra headers
@@ -230,7 +230,7 @@ async def list_variants(
230230
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
231231
) -> ClusterListVariantsResponse:
232232
"""
233-
Get Cluster Variants
233+
Get Cluster Variants Route
234234
235235
Args:
236236
extra_headers: Send extra headers

src/codex/resources/projects/entries.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def create(
5757
answer: Optional[str] | NotGiven = NOT_GIVEN,
5858
client_query_metadata: Iterable[object] | NotGiven = NOT_GIVEN,
5959
draft_answer: Optional[str] | NotGiven = NOT_GIVEN,
60-
x_access_key: str | NotGiven = NOT_GIVEN,
6160
x_client_library_version: str | NotGiven = NOT_GIVEN,
6261
x_integration_type: str | NotGiven = NOT_GIVEN,
6362
x_source: str | NotGiven = NOT_GIVEN,
@@ -86,7 +85,6 @@ def create(
8685
extra_headers = {
8786
**strip_not_given(
8887
{
89-
"x-access-key": x_access_key,
9088
"x-client-library-version": x_client_library_version,
9189
"x-integration-type": x_integration_type,
9290
"x-source": x_source,
@@ -325,7 +323,6 @@ def query(
325323
question: str,
326324
use_llm_matching: bool | NotGiven = NOT_GIVEN,
327325
client_metadata: Optional[object] | NotGiven = NOT_GIVEN,
328-
x_access_key: str | NotGiven = NOT_GIVEN,
329326
x_client_library_version: str | NotGiven = NOT_GIVEN,
330327
x_integration_type: str | NotGiven = NOT_GIVEN,
331328
x_source: str | NotGiven = NOT_GIVEN,
@@ -338,7 +335,7 @@ def query(
338335
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
339336
) -> EntryQueryResponse:
340337
"""
341-
Query Entries
338+
Query Entries Route
342339
343340
Args:
344341
extra_headers: Send extra headers
@@ -354,7 +351,6 @@ def query(
354351
extra_headers = {
355352
**strip_not_given(
356353
{
357-
"x-access-key": x_access_key,
358354
"x-client-library-version": x_client_library_version,
359355
"x-integration-type": x_integration_type,
360356
"x-source": x_source,
@@ -450,7 +446,6 @@ async def create(
450446
answer: Optional[str] | NotGiven = NOT_GIVEN,
451447
client_query_metadata: Iterable[object] | NotGiven = NOT_GIVEN,
452448
draft_answer: Optional[str] | NotGiven = NOT_GIVEN,
453-
x_access_key: str | NotGiven = NOT_GIVEN,
454449
x_client_library_version: str | NotGiven = NOT_GIVEN,
455450
x_integration_type: str | NotGiven = NOT_GIVEN,
456451
x_source: str | NotGiven = NOT_GIVEN,
@@ -479,7 +474,6 @@ async def create(
479474
extra_headers = {
480475
**strip_not_given(
481476
{
482-
"x-access-key": x_access_key,
483477
"x-client-library-version": x_client_library_version,
484478
"x-integration-type": x_integration_type,
485479
"x-source": x_source,
@@ -718,7 +712,6 @@ async def query(
718712
question: str,
719713
use_llm_matching: bool | NotGiven = NOT_GIVEN,
720714
client_metadata: Optional[object] | NotGiven = NOT_GIVEN,
721-
x_access_key: str | NotGiven = NOT_GIVEN,
722715
x_client_library_version: str | NotGiven = NOT_GIVEN,
723716
x_integration_type: str | NotGiven = NOT_GIVEN,
724717
x_source: str | NotGiven = NOT_GIVEN,
@@ -731,7 +724,7 @@ async def query(
731724
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
732725
) -> EntryQueryResponse:
733726
"""
734-
Query Entries
727+
Query Entries Route
735728
736729
Args:
737730
extra_headers: Send extra headers
@@ -747,7 +740,6 @@ async def query(
747740
extra_headers = {
748741
**strip_not_given(
749742
{
750-
"x-access-key": x_access_key,
751743
"x-client-library-version": x_client_library_version,
752744
"x-integration-type": x_integration_type,
753745
"x-source": x_source,

src/codex/resources/projects/projects.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ def update(
208208
def list(
209209
self,
210210
*,
211+
organization_id: str,
211212
include_entry_counts: bool | NotGiven = NOT_GIVEN,
212213
limit: int | NotGiven = NOT_GIVEN,
213214
offset: int | NotGiven = NOT_GIVEN,
214215
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
215-
organization_id: str | NotGiven = NOT_GIVEN,
216216
query: Optional[str] | NotGiven = NOT_GIVEN,
217217
sort: Literal["created_at", "updated_at"] | NotGiven = NOT_GIVEN,
218218
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -243,11 +243,11 @@ def list(
243243
timeout=timeout,
244244
query=maybe_transform(
245245
{
246+
"organization_id": organization_id,
246247
"include_entry_counts": include_entry_counts,
247248
"limit": limit,
248249
"offset": offset,
249250
"order": order,
250-
"organization_id": organization_id,
251251
"query": query,
252252
"sort": sort,
253253
},
@@ -513,11 +513,11 @@ async def update(
513513
async def list(
514514
self,
515515
*,
516+
organization_id: str,
516517
include_entry_counts: bool | NotGiven = NOT_GIVEN,
517518
limit: int | NotGiven = NOT_GIVEN,
518519
offset: int | NotGiven = NOT_GIVEN,
519520
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
520-
organization_id: str | NotGiven = NOT_GIVEN,
521521
query: Optional[str] | NotGiven = NOT_GIVEN,
522522
sort: Literal["created_at", "updated_at"] | NotGiven = NOT_GIVEN,
523523
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -548,11 +548,11 @@ async def list(
548548
timeout=timeout,
549549
query=await async_maybe_transform(
550550
{
551+
"organization_id": organization_id,
551552
"include_entry_counts": include_entry_counts,
552553
"limit": limit,
553554
"offset": offset,
554555
"order": order,
555-
"organization_id": organization_id,
556556
"query": query,
557557
"sort": sort,
558558
},

src/codex/types/project_list_params.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
from __future__ import annotations
44

55
from typing import Optional
6-
from typing_extensions import Literal, TypedDict
6+
from typing_extensions import Literal, Required, TypedDict
77

88
__all__ = ["ProjectListParams"]
99

1010

1111
class ProjectListParams(TypedDict, total=False):
12+
organization_id: Required[str]
13+
1214
include_entry_counts: bool
1315

1416
limit: int
@@ -17,8 +19,6 @@ class ProjectListParams(TypedDict, total=False):
1719

1820
order: Literal["asc", "desc"]
1921

20-
organization_id: str
21-
2222
query: Optional[str]
2323

2424
sort: Literal["created_at", "updated_at"]

src/codex/types/projects/access_key_create_params.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class AccessKeyCreateParams(TypedDict, total=False):
1818

1919
expires_at: Annotated[Union[str, datetime, None], PropertyInfo(format="iso8601")]
2020

21-
x_access_key: Annotated[str, PropertyInfo(alias="x-access-key")]
22-
2321
x_client_library_version: Annotated[str, PropertyInfo(alias="x-client-library-version")]
2422

2523
x_integration_type: Annotated[str, PropertyInfo(alias="x-integration-type")]

src/codex/types/projects/entry_create_params.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class EntryCreateParams(TypedDict, total=False):
1919

2020
draft_answer: Optional[str]
2121

22-
x_access_key: Annotated[str, PropertyInfo(alias="x-access-key")]
23-
2422
x_client_library_version: Annotated[str, PropertyInfo(alias="x-client-library-version")]
2523

2624
x_integration_type: Annotated[str, PropertyInfo(alias="x-integration-type")]

src/codex/types/projects/entry_query_params.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class EntryQueryParams(TypedDict, total=False):
1717

1818
client_metadata: Optional[object]
1919

20-
x_access_key: Annotated[str, PropertyInfo(alias="x-access-key")]
21-
2220
x_client_library_version: Annotated[str, PropertyInfo(alias="x-client-library-version")]
2321

2422
x_integration_type: Annotated[str, PropertyInfo(alias="x-integration-type")]

tests/api_resources/projects/test_access_keys.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def test_method_create_with_all_params(self, client: Codex) -> None:
3939
name="name",
4040
description="description",
4141
expires_at=parse_datetime("2019-12-27T18:11:19.117Z"),
42-
x_access_key="x-access-key",
4342
x_client_library_version="x-client-library-version",
4443
x_integration_type="x-integration-type",
4544
x_source="x-source",
@@ -400,7 +399,6 @@ async def test_method_create_with_all_params(self, async_client: AsyncCodex) ->
400399
name="name",
401400
description="description",
402401
expires_at=parse_datetime("2019-12-27T18:11:19.117Z"),
403-
x_access_key="x-access-key",
404402
x_client_library_version="x-client-library-version",
405403
x_integration_type="x-integration-type",
406404
x_source="x-source",

tests/api_resources/projects/test_entries.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def test_method_create_with_all_params(self, client: Codex) -> None:
3939
answer="answer",
4040
client_query_metadata=[{}],
4141
draft_answer="draft_answer",
42-
x_access_key="x-access-key",
4342
x_client_library_version="x-client-library-version",
4443
x_integration_type="x-integration-type",
4544
x_source="x-source",
@@ -397,7 +396,6 @@ def test_method_query_with_all_params(self, client: Codex) -> None:
397396
question="question",
398397
use_llm_matching=True,
399398
client_metadata={},
400-
x_access_key="x-access-key",
401399
x_client_library_version="x-client-library-version",
402400
x_integration_type="x-integration-type",
403401
x_source="x-source",
@@ -516,7 +514,6 @@ async def test_method_create_with_all_params(self, async_client: AsyncCodex) ->
516514
answer="answer",
517515
client_query_metadata=[{}],
518516
draft_answer="draft_answer",
519-
x_access_key="x-access-key",
520517
x_client_library_version="x-client-library-version",
521518
x_integration_type="x-integration-type",
522519
x_source="x-source",
@@ -874,7 +871,6 @@ async def test_method_query_with_all_params(self, async_client: AsyncCodex) -> N
874871
question="question",
875872
use_llm_matching=True,
876873
client_metadata={},
877-
x_access_key="x-access-key",
878874
x_client_library_version="x-client-library-version",
879875
x_integration_type="x-integration-type",
880876
x_source="x-source",

0 commit comments

Comments
 (0)