Skip to content

Commit a87b938

Browse files
feat(api): add safety case retrieval (#3911)
## Summary Adds support for retrieving safety case details by ID. ## Changes - Add client.safety.cases.retrieve for retrieving a safety case by ID - Expose the case identifier, creation time, entity identifier, nullable reason, and warning or deactivation notice
1 parent 6332577 commit a87b938

10 files changed

Lines changed: 605 additions & 7 deletions

File tree

‎.castiron.stats.yml‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
schema_version: 1
2-
generation_id: 0d99919e-4341-4042-88cf-64ec38034f9d
3-
openapi_spec_hash: 72dd9904e4616e46924320e49100670e
4-
openapi_transformed_spec_hash: e7d24da6852468e1b83db4468b3151de
5-
config_hash: c426d2799884f277047e545f57fad0c8
6-
codegen_sha: 273299f9b1b1d4aec76dd3f3c8053f24c99e5a6a
7-
codegen_hash: 22535fd7ebf99f054ee5627760908ae8c99c24130de1e9b3a150ba51a75a29c6
8-
public_codegen_sha: 8441291d5011f90d19b1ec9d3ed5ff9cbf7add16
2+
generation_id: 4381598a-5a3e-4b2c-b37b-65ab559dc25e
3+
openapi_spec_hash: f7fd2b85cc9e2a36081f6cb53f30c8a2
4+
openapi_transformed_spec_hash: 14712113bc9b12516d9a0a43d4e355f2
5+
config_hash: 60435bd668a5724c530fe7e9d6869e9a
6+
codegen_sha: 702ca0d6e39bf6d90ac1c8d331f8457644d5177e
7+
codegen_hash: 210d8e7aa966e14b48b838013ad2991c06262acab2a7f60c98f462218217fdb0
8+
public_codegen_sha: 680f9c0f4cc7960f95cf1293e761218ce883597e

‎api.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,18 @@ Methods:
463463

464464
- <code title="get /safety/alerts/{id}">client.safety.alerts.<a href="./src/openai/resources/safety/alerts.py">retrieve</a>(id) -> <a href="./src/openai/types/safety/safety_alert.py">SafetyAlert</a></code>
465465

466+
## Cases
467+
468+
Types:
469+
470+
```python
471+
from openai.types.safety import SafetyCase
472+
```
473+
474+
Methods:
475+
476+
- <code title="get /safety/cases/{id}">client.safety.cases.<a href="./src/openai/resources/safety/cases.py">retrieve</a>(id) -> <a href="./src/openai/types/safety/safety_case.py">SafetyCase</a></code>
477+
466478
# [Webhooks](src/openai/resources/webhooks/api.md)
467479

468480
Methods:

‎api_reference/openapi.transformed.yml‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22620,6 +22620,44 @@ paths:
2262022620
"created_at": 1741900000,
2262122621
"metadata": {"topic": "project-x"}
2262222622
}
22623+
/safety/cases/{id}:
22624+
get:
22625+
summary: Get safety case
22626+
description: Get a safety case by ID.
22627+
operationId: Getsafetycase
22628+
parameters:
22629+
- name: id
22630+
in: path
22631+
description: Safety case ID
22632+
required: true
22633+
schema:
22634+
description: Safety case ID
22635+
type: string
22636+
maxLength: 128
22637+
responses:
22638+
'200':
22639+
description: Success
22640+
content:
22641+
application/json:
22642+
schema:
22643+
$ref: '#/components/schemas/SafetyCaseResource'
22644+
x-oaiMeta:
22645+
group: safety-cases
22646+
path: retrieve
22647+
examples:
22648+
request:
22649+
curl: |
22650+
curl https://api.openai.com/v1/safety/cases/C-abc123 \
22651+
-H "Authorization: Bearer $OPENAI_API_KEY"
22652+
response: |
22653+
{
22654+
"id": "C-abc123",
22655+
"object": "safety.case",
22656+
"created_at": 1787659200,
22657+
"entity_identifier": "safety-id-123",
22658+
"reason": "cyber_abuse",
22659+
"notice": {"type": "warning"}
22660+
}
2262322661
/safety/alerts/{id}:
2262422662
get:
2262522663
summary: Get project safety alert
@@ -71405,6 +71443,47 @@ components:
7140571443
- object
7140671444
- deleted
7140771445
- id
71446+
SafetyCaseNoticeType:
71447+
type: string
71448+
enum:
71449+
- warning
71450+
- deactivation
71451+
SafetyCaseNotice:
71452+
properties:
71453+
type:
71454+
$ref: '#/components/schemas/SafetyCaseNoticeType'
71455+
type: object
71456+
required:
71457+
- type
71458+
SafetyCaseResource:
71459+
properties:
71460+
id:
71461+
type: string
71462+
object:
71463+
type: string
71464+
enum:
71465+
- safety.case
71466+
default: safety.case
71467+
x-stainless-const: true
71468+
created_at:
71469+
type: integer
71470+
format: unixtime
71471+
entity_identifier:
71472+
type: string
71473+
reason:
71474+
anyOf:
71475+
- type: string
71476+
- type: 'null'
71477+
notice:
71478+
$ref: '#/components/schemas/SafetyCaseNotice'
71479+
type: object
71480+
required:
71481+
- id
71482+
- object
71483+
- created_at
71484+
- entity_identifier
71485+
- reason
71486+
- notice
7140871487
SafetyAlertErrorType:
7140971488
type: string
7141071489
enum:
@@ -97121,6 +97200,20 @@ x-oaiMeta:
9712197200
- type: object
9712297201
key: ResponseErrorEvent
9712397202
path: <auto>
97203+
- id: safety-cases
97204+
title: Safety Cases
97205+
description: |
97206+
Retrieve details about a safety warning or deactivation using the case ID
97207+
from a `safety.warning_issued` or `safety.deactivation_issued` webhook event.
97208+
Cases belong to an organization and require an API key with `api.safety.read`.
97209+
navigationGroup: endpoints
97210+
sections:
97211+
- type: endpoint
97212+
key: Getsafetycase
97213+
path: retrieve
97214+
- type: object
97215+
key: SafetyCaseResource
97216+
path: object
9712497217
- id: safety-alerts
9712597218
title: Safety Alerts
9712697219
description: |

‎src/openai/resources/safety/__init__.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
import typing as _t
44

55
if _t.TYPE_CHECKING:
6+
from .cases import (
7+
Cases as Cases,
8+
AsyncCases as AsyncCases,
9+
CasesWithRawResponse as CasesWithRawResponse,
10+
AsyncCasesWithRawResponse as AsyncCasesWithRawResponse,
11+
CasesWithStreamingResponse as CasesWithStreamingResponse,
12+
AsyncCasesWithStreamingResponse as AsyncCasesWithStreamingResponse,
13+
)
614
from .alerts import (
715
Alerts as Alerts,
816
AsyncAlerts as AsyncAlerts,
@@ -28,6 +36,12 @@
2836
"AsyncAlertsWithRawResponse": (".alerts", "AsyncAlertsWithRawResponse"),
2937
"AlertsWithStreamingResponse": (".alerts", "AlertsWithStreamingResponse"),
3038
"AsyncAlertsWithStreamingResponse": (".alerts", "AsyncAlertsWithStreamingResponse"),
39+
"Cases": (".cases", "Cases"),
40+
"AsyncCases": (".cases", "AsyncCases"),
41+
"CasesWithRawResponse": (".cases", "CasesWithRawResponse"),
42+
"AsyncCasesWithRawResponse": (".cases", "AsyncCasesWithRawResponse"),
43+
"CasesWithStreamingResponse": (".cases", "CasesWithStreamingResponse"),
44+
"AsyncCasesWithStreamingResponse": (".cases", "AsyncCasesWithStreamingResponse"),
3145
"Safety": (".safety", "Safety"),
3246
"AsyncSafety": (".safety", "AsyncSafety"),
3347
"SafetyWithRawResponse": (".safety", "SafetyWithRawResponse"),
@@ -37,6 +51,7 @@
3751
}
3852
_SUBMODULES = {
3953
"alerts",
54+
"cases",
4055
"safety",
4156
}
4257

@@ -64,6 +79,12 @@ def __dir__() -> list[str]:
6479
"AsyncAlertsWithRawResponse",
6580
"AlertsWithStreamingResponse",
6681
"AsyncAlertsWithStreamingResponse",
82+
"Cases",
83+
"AsyncCases",
84+
"CasesWithRawResponse",
85+
"AsyncCasesWithRawResponse",
86+
"CasesWithStreamingResponse",
87+
"AsyncCasesWithStreamingResponse",
6788
"Safety",
6889
"AsyncSafety",
6990
"SafetyWithRawResponse",
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
import httpx2
6+
7+
from ... import _legacy_response
8+
from ..._types import Body, Query, Headers, NotGiven, not_given
9+
from ..._utils import path_template
10+
from ..._compat import cached_property
11+
from ..._resource import SyncAPIResource, AsyncAPIResource
12+
from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
13+
from ..._base_client import make_request_options
14+
from ...types.safety.safety_case import SafetyCase
15+
16+
__all__ = ["Cases", "AsyncCases"]
17+
18+
19+
class Cases(SyncAPIResource):
20+
@cached_property
21+
def with_raw_response(self) -> CasesWithRawResponse:
22+
"""
23+
This property can be used as a prefix for any HTTP method call to return
24+
the raw response object instead of the parsed content.
25+
26+
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
27+
"""
28+
return CasesWithRawResponse(self)
29+
30+
@cached_property
31+
def with_streaming_response(self) -> CasesWithStreamingResponse:
32+
"""
33+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
34+
35+
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
36+
"""
37+
return CasesWithStreamingResponse(self)
38+
39+
def retrieve(
40+
self,
41+
id: str,
42+
*,
43+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
44+
# The extra values given here take precedence over values defined on the client or passed to this method.
45+
extra_headers: Headers | None = None,
46+
extra_query: Query | None = None,
47+
extra_body: Body | None = None,
48+
timeout: float | httpx2.Timeout | None | NotGiven = not_given,
49+
) -> SafetyCase:
50+
"""
51+
Get a safety case by ID.
52+
53+
Args:
54+
id: Safety case ID
55+
56+
extra_headers: Send extra headers
57+
58+
extra_query: Add additional query parameters to the request
59+
60+
extra_body: Add additional JSON properties to the request
61+
62+
timeout: Override the client-level default timeout for this request, in seconds
63+
"""
64+
if not id:
65+
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
66+
return self._get(
67+
path_template("/safety/cases/{id}", id=id),
68+
options=make_request_options(
69+
extra_headers=extra_headers,
70+
extra_query=extra_query,
71+
extra_body=extra_body,
72+
timeout=timeout,
73+
security={"bearer_auth": True},
74+
),
75+
cast_to=SafetyCase,
76+
)
77+
78+
79+
class AsyncCases(AsyncAPIResource):
80+
@cached_property
81+
def with_raw_response(self) -> AsyncCasesWithRawResponse:
82+
"""
83+
This property can be used as a prefix for any HTTP method call to return
84+
the raw response object instead of the parsed content.
85+
86+
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
87+
"""
88+
return AsyncCasesWithRawResponse(self)
89+
90+
@cached_property
91+
def with_streaming_response(self) -> AsyncCasesWithStreamingResponse:
92+
"""
93+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
94+
95+
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
96+
"""
97+
return AsyncCasesWithStreamingResponse(self)
98+
99+
async def retrieve(
100+
self,
101+
id: str,
102+
*,
103+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
104+
# The extra values given here take precedence over values defined on the client or passed to this method.
105+
extra_headers: Headers | None = None,
106+
extra_query: Query | None = None,
107+
extra_body: Body | None = None,
108+
timeout: float | httpx2.Timeout | None | NotGiven = not_given,
109+
) -> SafetyCase:
110+
"""
111+
Get a safety case by ID.
112+
113+
Args:
114+
id: Safety case ID
115+
116+
extra_headers: Send extra headers
117+
118+
extra_query: Add additional query parameters to the request
119+
120+
extra_body: Add additional JSON properties to the request
121+
122+
timeout: Override the client-level default timeout for this request, in seconds
123+
"""
124+
if not id:
125+
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
126+
return await self._get(
127+
path_template("/safety/cases/{id}", id=id),
128+
options=make_request_options(
129+
extra_headers=extra_headers,
130+
extra_query=extra_query,
131+
extra_body=extra_body,
132+
timeout=timeout,
133+
security={"bearer_auth": True},
134+
),
135+
cast_to=SafetyCase,
136+
)
137+
138+
139+
class CasesWithRawResponse:
140+
def __init__(self, cases: Cases) -> None:
141+
self._cases = cases
142+
143+
self.retrieve = _legacy_response.to_raw_response_wrapper(
144+
cases.retrieve,
145+
)
146+
147+
148+
class AsyncCasesWithRawResponse:
149+
def __init__(self, cases: AsyncCases) -> None:
150+
self._cases = cases
151+
152+
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
153+
cases.retrieve,
154+
)
155+
156+
157+
class CasesWithStreamingResponse:
158+
def __init__(self, cases: Cases) -> None:
159+
self._cases = cases
160+
161+
self.retrieve = to_streamed_response_wrapper(
162+
cases.retrieve,
163+
)
164+
165+
166+
class AsyncCasesWithStreamingResponse:
167+
def __init__(self, cases: AsyncCases) -> None:
168+
self._cases = cases
169+
170+
self.retrieve = async_to_streamed_response_wrapper(
171+
cases.retrieve,
172+
)

0 commit comments

Comments
 (0)