main
1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import httpx
6
7from ... import _legacy_response
8from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
9from ..._utils import maybe_transform, async_maybe_transform
10from ..._compat import cached_property
11from ..._resource import SyncAPIResource, AsyncAPIResource
12from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
13from ..._base_client import make_request_options
14from ...types.realtime import client_secret_create_params
15from ...types.realtime.client_secret_create_response import ClientSecretCreateResponse
16
17__all__ = ["ClientSecrets", "AsyncClientSecrets"]
18
19
20class ClientSecrets(SyncAPIResource):
21 @cached_property
22 def with_raw_response(self) -> ClientSecretsWithRawResponse:
23 """
24 This property can be used as a prefix for any HTTP method call to return
25 the raw response object instead of the parsed content.
26
27 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
28 """
29 return ClientSecretsWithRawResponse(self)
30
31 @cached_property
32 def with_streaming_response(self) -> ClientSecretsWithStreamingResponse:
33 """
34 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
35
36 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
37 """
38 return ClientSecretsWithStreamingResponse(self)
39
40 def create(
41 self,
42 *,
43 expires_after: client_secret_create_params.ExpiresAfter | Omit = omit,
44 session: client_secret_create_params.Session | Omit = omit,
45 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
46 # The extra values given here take precedence over values defined on the client or passed to this method.
47 extra_headers: Headers | None = None,
48 extra_query: Query | None = None,
49 extra_body: Body | None = None,
50 timeout: float | httpx.Timeout | None | NotGiven = not_given,
51 ) -> ClientSecretCreateResponse:
52 """
53 Create a Realtime client secret with an associated session configuration.
54
55 Args:
56 expires_after: Configuration for the client secret expiration. Expiration refers to the time
57 after which a client secret will no longer be valid for creating sessions. The
58 session itself may continue after that time once started. A secret can be used
59 to create multiple sessions until it expires.
60
61 session: Session configuration to use for the client secret. Choose either a realtime
62 session or a transcription session.
63
64 extra_headers: Send extra headers
65
66 extra_query: Add additional query parameters to the request
67
68 extra_body: Add additional JSON properties to the request
69
70 timeout: Override the client-level default timeout for this request, in seconds
71 """
72 return self._post(
73 "/realtime/client_secrets",
74 body=maybe_transform(
75 {
76 "expires_after": expires_after,
77 "session": session,
78 },
79 client_secret_create_params.ClientSecretCreateParams,
80 ),
81 options=make_request_options(
82 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
83 ),
84 cast_to=ClientSecretCreateResponse,
85 )
86
87
88class AsyncClientSecrets(AsyncAPIResource):
89 @cached_property
90 def with_raw_response(self) -> AsyncClientSecretsWithRawResponse:
91 """
92 This property can be used as a prefix for any HTTP method call to return
93 the raw response object instead of the parsed content.
94
95 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
96 """
97 return AsyncClientSecretsWithRawResponse(self)
98
99 @cached_property
100 def with_streaming_response(self) -> AsyncClientSecretsWithStreamingResponse:
101 """
102 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
103
104 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
105 """
106 return AsyncClientSecretsWithStreamingResponse(self)
107
108 async def create(
109 self,
110 *,
111 expires_after: client_secret_create_params.ExpiresAfter | Omit = omit,
112 session: client_secret_create_params.Session | Omit = omit,
113 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
114 # The extra values given here take precedence over values defined on the client or passed to this method.
115 extra_headers: Headers | None = None,
116 extra_query: Query | None = None,
117 extra_body: Body | None = None,
118 timeout: float | httpx.Timeout | None | NotGiven = not_given,
119 ) -> ClientSecretCreateResponse:
120 """
121 Create a Realtime client secret with an associated session configuration.
122
123 Args:
124 expires_after: Configuration for the client secret expiration. Expiration refers to the time
125 after which a client secret will no longer be valid for creating sessions. The
126 session itself may continue after that time once started. A secret can be used
127 to create multiple sessions until it expires.
128
129 session: Session configuration to use for the client secret. Choose either a realtime
130 session or a transcription session.
131
132 extra_headers: Send extra headers
133
134 extra_query: Add additional query parameters to the request
135
136 extra_body: Add additional JSON properties to the request
137
138 timeout: Override the client-level default timeout for this request, in seconds
139 """
140 return await self._post(
141 "/realtime/client_secrets",
142 body=await async_maybe_transform(
143 {
144 "expires_after": expires_after,
145 "session": session,
146 },
147 client_secret_create_params.ClientSecretCreateParams,
148 ),
149 options=make_request_options(
150 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
151 ),
152 cast_to=ClientSecretCreateResponse,
153 )
154
155
156class ClientSecretsWithRawResponse:
157 def __init__(self, client_secrets: ClientSecrets) -> None:
158 self._client_secrets = client_secrets
159
160 self.create = _legacy_response.to_raw_response_wrapper(
161 client_secrets.create,
162 )
163
164
165class AsyncClientSecretsWithRawResponse:
166 def __init__(self, client_secrets: AsyncClientSecrets) -> None:
167 self._client_secrets = client_secrets
168
169 self.create = _legacy_response.async_to_raw_response_wrapper(
170 client_secrets.create,
171 )
172
173
174class ClientSecretsWithStreamingResponse:
175 def __init__(self, client_secrets: ClientSecrets) -> None:
176 self._client_secrets = client_secrets
177
178 self.create = to_streamed_response_wrapper(
179 client_secrets.create,
180 )
181
182
183class AsyncClientSecretsWithStreamingResponse:
184 def __init__(self, client_secrets: AsyncClientSecrets) -> None:
185 self._client_secrets = client_secrets
186
187 self.create = async_to_streamed_response_wrapper(
188 client_secrets.create,
189 )