client_secrets.py 7.5 KB

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