main
1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5from typing import List, Union, Optional
6from typing_extensions import Literal
7
8import httpx
9
10from ... import _legacy_response
11from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given
12from ..._utils import maybe_transform, async_maybe_transform
13from ..._compat import cached_property
14from ..._resource import SyncAPIResource, AsyncAPIResource
15from ..._response import (
16 StreamedBinaryAPIResponse,
17 AsyncStreamedBinaryAPIResponse,
18 to_streamed_response_wrapper,
19 async_to_streamed_response_wrapper,
20 to_custom_streamed_response_wrapper,
21 async_to_custom_streamed_response_wrapper,
22)
23from ..._base_client import make_request_options
24from ...types.realtime import (
25 call_refer_params,
26 call_accept_params,
27 call_create_params,
28 call_reject_params,
29)
30from ...types.responses.response_prompt_param import ResponsePromptParam
31from ...types.realtime.realtime_truncation_param import RealtimeTruncationParam
32from ...types.realtime.realtime_audio_config_param import RealtimeAudioConfigParam
33from ...types.realtime.realtime_tools_config_param import RealtimeToolsConfigParam
34from ...types.realtime.realtime_tracing_config_param import RealtimeTracingConfigParam
35from ...types.realtime.realtime_tool_choice_config_param import RealtimeToolChoiceConfigParam
36from ...types.realtime.realtime_session_create_request_param import RealtimeSessionCreateRequestParam
37
38__all__ = ["Calls", "AsyncCalls"]
39
40
41class Calls(SyncAPIResource):
42 @cached_property
43 def with_raw_response(self) -> CallsWithRawResponse:
44 """
45 This property can be used as a prefix for any HTTP method call to return
46 the raw response object instead of the parsed content.
47
48 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
49 """
50 return CallsWithRawResponse(self)
51
52 @cached_property
53 def with_streaming_response(self) -> CallsWithStreamingResponse:
54 """
55 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
56
57 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
58 """
59 return CallsWithStreamingResponse(self)
60
61 def create(
62 self,
63 *,
64 sdp: str,
65 session: RealtimeSessionCreateRequestParam | Omit = omit,
66 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
67 # The extra values given here take precedence over values defined on the client or passed to this method.
68 extra_headers: Headers | None = None,
69 extra_query: Query | None = None,
70 extra_body: Body | None = None,
71 timeout: float | httpx.Timeout | None | NotGiven = not_given,
72 ) -> _legacy_response.HttpxBinaryResponseContent:
73 """
74 Create a new Realtime API call over WebRTC and receive the SDP answer needed to
75 complete the peer connection.
76
77 Args:
78 sdp: WebRTC Session Description Protocol (SDP) offer generated by the caller.
79
80 session: Realtime session object configuration.
81
82 extra_headers: Send extra headers
83
84 extra_query: Add additional query parameters to the request
85
86 extra_body: Add additional JSON properties to the request
87
88 timeout: Override the client-level default timeout for this request, in seconds
89 """
90 extra_headers = {"Accept": "application/sdp", **(extra_headers or {})}
91 return self._post(
92 "/realtime/calls",
93 body=maybe_transform(
94 {
95 "sdp": sdp,
96 "session": session,
97 },
98 call_create_params.CallCreateParams,
99 ),
100 options=make_request_options(
101 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
102 ),
103 cast_to=_legacy_response.HttpxBinaryResponseContent,
104 )
105
106 def accept(
107 self,
108 call_id: str,
109 *,
110 type: Literal["realtime"],
111 audio: RealtimeAudioConfigParam | Omit = omit,
112 include: List[Literal["item.input_audio_transcription.logprobs"]] | Omit = omit,
113 instructions: str | Omit = omit,
114 max_output_tokens: Union[int, Literal["inf"]] | Omit = omit,
115 model: Union[
116 str,
117 Literal[
118 "gpt-realtime",
119 "gpt-realtime-2025-08-28",
120 "gpt-4o-realtime-preview",
121 "gpt-4o-realtime-preview-2024-10-01",
122 "gpt-4o-realtime-preview-2024-12-17",
123 "gpt-4o-realtime-preview-2025-06-03",
124 "gpt-4o-mini-realtime-preview",
125 "gpt-4o-mini-realtime-preview-2024-12-17",
126 "gpt-realtime-mini",
127 "gpt-realtime-mini-2025-10-06",
128 "gpt-audio-mini",
129 "gpt-audio-mini-2025-10-06",
130 ],
131 ]
132 | Omit = omit,
133 output_modalities: List[Literal["text", "audio"]] | Omit = omit,
134 prompt: Optional[ResponsePromptParam] | Omit = omit,
135 tool_choice: RealtimeToolChoiceConfigParam | Omit = omit,
136 tools: RealtimeToolsConfigParam | Omit = omit,
137 tracing: Optional[RealtimeTracingConfigParam] | Omit = omit,
138 truncation: RealtimeTruncationParam | Omit = omit,
139 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
140 # The extra values given here take precedence over values defined on the client or passed to this method.
141 extra_headers: Headers | None = None,
142 extra_query: Query | None = None,
143 extra_body: Body | None = None,
144 timeout: float | httpx.Timeout | None | NotGiven = not_given,
145 ) -> None:
146 """
147 Accept an incoming SIP call and configure the realtime session that will handle
148 it.
149
150 Args:
151 type: The type of session to create. Always `realtime` for the Realtime API.
152
153 audio: Configuration for input and output audio.
154
155 include: Additional fields to include in server outputs.
156
157 `item.input_audio_transcription.logprobs`: Include logprobs for input audio
158 transcription.
159
160 instructions: The default system instructions (i.e. system message) prepended to model calls.
161 This field allows the client to guide the model on desired responses. The model
162 can be instructed on response content and format, (e.g. "be extremely succinct",
163 "act friendly", "here are examples of good responses") and on audio behavior
164 (e.g. "talk quickly", "inject emotion into your voice", "laugh frequently"). The
165 instructions are not guaranteed to be followed by the model, but they provide
166 guidance to the model on the desired behavior.
167
168 Note that the server sets default instructions which will be used if this field
169 is not set and are visible in the `session.created` event at the start of the
170 session.
171
172 max_output_tokens: Maximum number of output tokens for a single assistant response, inclusive of
173 tool calls. Provide an integer between 1 and 4096 to limit output tokens, or
174 `inf` for the maximum available tokens for a given model. Defaults to `inf`.
175
176 model: The Realtime model used for this session.
177
178 output_modalities: The set of modalities the model can respond with. It defaults to `["audio"]`,
179 indicating that the model will respond with audio plus a transcript. `["text"]`
180 can be used to make the model respond with text only. It is not possible to
181 request both `text` and `audio` at the same time.
182
183 prompt: Reference to a prompt template and its variables.
184 [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
185
186 tool_choice: How the model chooses tools. Provide one of the string modes or force a specific
187 function/MCP tool.
188
189 tools: Tools available to the model.
190
191 tracing: Realtime API can write session traces to the
192 [Traces Dashboard](/logs?api=traces). Set to null to disable tracing. Once
193 tracing is enabled for a session, the configuration cannot be modified.
194
195 `auto` will create a trace for the session with default values for the workflow
196 name, group id, and metadata.
197
198 truncation: When the number of tokens in a conversation exceeds the model's input token
199 limit, the conversation be truncated, meaning messages (starting from the
200 oldest) will not be included in the model's context. A 32k context model with
201 4,096 max output tokens can only include 28,224 tokens in the context before
202 truncation occurs.
203
204 Clients can configure truncation behavior to truncate with a lower max token
205 limit, which is an effective way to control token usage and cost.
206
207 Truncation will reduce the number of cached tokens on the next turn (busting the
208 cache), since messages are dropped from the beginning of the context. However,
209 clients can also configure truncation to retain messages up to a fraction of the
210 maximum context size, which will reduce the need for future truncations and thus
211 improve the cache rate.
212
213 Truncation can be disabled entirely, which means the server will never truncate
214 but would instead return an error if the conversation exceeds the model's input
215 token limit.
216
217 extra_headers: Send extra headers
218
219 extra_query: Add additional query parameters to the request
220
221 extra_body: Add additional JSON properties to the request
222
223 timeout: Override the client-level default timeout for this request, in seconds
224 """
225 if not call_id:
226 raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}")
227 extra_headers = {"Accept": "*/*", **(extra_headers or {})}
228 return self._post(
229 f"/realtime/calls/{call_id}/accept",
230 body=maybe_transform(
231 {
232 "type": type,
233 "audio": audio,
234 "include": include,
235 "instructions": instructions,
236 "max_output_tokens": max_output_tokens,
237 "model": model,
238 "output_modalities": output_modalities,
239 "prompt": prompt,
240 "tool_choice": tool_choice,
241 "tools": tools,
242 "tracing": tracing,
243 "truncation": truncation,
244 },
245 call_accept_params.CallAcceptParams,
246 ),
247 options=make_request_options(
248 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
249 ),
250 cast_to=NoneType,
251 )
252
253 def hangup(
254 self,
255 call_id: str,
256 *,
257 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
258 # The extra values given here take precedence over values defined on the client or passed to this method.
259 extra_headers: Headers | None = None,
260 extra_query: Query | None = None,
261 extra_body: Body | None = None,
262 timeout: float | httpx.Timeout | None | NotGiven = not_given,
263 ) -> None:
264 """
265 End an active Realtime API call, whether it was initiated over SIP or WebRTC.
266
267 Args:
268 extra_headers: Send extra headers
269
270 extra_query: Add additional query parameters to the request
271
272 extra_body: Add additional JSON properties to the request
273
274 timeout: Override the client-level default timeout for this request, in seconds
275 """
276 if not call_id:
277 raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}")
278 extra_headers = {"Accept": "*/*", **(extra_headers or {})}
279 return self._post(
280 f"/realtime/calls/{call_id}/hangup",
281 options=make_request_options(
282 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
283 ),
284 cast_to=NoneType,
285 )
286
287 def refer(
288 self,
289 call_id: str,
290 *,
291 target_uri: str,
292 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
293 # The extra values given here take precedence over values defined on the client or passed to this method.
294 extra_headers: Headers | None = None,
295 extra_query: Query | None = None,
296 extra_body: Body | None = None,
297 timeout: float | httpx.Timeout | None | NotGiven = not_given,
298 ) -> None:
299 """
300 Transfer an active SIP call to a new destination using the SIP REFER verb.
301
302 Args:
303 target_uri: URI that should appear in the SIP Refer-To header. Supports values like
304 `tel:+14155550123` or `sip:agent@example.com`.
305
306 extra_headers: Send extra headers
307
308 extra_query: Add additional query parameters to the request
309
310 extra_body: Add additional JSON properties to the request
311
312 timeout: Override the client-level default timeout for this request, in seconds
313 """
314 if not call_id:
315 raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}")
316 extra_headers = {"Accept": "*/*", **(extra_headers or {})}
317 return self._post(
318 f"/realtime/calls/{call_id}/refer",
319 body=maybe_transform({"target_uri": target_uri}, call_refer_params.CallReferParams),
320 options=make_request_options(
321 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
322 ),
323 cast_to=NoneType,
324 )
325
326 def reject(
327 self,
328 call_id: str,
329 *,
330 status_code: int | Omit = omit,
331 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
332 # The extra values given here take precedence over values defined on the client or passed to this method.
333 extra_headers: Headers | None = None,
334 extra_query: Query | None = None,
335 extra_body: Body | None = None,
336 timeout: float | httpx.Timeout | None | NotGiven = not_given,
337 ) -> None:
338 """
339 Decline an incoming SIP call by returning a SIP status code to the caller.
340
341 Args:
342 status_code: SIP response code to send back to the caller. Defaults to `603` (Decline) when
343 omitted.
344
345 extra_headers: Send extra headers
346
347 extra_query: Add additional query parameters to the request
348
349 extra_body: Add additional JSON properties to the request
350
351 timeout: Override the client-level default timeout for this request, in seconds
352 """
353 if not call_id:
354 raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}")
355 extra_headers = {"Accept": "*/*", **(extra_headers or {})}
356 return self._post(
357 f"/realtime/calls/{call_id}/reject",
358 body=maybe_transform({"status_code": status_code}, call_reject_params.CallRejectParams),
359 options=make_request_options(
360 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
361 ),
362 cast_to=NoneType,
363 )
364
365
366class AsyncCalls(AsyncAPIResource):
367 @cached_property
368 def with_raw_response(self) -> AsyncCallsWithRawResponse:
369 """
370 This property can be used as a prefix for any HTTP method call to return
371 the raw response object instead of the parsed content.
372
373 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
374 """
375 return AsyncCallsWithRawResponse(self)
376
377 @cached_property
378 def with_streaming_response(self) -> AsyncCallsWithStreamingResponse:
379 """
380 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
381
382 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
383 """
384 return AsyncCallsWithStreamingResponse(self)
385
386 async def create(
387 self,
388 *,
389 sdp: str,
390 session: RealtimeSessionCreateRequestParam | Omit = omit,
391 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
392 # The extra values given here take precedence over values defined on the client or passed to this method.
393 extra_headers: Headers | None = None,
394 extra_query: Query | None = None,
395 extra_body: Body | None = None,
396 timeout: float | httpx.Timeout | None | NotGiven = not_given,
397 ) -> _legacy_response.HttpxBinaryResponseContent:
398 """
399 Create a new Realtime API call over WebRTC and receive the SDP answer needed to
400 complete the peer connection.
401
402 Args:
403 sdp: WebRTC Session Description Protocol (SDP) offer generated by the caller.
404
405 session: Realtime session object configuration.
406
407 extra_headers: Send extra headers
408
409 extra_query: Add additional query parameters to the request
410
411 extra_body: Add additional JSON properties to the request
412
413 timeout: Override the client-level default timeout for this request, in seconds
414 """
415 extra_headers = {"Accept": "application/sdp", **(extra_headers or {})}
416 return await self._post(
417 "/realtime/calls",
418 body=await async_maybe_transform(
419 {
420 "sdp": sdp,
421 "session": session,
422 },
423 call_create_params.CallCreateParams,
424 ),
425 options=make_request_options(
426 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
427 ),
428 cast_to=_legacy_response.HttpxBinaryResponseContent,
429 )
430
431 async def accept(
432 self,
433 call_id: str,
434 *,
435 type: Literal["realtime"],
436 audio: RealtimeAudioConfigParam | Omit = omit,
437 include: List[Literal["item.input_audio_transcription.logprobs"]] | Omit = omit,
438 instructions: str | Omit = omit,
439 max_output_tokens: Union[int, Literal["inf"]] | Omit = omit,
440 model: Union[
441 str,
442 Literal[
443 "gpt-realtime",
444 "gpt-realtime-2025-08-28",
445 "gpt-4o-realtime-preview",
446 "gpt-4o-realtime-preview-2024-10-01",
447 "gpt-4o-realtime-preview-2024-12-17",
448 "gpt-4o-realtime-preview-2025-06-03",
449 "gpt-4o-mini-realtime-preview",
450 "gpt-4o-mini-realtime-preview-2024-12-17",
451 "gpt-realtime-mini",
452 "gpt-realtime-mini-2025-10-06",
453 "gpt-audio-mini",
454 "gpt-audio-mini-2025-10-06",
455 ],
456 ]
457 | Omit = omit,
458 output_modalities: List[Literal["text", "audio"]] | Omit = omit,
459 prompt: Optional[ResponsePromptParam] | Omit = omit,
460 tool_choice: RealtimeToolChoiceConfigParam | Omit = omit,
461 tools: RealtimeToolsConfigParam | Omit = omit,
462 tracing: Optional[RealtimeTracingConfigParam] | Omit = omit,
463 truncation: RealtimeTruncationParam | Omit = omit,
464 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
465 # The extra values given here take precedence over values defined on the client or passed to this method.
466 extra_headers: Headers | None = None,
467 extra_query: Query | None = None,
468 extra_body: Body | None = None,
469 timeout: float | httpx.Timeout | None | NotGiven = not_given,
470 ) -> None:
471 """
472 Accept an incoming SIP call and configure the realtime session that will handle
473 it.
474
475 Args:
476 type: The type of session to create. Always `realtime` for the Realtime API.
477
478 audio: Configuration for input and output audio.
479
480 include: Additional fields to include in server outputs.
481
482 `item.input_audio_transcription.logprobs`: Include logprobs for input audio
483 transcription.
484
485 instructions: The default system instructions (i.e. system message) prepended to model calls.
486 This field allows the client to guide the model on desired responses. The model
487 can be instructed on response content and format, (e.g. "be extremely succinct",
488 "act friendly", "here are examples of good responses") and on audio behavior
489 (e.g. "talk quickly", "inject emotion into your voice", "laugh frequently"). The
490 instructions are not guaranteed to be followed by the model, but they provide
491 guidance to the model on the desired behavior.
492
493 Note that the server sets default instructions which will be used if this field
494 is not set and are visible in the `session.created` event at the start of the
495 session.
496
497 max_output_tokens: Maximum number of output tokens for a single assistant response, inclusive of
498 tool calls. Provide an integer between 1 and 4096 to limit output tokens, or
499 `inf` for the maximum available tokens for a given model. Defaults to `inf`.
500
501 model: The Realtime model used for this session.
502
503 output_modalities: The set of modalities the model can respond with. It defaults to `["audio"]`,
504 indicating that the model will respond with audio plus a transcript. `["text"]`
505 can be used to make the model respond with text only. It is not possible to
506 request both `text` and `audio` at the same time.
507
508 prompt: Reference to a prompt template and its variables.
509 [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
510
511 tool_choice: How the model chooses tools. Provide one of the string modes or force a specific
512 function/MCP tool.
513
514 tools: Tools available to the model.
515
516 tracing: Realtime API can write session traces to the
517 [Traces Dashboard](/logs?api=traces). Set to null to disable tracing. Once
518 tracing is enabled for a session, the configuration cannot be modified.
519
520 `auto` will create a trace for the session with default values for the workflow
521 name, group id, and metadata.
522
523 truncation: When the number of tokens in a conversation exceeds the model's input token
524 limit, the conversation be truncated, meaning messages (starting from the
525 oldest) will not be included in the model's context. A 32k context model with
526 4,096 max output tokens can only include 28,224 tokens in the context before
527 truncation occurs.
528
529 Clients can configure truncation behavior to truncate with a lower max token
530 limit, which is an effective way to control token usage and cost.
531
532 Truncation will reduce the number of cached tokens on the next turn (busting the
533 cache), since messages are dropped from the beginning of the context. However,
534 clients can also configure truncation to retain messages up to a fraction of the
535 maximum context size, which will reduce the need for future truncations and thus
536 improve the cache rate.
537
538 Truncation can be disabled entirely, which means the server will never truncate
539 but would instead return an error if the conversation exceeds the model's input
540 token limit.
541
542 extra_headers: Send extra headers
543
544 extra_query: Add additional query parameters to the request
545
546 extra_body: Add additional JSON properties to the request
547
548 timeout: Override the client-level default timeout for this request, in seconds
549 """
550 if not call_id:
551 raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}")
552 extra_headers = {"Accept": "*/*", **(extra_headers or {})}
553 return await self._post(
554 f"/realtime/calls/{call_id}/accept",
555 body=await async_maybe_transform(
556 {
557 "type": type,
558 "audio": audio,
559 "include": include,
560 "instructions": instructions,
561 "max_output_tokens": max_output_tokens,
562 "model": model,
563 "output_modalities": output_modalities,
564 "prompt": prompt,
565 "tool_choice": tool_choice,
566 "tools": tools,
567 "tracing": tracing,
568 "truncation": truncation,
569 },
570 call_accept_params.CallAcceptParams,
571 ),
572 options=make_request_options(
573 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
574 ),
575 cast_to=NoneType,
576 )
577
578 async def hangup(
579 self,
580 call_id: str,
581 *,
582 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
583 # The extra values given here take precedence over values defined on the client or passed to this method.
584 extra_headers: Headers | None = None,
585 extra_query: Query | None = None,
586 extra_body: Body | None = None,
587 timeout: float | httpx.Timeout | None | NotGiven = not_given,
588 ) -> None:
589 """
590 End an active Realtime API call, whether it was initiated over SIP or WebRTC.
591
592 Args:
593 extra_headers: Send extra headers
594
595 extra_query: Add additional query parameters to the request
596
597 extra_body: Add additional JSON properties to the request
598
599 timeout: Override the client-level default timeout for this request, in seconds
600 """
601 if not call_id:
602 raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}")
603 extra_headers = {"Accept": "*/*", **(extra_headers or {})}
604 return await self._post(
605 f"/realtime/calls/{call_id}/hangup",
606 options=make_request_options(
607 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
608 ),
609 cast_to=NoneType,
610 )
611
612 async def refer(
613 self,
614 call_id: str,
615 *,
616 target_uri: str,
617 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
618 # The extra values given here take precedence over values defined on the client or passed to this method.
619 extra_headers: Headers | None = None,
620 extra_query: Query | None = None,
621 extra_body: Body | None = None,
622 timeout: float | httpx.Timeout | None | NotGiven = not_given,
623 ) -> None:
624 """
625 Transfer an active SIP call to a new destination using the SIP REFER verb.
626
627 Args:
628 target_uri: URI that should appear in the SIP Refer-To header. Supports values like
629 `tel:+14155550123` or `sip:agent@example.com`.
630
631 extra_headers: Send extra headers
632
633 extra_query: Add additional query parameters to the request
634
635 extra_body: Add additional JSON properties to the request
636
637 timeout: Override the client-level default timeout for this request, in seconds
638 """
639 if not call_id:
640 raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}")
641 extra_headers = {"Accept": "*/*", **(extra_headers or {})}
642 return await self._post(
643 f"/realtime/calls/{call_id}/refer",
644 body=await async_maybe_transform({"target_uri": target_uri}, call_refer_params.CallReferParams),
645 options=make_request_options(
646 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
647 ),
648 cast_to=NoneType,
649 )
650
651 async def reject(
652 self,
653 call_id: str,
654 *,
655 status_code: int | Omit = omit,
656 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
657 # The extra values given here take precedence over values defined on the client or passed to this method.
658 extra_headers: Headers | None = None,
659 extra_query: Query | None = None,
660 extra_body: Body | None = None,
661 timeout: float | httpx.Timeout | None | NotGiven = not_given,
662 ) -> None:
663 """
664 Decline an incoming SIP call by returning a SIP status code to the caller.
665
666 Args:
667 status_code: SIP response code to send back to the caller. Defaults to `603` (Decline) when
668 omitted.
669
670 extra_headers: Send extra headers
671
672 extra_query: Add additional query parameters to the request
673
674 extra_body: Add additional JSON properties to the request
675
676 timeout: Override the client-level default timeout for this request, in seconds
677 """
678 if not call_id:
679 raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}")
680 extra_headers = {"Accept": "*/*", **(extra_headers or {})}
681 return await self._post(
682 f"/realtime/calls/{call_id}/reject",
683 body=await async_maybe_transform({"status_code": status_code}, call_reject_params.CallRejectParams),
684 options=make_request_options(
685 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
686 ),
687 cast_to=NoneType,
688 )
689
690
691class CallsWithRawResponse:
692 def __init__(self, calls: Calls) -> None:
693 self._calls = calls
694
695 self.create = _legacy_response.to_raw_response_wrapper(
696 calls.create,
697 )
698 self.accept = _legacy_response.to_raw_response_wrapper(
699 calls.accept,
700 )
701 self.hangup = _legacy_response.to_raw_response_wrapper(
702 calls.hangup,
703 )
704 self.refer = _legacy_response.to_raw_response_wrapper(
705 calls.refer,
706 )
707 self.reject = _legacy_response.to_raw_response_wrapper(
708 calls.reject,
709 )
710
711
712class AsyncCallsWithRawResponse:
713 def __init__(self, calls: AsyncCalls) -> None:
714 self._calls = calls
715
716 self.create = _legacy_response.async_to_raw_response_wrapper(
717 calls.create,
718 )
719 self.accept = _legacy_response.async_to_raw_response_wrapper(
720 calls.accept,
721 )
722 self.hangup = _legacy_response.async_to_raw_response_wrapper(
723 calls.hangup,
724 )
725 self.refer = _legacy_response.async_to_raw_response_wrapper(
726 calls.refer,
727 )
728 self.reject = _legacy_response.async_to_raw_response_wrapper(
729 calls.reject,
730 )
731
732
733class CallsWithStreamingResponse:
734 def __init__(self, calls: Calls) -> None:
735 self._calls = calls
736
737 self.create = to_custom_streamed_response_wrapper(
738 calls.create,
739 StreamedBinaryAPIResponse,
740 )
741 self.accept = to_streamed_response_wrapper(
742 calls.accept,
743 )
744 self.hangup = to_streamed_response_wrapper(
745 calls.hangup,
746 )
747 self.refer = to_streamed_response_wrapper(
748 calls.refer,
749 )
750 self.reject = to_streamed_response_wrapper(
751 calls.reject,
752 )
753
754
755class AsyncCallsWithStreamingResponse:
756 def __init__(self, calls: AsyncCalls) -> None:
757 self._calls = calls
758
759 self.create = async_to_custom_streamed_response_wrapper(
760 calls.create,
761 AsyncStreamedBinaryAPIResponse,
762 )
763 self.accept = async_to_streamed_response_wrapper(
764 calls.accept,
765 )
766 self.hangup = async_to_streamed_response_wrapper(
767 calls.hangup,
768 )
769 self.refer = async_to_streamed_response_wrapper(
770 calls.refer,
771 )
772 self.reject = async_to_streamed_response_wrapper(
773 calls.reject,
774 )