Skip to content

Commit cb2c6ed

Browse files
feat(api): api update
1 parent b10aff3 commit cb2c6ed

File tree

5 files changed

+126
-16
lines changed

5 files changed

+126
-16
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: 55
2-
openapi_spec_hash: 3c5027a5bd3fb174b9b7f26bd5cb0eba
2+
openapi_spec_hash: 37c29bad42e8605b1c087d22c8d48f30
33
config_hash: 48c3812186c899cdef23cc8de76bd2aa

src/codex/resources/projects/projects.py

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,9 @@ def retrieve_analytics(
564564
self,
565565
project_id: str,
566566
*,
567-
end: int | Omit = omit,
568-
start: int | Omit = omit,
567+
end: Optional[int] | Omit = omit,
568+
metadata_filters: Optional[str] | Omit = omit,
569+
start: Optional[int] | Omit = omit,
569570
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
570571
# The extra values given here take precedence over values defined on the client or passed to this method.
571572
extra_headers: Headers | None = None,
@@ -574,12 +575,46 @@ def retrieve_analytics(
574575
timeout: float | httpx.Timeout | None | NotGiven = not_given,
575576
) -> ProjectRetrieveAnalyticsResponse:
576577
"""
577-
Get Project Analytics Route
578+
Retrieve analytics data for a project including queries, bad responses, and
579+
answers published.
580+
581+
**Metadata Filtering:**
582+
- Filter by custom metadata fields using key-value pairs
583+
- Supports single values: `{"department": "Engineering"}`
584+
- Supports multiple values: `{"priority": ["high", "medium"]}`
585+
- Supports null/missing values: `{"department": []}` or `{"department": [null]}`
586+
587+
**Available Metadata Fields:**
588+
- Only metadata keys that exist on query logs are returned in `metadata_fields`
589+
- Fields with ≤12 unique values show as "select" type with checkbox options
590+
- Fields with >12 unique values show as "input" type for text search
591+
- Fields with no data are excluded from the response entirely
592+
593+
**Null Value Behavior:**
594+
- Empty arrays `[]` are automatically converted to `[null]` to filter for records where the metadata field is missing or null
595+
- Use `[null]` explicitly to filter for records where the field is missing or null
596+
- Use `["value1", null, "value2"]` to include both specific values and null values
597+
- Records match if the metadata field is null, missing from custom_metadata, or custom_metadata itself is null
598+
599+
**Date Filtering:**
600+
- Provide `start` only: filter logs created at or after this timestamp
601+
- Provide `end` only: filter logs created at or before this timestamp
602+
- Provide both: filter logs created within the time range
603+
- Provide neither: include all logs regardless of creation time
578604
579605
Args:
580-
end: End timestamp in seconds since epoch
606+
end: Filter logs created at or before this timestamp (epoch seconds). Can be used
607+
alone for upper-bound filtering.
581608
582-
start: Start timestamp in seconds since epoch
609+
metadata_filters:
610+
Metadata filters as JSON string. Examples:
611+
- Single value: '{"department": "Engineering"}'
612+
- Multiple values: '{"priority": ["high", "medium"]}'
613+
- Null/missing values: '{"department": []}' or '{"department": [null]}'
614+
- Mixed values: '{"status": ["active", null, "pending"]}'
615+
616+
start: Filter logs created at or after this timestamp (epoch seconds). Can be used
617+
alone for lower-bound filtering.
583618
584619
extra_headers: Send extra headers
585620
@@ -601,6 +636,7 @@ def retrieve_analytics(
601636
query=maybe_transform(
602637
{
603638
"end": end,
639+
"metadata_filters": metadata_filters,
604640
"start": start,
605641
},
606642
project_retrieve_analytics_params.ProjectRetrieveAnalyticsParams,
@@ -1301,8 +1337,9 @@ async def retrieve_analytics(
13011337
self,
13021338
project_id: str,
13031339
*,
1304-
end: int | Omit = omit,
1305-
start: int | Omit = omit,
1340+
end: Optional[int] | Omit = omit,
1341+
metadata_filters: Optional[str] | Omit = omit,
1342+
start: Optional[int] | Omit = omit,
13061343
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
13071344
# The extra values given here take precedence over values defined on the client or passed to this method.
13081345
extra_headers: Headers | None = None,
@@ -1311,12 +1348,46 @@ async def retrieve_analytics(
13111348
timeout: float | httpx.Timeout | None | NotGiven = not_given,
13121349
) -> ProjectRetrieveAnalyticsResponse:
13131350
"""
1314-
Get Project Analytics Route
1351+
Retrieve analytics data for a project including queries, bad responses, and
1352+
answers published.
1353+
1354+
**Metadata Filtering:**
1355+
- Filter by custom metadata fields using key-value pairs
1356+
- Supports single values: `{"department": "Engineering"}`
1357+
- Supports multiple values: `{"priority": ["high", "medium"]}`
1358+
- Supports null/missing values: `{"department": []}` or `{"department": [null]}`
1359+
1360+
**Available Metadata Fields:**
1361+
- Only metadata keys that exist on query logs are returned in `metadata_fields`
1362+
- Fields with ≤12 unique values show as "select" type with checkbox options
1363+
- Fields with >12 unique values show as "input" type for text search
1364+
- Fields with no data are excluded from the response entirely
1365+
1366+
**Null Value Behavior:**
1367+
- Empty arrays `[]` are automatically converted to `[null]` to filter for records where the metadata field is missing or null
1368+
- Use `[null]` explicitly to filter for records where the field is missing or null
1369+
- Use `["value1", null, "value2"]` to include both specific values and null values
1370+
- Records match if the metadata field is null, missing from custom_metadata, or custom_metadata itself is null
1371+
1372+
**Date Filtering:**
1373+
- Provide `start` only: filter logs created at or after this timestamp
1374+
- Provide `end` only: filter logs created at or before this timestamp
1375+
- Provide both: filter logs created within the time range
1376+
- Provide neither: include all logs regardless of creation time
13151377
13161378
Args:
1317-
end: End timestamp in seconds since epoch
1379+
end: Filter logs created at or before this timestamp (epoch seconds). Can be used
1380+
alone for upper-bound filtering.
1381+
1382+
metadata_filters:
1383+
Metadata filters as JSON string. Examples:
1384+
- Single value: '{"department": "Engineering"}'
1385+
- Multiple values: '{"priority": ["high", "medium"]}'
1386+
- Null/missing values: '{"department": []}' or '{"department": [null]}'
1387+
- Mixed values: '{"status": ["active", null, "pending"]}'
13181388
1319-
start: Start timestamp in seconds since epoch
1389+
start: Filter logs created at or after this timestamp (epoch seconds). Can be used
1390+
alone for lower-bound filtering.
13201391
13211392
extra_headers: Send extra headers
13221393
@@ -1338,6 +1409,7 @@ async def retrieve_analytics(
13381409
query=await async_maybe_transform(
13391410
{
13401411
"end": end,
1412+
"metadata_filters": metadata_filters,
13411413
"start": start,
13421414
},
13431415
project_retrieve_analytics_params.ProjectRetrieveAnalyticsParams,

src/codex/types/project_retrieve_analytics_params.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,30 @@
22

33
from __future__ import annotations
44

5+
from typing import Optional
56
from typing_extensions import TypedDict
67

78
__all__ = ["ProjectRetrieveAnalyticsParams"]
89

910

1011
class ProjectRetrieveAnalyticsParams(TypedDict, total=False):
11-
end: int
12-
"""End timestamp in seconds since epoch"""
12+
end: Optional[int]
13+
"""Filter logs created at or before this timestamp (epoch seconds).
1314
14-
start: int
15-
"""Start timestamp in seconds since epoch"""
15+
Can be used alone for upper-bound filtering.
16+
"""
17+
18+
metadata_filters: Optional[str]
19+
"""Metadata filters as JSON string.
20+
21+
Examples: - Single value: '{"department": "Engineering"}' - Multiple values:
22+
'{"priority": ["high", "medium"]}' - Null/missing values: '{"department": []}'
23+
or '{"department": [null]}' - Mixed values: '{"status": ["active", null,
24+
"pending"]}'
25+
"""
26+
27+
start: Optional[int]
28+
"""Filter logs created at or after this timestamp (epoch seconds).
29+
30+
Can be used alone for lower-bound filtering.
31+
"""

src/codex/types/project_retrieve_analytics_response.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
from typing import Dict, List
3+
from typing import Dict, List, Optional
4+
from typing_extensions import Literal
45

56
from .._models import BaseModel
67

@@ -11,6 +12,7 @@
1112
"BadResponses",
1213
"BadResponsesResponsesByType",
1314
"Queries",
15+
"MetadataField",
1416
]
1517

1618

@@ -44,9 +46,27 @@ class Queries(BaseModel):
4446
total: int
4547

4648

49+
class MetadataField(BaseModel):
50+
field_type: Literal["select", "input"]
51+
"""Field type: 'select' for checkbox selection, 'input' for text input"""
52+
53+
key: str
54+
"""Metadata field key"""
55+
56+
values: Optional[List[Optional[str]]] = None
57+
"""Possible values for this metadata field (None if more than 12 values).
58+
59+
Array elements may include null to represent logs where the metadata key is
60+
missing or null.
61+
"""
62+
63+
4764
class ProjectRetrieveAnalyticsResponse(BaseModel):
4865
answers_published: AnswersPublished
4966

5067
bad_responses: BadResponses
5168

5269
queries: Queries
70+
71+
metadata_fields: Optional[List[MetadataField]] = None
72+
"""Available metadata fields for filtering"""

tests/api_resources/test_projects.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ def test_method_retrieve_analytics_with_all_params(self, client: Codex) -> None:
743743
project = client.projects.retrieve_analytics(
744744
project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
745745
end=0,
746+
metadata_filters="metadata_filters",
746747
start=0,
747748
)
748749
assert_matches_type(ProjectRetrieveAnalyticsResponse, project, path=["response"])
@@ -1630,6 +1631,7 @@ async def test_method_retrieve_analytics_with_all_params(self, async_client: Asy
16301631
project = await async_client.projects.retrieve_analytics(
16311632
project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
16321633
end=0,
1634+
metadata_filters="metadata_filters",
16331635
start=0,
16341636
)
16351637
assert_matches_type(ProjectRetrieveAnalyticsResponse, project, path=["response"])

0 commit comments

Comments
 (0)