resources/realtime/subresources/sessions/methods/create/index.md +0 −811 deleted
File Deleted View Diff
1## Create session
2
3**post** `/realtime/sessions`
4
5Create an ephemeral API token for use in client-side applications with the
6Realtime API. Can be configured with the same session parameters as the
7`session.update` client event.
8
9It responds with a session object, plus a `client_secret` key which contains
10a usable ephemeral API token that can be used to authenticate browser clients
11for the Realtime API.
12
13Returns the created Realtime session object, plus an ephemeral key.
14
15### Body Parameters
16
17- `client_secret: object { expires_at, value }`
18
19 Ephemeral key returned by the API.
20
21 - `expires_at: number`
22
23 Timestamp for when the token expires. Currently, all tokens expire
24 after one minute.
25
26 - `value: string`
27
28 Ephemeral key usable in client environments to authenticate connections
29 to the Realtime API. Use this in client-side environments rather than
30 a standard API token, which should only be used server-side.
31
32- `input_audio_format: optional string`
33
34 The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.
35
36- `input_audio_transcription: optional object { model }`
37
38 Configuration for input audio transcription, defaults to off and can be
39 set to `null` to turn off once on. Input audio transcription is not native
40 to the model, since the model consumes audio directly. Transcription runs
41 asynchronously and should be treated as rough guidance
42 rather than the representation understood by the model.
43
44 - `model: optional string`
45
46 The model to use for transcription.
47
48- `instructions: optional string`
49
50 The default system instructions (i.e. system message) prepended to model calls. This field allows the client to guide the model on desired responses. The model can be instructed on response content and format, (e.g. "be extremely succinct", "act friendly", "here are examples of good responses") and on audio behavior (e.g. "talk quickly", "inject emotion into your voice", "laugh frequently"). The instructions are not guaranteed to be followed by the model, but they provide guidance to the model on the desired behavior.
51 Note that the server sets default instructions which will be used if this field is not set and are visible in the `session.created` event at the start of the session.
52
53- `max_response_output_tokens: optional number or "inf"`
54
55 Maximum number of output tokens for a single assistant response,
56 inclusive of tool calls. Provide an integer between 1 and 4096 to
57 limit output tokens, or `inf` for the maximum available tokens for a
58 given model. Defaults to `inf`.
59
60 - `number`
61
62 - `"inf"`
63
64 - `"inf"`
65
66- `modalities: optional array of "text" or "audio"`
67
68 The set of modalities the model can respond with. To disable audio,
69 set this to ["text"].
70
71 - `"text"`
72
73 - `"audio"`
74
75- `output_audio_format: optional string`
76
77 The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.
78
79- `prompt: optional ResponsePrompt or null`
80
81 Reference to a prompt template and its variables.
82 [Learn more](/api/docs/guides/text?api-mode=responses#version-prompts-in-code).
83
84 - `id: string`
85
86 The unique identifier of the prompt template to use.
87
88 - `variables: optional map[string or ResponseInputText or ResponseInputImage or ResponseInputFile] or null`
89
90 Optional map of values to substitute in for variables in your
91 prompt. The substitution values can either be strings, or other
92 Response input types like images or files.
93
94 - `string`
95
96 - `ResponseInputText object { text, type, prompt_cache_breakpoint }`
97
98 A text input to the model.
99
100 - `text: string`
101
102 The text input to the model.
103
104 - `type: "input_text"`
105
106 The type of the input item. Always `input_text`.
107
108 - `"input_text"`
109
110 - `prompt_cache_breakpoint: optional object { mode }`
111
112 Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a token block.
113
114 - `mode: "explicit"`
115
116 The breakpoint mode. Always `explicit`.
117
118 - `"explicit"`
119
120 - `ResponseInputImage object { detail, type, file_id, 2 more }`
121
122 An image input to the model. Learn about [image inputs](/api/docs/guides/images-vision).
123
124 - `detail: ImageDetail`
125
126 The detail level of the image to be sent to the model. One of `high`, `low`, `auto`, or `original`. Defaults to `auto`.
127
128 - `"low"`
129
130 - `"high"`
131
132 - `"auto"`
133
134 - `"original"`
135
136 - `type: "input_image"`
137
138 The type of the input item. Always `input_image`.
139
140 - `"input_image"`
141
142 - `file_id: optional string or null`
143
144 The ID of the file to be sent to the model.
145
146 - `image_url: optional string or null`
147
148 The URL of the image to be sent to the model. A fully qualified URL or base64 encoded image in a data URL.
149
150 - `prompt_cache_breakpoint: optional object { mode }`
151
152 Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a token block.
153
154 - `mode: "explicit"`
155
156 The breakpoint mode. Always `explicit`.
157
158 - `"explicit"`
159
160 - `ResponseInputFile object { type, detail, file_data, 4 more }`
161
162 A file input to the model.
163
164 - `type: "input_file"`
165
166 The type of the input item. Always `input_file`.
167
168 - `"input_file"`
169
170 - `detail: optional "auto" or "low" or "high"`
171
172 The detail level of the file to be sent to the model. Use `auto` to let the system select the detail level; for GPT-5.6 and later models, `auto` uses high-quality rendering, which may increase input token usage. Use `low` for lower-cost rendering, or `high` to render the file at higher quality. Defaults to `auto`.
173
174 - `"auto"`
175
176 - `"low"`
177
178 - `"high"`
179
180 - `file_data: optional string`
181
182 The content of the file to be sent to the model.
183
184 - `file_id: optional string or null`
185
186 The ID of the file to be sent to the model.
187
188 - `file_url: optional string`
189
190 The URL of the file to be sent to the model.
191
192 - `filename: optional string`
193
194 The name of the file to be sent to the model.
195
196 - `prompt_cache_breakpoint: optional object { mode }`
197
198 Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a token block.
199
200 - `mode: "explicit"`
201
202 The breakpoint mode. Always `explicit`.
203
204 - `"explicit"`
205
206 - `version: optional string or null`
207
208 Optional version of the prompt template.
209
210- `speed: optional number`
211
212 The speed of the model's spoken response. 1.0 is the default speed. 0.25 is
213 the minimum speed. 1.5 is the maximum speed. This value can only be changed
214 in between model turns, not while a response is in progress.
215
216- `temperature: optional number`
217
218 Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.
219
220- `tool_choice: optional string`
221
222 How the model chooses tools. Options are `auto`, `none`, `required`, or
223 specify a function.
224
225- `tools: optional array of object { description, name, parameters, type }`
226
227 Tools (functions) available to the model.
228
229 - `description: optional string`
230
231 The description of the function, including guidance on when and how
232 to call it, and guidance about what to tell the user when calling
233 (if anything).
234
235 - `name: optional string`
236
237 The name of the function.
238
239 - `parameters: optional unknown`
240
241 Parameters of the function in JSON Schema.
242
243 - `type: optional "function"`
244
245 The type of the tool, i.e. `function`.
246
247 - `"function"`
248
249- `tracing: optional "auto" or object { group_id, metadata, workflow_name }`
250
251 Configuration options for tracing. Set to null to disable tracing. Once
252 tracing is enabled for a session, the configuration cannot be modified.
253
254 `auto` will create a trace for the session with default values for the
255 workflow name, group id, and metadata.
256
257 - `"auto"`
258
259 Default tracing mode for the session.
260
261 - `"auto"`
262
263 - `TracingConfiguration object { group_id, metadata, workflow_name }`
264
265 Granular configuration for tracing.
266
267 - `group_id: optional string`
268
269 The group id to attach to this trace to enable filtering and
270 grouping in the traces dashboard.
271
272 - `metadata: optional unknown`
273
274 The arbitrary metadata to attach to this trace to enable
275 filtering in the traces dashboard.
276
277 - `workflow_name: optional string`
278
279 The name of the workflow to attach to this trace. This is used to
280 name the trace in the traces dashboard.
281
282- `truncation: optional RealtimeTruncation`
283
284 When the number of tokens in a conversation exceeds the model's input token limit, the conversation be truncated, meaning messages (starting from the oldest) will not be included in the model's context. A 32k context model with 4,096 max output tokens can only include 28,224 tokens in the context before truncation occurs.
285
286 Clients can configure truncation behavior to truncate with a lower max token limit, which is an effective way to control token usage and cost.
287
288 Truncation will reduce the number of cached tokens on the next turn (busting the cache), since messages are dropped from the beginning of the context. However, clients can also configure truncation to retain messages up to a fraction of the maximum context size, which will reduce the need for future truncations and thus improve the cache rate.
289
290 Truncation can be disabled entirely, which means the server will never truncate but would instead return an error if the conversation exceeds the model's input token limit.
291
292 - `"auto" or "disabled"`
293
294 The truncation strategy to use for the session. `auto` is the default truncation strategy. `disabled` will disable truncation and emit errors when the conversation exceeds the input token limit.
295
296 - `"auto"`
297
298 - `"disabled"`
299
300 - `RetentionRatioTruncation object { retention_ratio, type, token_limits }`
301
302 Retain a fraction of the conversation tokens when the conversation exceeds the input token limit. This allows you to amortize truncations across multiple turns, which can help improve cached token usage.
303
304 - `retention_ratio: number`
305
306 Fraction of post-instruction conversation tokens to retain (`0.0` - `1.0`) when the conversation exceeds the input token limit. Setting this to `0.8` means that messages will be dropped until 80% of the maximum allowed tokens are used. This helps reduce the frequency of truncations and improve cache rates.
307
308 - `type: "retention_ratio"`
309
310 Use retention ratio truncation.
311
312 - `"retention_ratio"`
313
314 - `token_limits: optional object { post_instructions }`
315
316 Optional custom token limits for this truncation strategy. If not provided, the model's default token limits will be used.
317
318 - `post_instructions: optional number`
319
320 Maximum tokens allowed in the conversation after instructions (which including tool definitions). For example, setting this to 5,000 would mean that truncation would occur when the conversation exceeds 5,000 tokens after instructions. This cannot be higher than the model's context window size minus the maximum output tokens.
321
322- `turn_detection: optional object { prefix_padding_ms, silence_duration_ms, threshold, type }`
323
324 Configuration for turn detection. Can be set to `null` to turn off. Server
325 VAD means that the model will detect the start and end of speech based on
326 audio volume and respond at the end of user speech.
327
328 - `prefix_padding_ms: optional number`
329
330 Amount of audio to include before the VAD detected speech (in
331 milliseconds). Defaults to 300ms.
332
333 - `silence_duration_ms: optional number`
334
335 Duration of silence to detect speech stop (in milliseconds). Defaults
336 to 500ms. With shorter values the model will respond more quickly,
337 but may jump in on short pauses from the user.
338
339 - `threshold: optional number`
340
341 Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A
342 higher threshold will require louder audio to activate the model, and
343 thus might perform better in noisy environments.
344
345 - `type: optional string`
346
347 Type of turn detection, only `server_vad` is currently supported.
348
349- `voice: optional string or "alloy" or "ash" or "ballad" or 7 more or object { id }`
350
351 The voice the model uses to respond. Supported built-in voices are
352 `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, `verse`,
353 `marin`, and `cedar`. You may also provide a custom voice object with an
354 `id`, for example `{ "id": "voice_1234" }`. Voice cannot be changed during
355 the session once the model has responded with audio at least once.
356
357 - `string`
358
359 - `"alloy" or "ash" or "ballad" or 7 more`
360
361 - `"alloy"`
362
363 - `"ash"`
364
365 - `"ballad"`
366
367 - `"coral"`
368
369 - `"echo"`
370
371 - `"sage"`
372
373 - `"shimmer"`
374
375 - `"verse"`
376
377 - `"marin"`
378
379 - `"cedar"`
380
381 - `ID object { id }`
382
383 Custom voice reference.
384
385 - `id: string`
386
387 The custom voice ID, e.g. `voice_1234`.
388
389### Returns
390
391- `id: optional string`
392
393 Unique identifier for the session that looks like `sess_1234567890abcdef`.
394
395- `audio: optional object { input, output }`
396
397 Configuration for input and output audio for the session.
398
399 - `input: optional object { format, noise_reduction, transcription, turn_detection }`
400
401 - `format: optional RealtimeAudioFormats`
402
403 The PCM audio format. Only a 24kHz sample rate is supported.
404
405 - `PCMAudio object { rate, type }`
406
407 The PCM audio format. Only a 24kHz sample rate is supported.
408
409 - `rate: optional 24000`
410
411 The sample rate of the audio. Always `24000`.
412
413 - `24000`
414
415 - `type: optional "audio/pcm"`
416
417 The audio format. Always `audio/pcm`.
418
419 - `"audio/pcm"`
420
421 - `PCMUAudio object { type }`
422
423 The G.711 μ-law format.
424
425 - `type: optional "audio/pcmu"`
426
427 The audio format. Always `audio/pcmu`.
428
429 - `"audio/pcmu"`
430
431 - `PCMAAudio object { type }`
432
433 The G.711 A-law format.
434
435 - `type: optional "audio/pcma"`
436
437 The audio format. Always `audio/pcma`.
438
439 - `"audio/pcma"`
440
441 - `noise_reduction: optional object { type }`
442
443 Configuration for input audio noise reduction.
444
445 - `type: optional NoiseReductionType`
446
447 Type of noise reduction. `near_field` is for close-talking microphones such as headphones, `far_field` is for far-field microphones such as laptop or conference room microphones.
448
449 - `"near_field"`
450
451 - `"far_field"`
452
453 - `transcription: optional object { language, languages, model, prompt }`
454
455 Configuration for input audio transcription.
456
457 - `language: optional string`
458
459 The language of the input audio.
460
461 - `languages: optional array of string`
462
463 The possible input audio languages configured for transcription, in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format.
464
465 - `model: optional string or "whisper-1" or "gpt-transcribe" or "gpt-live-transcribe" or 5 more`
466
467 The model used for transcription. Current options are `whisper-1`, `gpt-transcribe`, `gpt-live-transcribe`, `gpt-4o-mini-transcribe`, `gpt-4o-mini-transcribe-2025-12-15`, `gpt-4o-transcribe`, `gpt-4o-transcribe-diarize`, and `gpt-realtime-whisper`.
468
469 - `string`
470
471 - `"whisper-1" or "gpt-transcribe" or "gpt-live-transcribe" or 5 more`
472
473 The model used for transcription. Current options are `whisper-1`, `gpt-transcribe`, `gpt-live-transcribe`, `gpt-4o-mini-transcribe`, `gpt-4o-mini-transcribe-2025-12-15`, `gpt-4o-transcribe`, `gpt-4o-transcribe-diarize`, and `gpt-realtime-whisper`.
474
475 - `"whisper-1"`
476
477 - `"gpt-transcribe"`
478
479 - `"gpt-live-transcribe"`
480
481 - `"gpt-4o-mini-transcribe"`
482
483 - `"gpt-4o-mini-transcribe-2025-12-15"`
484
485 - `"gpt-4o-transcribe"`
486
487 - `"gpt-4o-transcribe-diarize"`
488
489 - `"gpt-realtime-whisper"`
490
491 - `prompt: optional string`
492
493 The prompt configured for input audio transcription, when present.
494
495 - `turn_detection: optional object { prefix_padding_ms, silence_duration_ms, threshold, type }`
496
497 Configuration for turn detection.
498
499 - `prefix_padding_ms: optional number`
500
501 - `silence_duration_ms: optional number`
502
503 - `threshold: optional number`
504
505 - `type: optional string`
506
507 Type of turn detection, only `server_vad` is currently supported.
508
509 - `output: optional object { format, speed, voice }`
510
511 - `format: optional RealtimeAudioFormats`
512
513 The PCM audio format. Only a 24kHz sample rate is supported.
514
515 - `speed: optional number`
516
517 - `voice: optional string or "alloy" or "ash" or "ballad" or 7 more`
518
519 - `string`
520
521 - `"alloy" or "ash" or "ballad" or 7 more`
522
523 - `"alloy"`
524
525 - `"ash"`
526
527 - `"ballad"`
528
529 - `"coral"`
530
531 - `"echo"`
532
533 - `"sage"`
534
535 - `"shimmer"`
536
537 - `"verse"`
538
539 - `"marin"`
540
541 - `"cedar"`
542
543- `expires_at: optional number`
544
545 Expiration timestamp for the session, in seconds since epoch.
546
547- `include: optional array of "item.input_audio_transcription.logprobs"`
548
549 Additional fields to include in server outputs.
550
551 - `item.input_audio_transcription.logprobs`: Include logprobs for input audio transcription.
552
553 - `"item.input_audio_transcription.logprobs"`
554
555- `instructions: optional string`
556
557 The default system instructions (i.e. system message) prepended to model
558 calls. This field allows the client to guide the model on desired
559 responses. The model can be instructed on response content and format,
560 (e.g. "be extremely succinct", "act friendly", "here are examples of good
561 responses") and on audio behavior (e.g. "talk quickly", "inject emotion
562 into your voice", "laugh frequently"). The instructions are not guaranteed
563 to be followed by the model, but they provide guidance to the model on the
564 desired behavior.
565
566 Note that the server sets default instructions which will be used if this
567 field is not set and are visible in the `session.created` event at the
568 start of the session.
569
570- `max_output_tokens: optional number or "inf"`
571
572 Maximum number of output tokens for a single assistant response,
573 inclusive of tool calls. Provide an integer between 1 and 4096 to
574 limit output tokens, or `inf` for the maximum available tokens for a
575 given model. Defaults to `inf`.
576
577 - `number`
578
579 - `"inf"`
580
581 - `"inf"`
582
583- `model: optional string`
584
585 The Realtime model used for this session.
586
587- `object: optional string`
588
589 The object type. Always `realtime.session`.
590
591- `output_modalities: optional array of "text" or "audio"`
592
593 The set of modalities the model can respond with. To disable audio,
594 set this to ["text"].
595
596 - `"text"`
597
598 - `"audio"`
599
600- `tool_choice: optional string`
601
602 How the model chooses tools. Options are `auto`, `none`, `required`, or
603 specify a function.
604
605- `tools: optional array of RealtimeFunctionTool`
606
607 Tools (functions) available to the model.
608
609 - `description: optional string`
610
611 The description of the function, including guidance on when and how
612 to call it, and guidance about what to tell the user when calling
613 (if anything).
614
615 - `name: optional string`
616
617 The name of the function.
618
619 - `parameters: optional unknown`
620
621 Parameters of the function in JSON Schema.
622
623 - `type: optional "function"`
624
625 The type of the tool, i.e. `function`.
626
627 - `"function"`
628
629- `tracing: optional "auto" or object { group_id, metadata, workflow_name }`
630
631 Configuration options for tracing. Set to null to disable tracing. Once
632 tracing is enabled for a session, the configuration cannot be modified.
633
634 `auto` will create a trace for the session with default values for the
635 workflow name, group id, and metadata.
636
637 - `"auto"`
638
639 Default tracing mode for the session.
640
641 - `"auto"`
642
643 - `TracingConfiguration object { group_id, metadata, workflow_name }`
644
645 Granular configuration for tracing.
646
647 - `group_id: optional string`
648
649 The group id to attach to this trace to enable filtering and
650 grouping in the traces dashboard.
651
652 - `metadata: optional unknown`
653
654 The arbitrary metadata to attach to this trace to enable
655 filtering in the traces dashboard.
656
657 - `workflow_name: optional string`
658
659 The name of the workflow to attach to this trace. This is used to
660 name the trace in the traces dashboard.
661
662- `turn_detection: optional object { prefix_padding_ms, silence_duration_ms, threshold, type }`
663
664 Configuration for turn detection. Can be set to `null` to turn off. Server
665 VAD means that the model will detect the start and end of speech based on
666 audio volume and respond at the end of user speech.
667
668 - `prefix_padding_ms: optional number`
669
670 Amount of audio to include before the VAD detected speech (in
671 milliseconds). Defaults to 300ms.
672
673 - `silence_duration_ms: optional number`
674
675 Duration of silence to detect speech stop (in milliseconds). Defaults
676 to 500ms. With shorter values the model will respond more quickly,
677 but may jump in on short pauses from the user.
678
679 - `threshold: optional number`
680
681 Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A
682 higher threshold will require louder audio to activate the model, and
683 thus might perform better in noisy environments.
684
685 - `type: optional string`
686
687 Type of turn detection, only `server_vad` is currently supported.
688
689### Example
690
691```http
692curl https://api.openai.com/v1/realtime/sessions \
693 -H 'Content-Type: application/json' \
694 -H "Authorization: Bearer $OPENAI_API_KEY" \
695 -d '{
696 "client_secret": {
697 "expires_at": 0,
698 "value": "value"
699 }
700 }'
701```
702
703#### Response
704
705```json
706{
707 "id": "id",
708 "audio": {
709 "input": {
710 "format": {
711 "rate": 24000,
712 "type": "audio/pcm"
713 },
714 "noise_reduction": {
715 "type": "near_field"
716 },
717 "transcription": {
718 "language": "language",
719 "languages": [
720 "string"
721 ],
722 "model": "whisper-1",
723 "prompt": "prompt"
724 },
725 "turn_detection": {
726 "prefix_padding_ms": 0,
727 "silence_duration_ms": 0,
728 "threshold": 0,
729 "type": "type"
730 }
731 },
732 "output": {
733 "format": {
734 "rate": 24000,
735 "type": "audio/pcm"
736 },
737 "speed": 0,
738 "voice": "ash"
739 }
740 },
741 "expires_at": 0,
742 "include": [
743 "item.input_audio_transcription.logprobs"
744 ],
745 "instructions": "instructions",
746 "max_output_tokens": "inf",
747 "model": "model",
748 "object": "object",
749 "output_modalities": [
750 "text"
751 ],
752 "tool_choice": "tool_choice",
753 "tools": [
754 {
755 "description": "description",
756 "name": "name",
757 "parameters": {},
758 "type": "function"
759 }
760 ],
761 "tracing": "auto",
762 "turn_detection": {
763 "prefix_padding_ms": 0,
764 "silence_duration_ms": 0,
765 "threshold": 0,
766 "type": "type"
767 }
768}
769```
770
771### Example
772
773```http
774curl -X POST https://api.openai.com/v1/realtime/sessions \
775 -H "Authorization: Bearer $OPENAI_API_KEY" \
776 -H "Content-Type: application/json" \
777 -d '{
778 "model": "gpt-realtime",
779 "modalities": ["audio", "text"],
780 "instructions": "You are a friendly assistant."
781 }'
782```
783
784#### Response
785
786```json
787{
788 "id": "sess_001",
789 "object": "realtime.session",
790 "model": "gpt-realtime-2025-08-25",
791 "modalities": ["audio", "text"],
792 "instructions": "You are a friendly assistant.",
793 "voice": "alloy",
794 "input_audio_format": "pcm16",
795 "output_audio_format": "pcm16",
796 "input_audio_transcription": {
797 "model": "whisper-1"
798 },
799 "turn_detection": null,
800 "tools": [],
801 "tool_choice": "none",
802 "temperature": 0.7,
803 "max_response_output_tokens": 200,
804 "speed": 1.1,
805 "tracing": "auto",
806 "client_secret": {
807 "value": "ek_abc123",
808 "expires_at": 1234567890
809 }
810}
811```