resources/realtime/subresources/sessions/methods/create/index.md +0 −768 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`
80
81 Reference to a prompt template and its variables.
82 [Learn more](/docs/guides/text?api-mode=responses#reusable-prompts).
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]`
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 }`
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 - `ResponseInputImage object { detail, type, file_id, image_url }`
111
112 An image input to the model. Learn about [image inputs](/docs/guides/vision).
113
114 - `detail: "low" or "high" or "auto" or "original"`
115
116 The detail level of the image to be sent to the model. One of `high`, `low`, `auto`, or `original`. Defaults to `auto`.
117
118 - `"low"`
119
120 - `"high"`
121
122 - `"auto"`
123
124 - `"original"`
125
126 - `type: "input_image"`
127
128 The type of the input item. Always `input_image`.
129
130 - `"input_image"`
131
132 - `file_id: optional string`
133
134 The ID of the file to be sent to the model.
135
136 - `image_url: optional string`
137
138 The URL of the image to be sent to the model. A fully qualified URL or base64 encoded image in a data URL.
139
140 - `ResponseInputFile object { type, detail, file_data, 3 more }`
141
142 A file input to the model.
143
144 - `type: "input_file"`
145
146 The type of the input item. Always `input_file`.
147
148 - `"input_file"`
149
150 - `detail: optional "low" or "high"`
151
152 The detail level of the file to be sent to the model. Use `low` for the default rendering behavior, or `high` to render the file at higher quality. Defaults to `low`.
153
154 - `"low"`
155
156 - `"high"`
157
158 - `file_data: optional string`
159
160 The content of the file to be sent to the model.
161
162 - `file_id: optional string`
163
164 The ID of the file to be sent to the model.
165
166 - `file_url: optional string`
167
168 The URL of the file to be sent to the model.
169
170 - `filename: optional string`
171
172 The name of the file to be sent to the model.
173
174 - `version: optional string`
175
176 Optional version of the prompt template.
177
178- `speed: optional number`
179
180 The speed of the model's spoken response. 1.0 is the default speed. 0.25 is
181 the minimum speed. 1.5 is the maximum speed. This value can only be changed
182 in between model turns, not while a response is in progress.
183
184- `temperature: optional number`
185
186 Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.
187
188- `tool_choice: optional string`
189
190 How the model chooses tools. Options are `auto`, `none`, `required`, or
191 specify a function.
192
193- `tools: optional array of object { description, name, parameters, type }`
194
195 Tools (functions) available to the model.
196
197 - `description: optional string`
198
199 The description of the function, including guidance on when and how
200 to call it, and guidance about what to tell the user when calling
201 (if anything).
202
203 - `name: optional string`
204
205 The name of the function.
206
207 - `parameters: optional unknown`
208
209 Parameters of the function in JSON Schema.
210
211 - `type: optional "function"`
212
213 The type of the tool, i.e. `function`.
214
215 - `"function"`
216
217- `tracing: optional "auto" or object { group_id, metadata, workflow_name }`
218
219 Configuration options for tracing. Set to null to disable tracing. Once
220 tracing is enabled for a session, the configuration cannot be modified.
221
222 `auto` will create a trace for the session with default values for the
223 workflow name, group id, and metadata.
224
225 - `"auto"`
226
227 Default tracing mode for the session.
228
229 - `"auto"`
230
231 - `TracingConfiguration object { group_id, metadata, workflow_name }`
232
233 Granular configuration for tracing.
234
235 - `group_id: optional string`
236
237 The group id to attach to this trace to enable filtering and
238 grouping in the traces dashboard.
239
240 - `metadata: optional unknown`
241
242 The arbitrary metadata to attach to this trace to enable
243 filtering in the traces dashboard.
244
245 - `workflow_name: optional string`
246
247 The name of the workflow to attach to this trace. This is used to
248 name the trace in the traces dashboard.
249
250- `truncation: optional RealtimeTruncation`
251
252 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.
253
254 Clients can configure truncation behavior to truncate with a lower max token limit, which is an effective way to control token usage and cost.
255
256 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.
257
258 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.
259
260 - `"auto" or "disabled"`
261
262 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.
263
264 - `"auto"`
265
266 - `"disabled"`
267
268 - `RetentionRatioTruncation object { retention_ratio, type, token_limits }`
269
270 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.
271
272 - `retention_ratio: number`
273
274 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.
275
276 - `type: "retention_ratio"`
277
278 Use retention ratio truncation.
279
280 - `"retention_ratio"`
281
282 - `token_limits: optional object { post_instructions }`
283
284 Optional custom token limits for this truncation strategy. If not provided, the model's default token limits will be used.
285
286 - `post_instructions: optional number`
287
288 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.
289
290- `turn_detection: optional object { prefix_padding_ms, silence_duration_ms, threshold, type }`
291
292 Configuration for turn detection. Can be set to `null` to turn off. Server
293 VAD means that the model will detect the start and end of speech based on
294 audio volume and respond at the end of user speech.
295
296 - `prefix_padding_ms: optional number`
297
298 Amount of audio to include before the VAD detected speech (in
299 milliseconds). Defaults to 300ms.
300
301 - `silence_duration_ms: optional number`
302
303 Duration of silence to detect speech stop (in milliseconds). Defaults
304 to 500ms. With shorter values the model will respond more quickly,
305 but may jump in on short pauses from the user.
306
307 - `threshold: optional number`
308
309 Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A
310 higher threshold will require louder audio to activate the model, and
311 thus might perform better in noisy environments.
312
313 - `type: optional string`
314
315 Type of turn detection, only `server_vad` is currently supported.
316
317- `voice: optional string or "alloy" or "ash" or "ballad" or 7 more or object { id }`
318
319 The voice the model uses to respond. Supported built-in voices are
320 `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, `verse`,
321 `marin`, and `cedar`. You may also provide a custom voice object with an
322 `id`, for example `{ "id": "voice_1234" }`. Voice cannot be changed during
323 the session once the model has responded with audio at least once.
324
325 - `string`
326
327 - `"alloy" or "ash" or "ballad" or 7 more`
328
329 - `"alloy"`
330
331 - `"ash"`
332
333 - `"ballad"`
334
335 - `"coral"`
336
337 - `"echo"`
338
339 - `"sage"`
340
341 - `"shimmer"`
342
343 - `"verse"`
344
345 - `"marin"`
346
347 - `"cedar"`
348
349 - `ID object { id }`
350
351 Custom voice reference.
352
353 - `id: string`
354
355 The custom voice ID, e.g. `voice_1234`.
356
357### Returns
358
359- `id: optional string`
360
361 Unique identifier for the session that looks like `sess_1234567890abcdef`.
362
363- `audio: optional object { input, output }`
364
365 Configuration for input and output audio for the session.
366
367 - `input: optional object { format, noise_reduction, transcription, turn_detection }`
368
369 - `format: optional RealtimeAudioFormats`
370
371 The PCM audio format. Only a 24kHz sample rate is supported.
372
373 - `PCMAudioFormat object { rate, type }`
374
375 The PCM audio format. Only a 24kHz sample rate is supported.
376
377 - `rate: optional 24000`
378
379 The sample rate of the audio. Always `24000`.
380
381 - `24000`
382
383 - `type: optional "audio/pcm"`
384
385 The audio format. Always `audio/pcm`.
386
387 - `"audio/pcm"`
388
389 - `PCMUAudioFormat object { type }`
390
391 The G.711 μ-law format.
392
393 - `type: optional "audio/pcmu"`
394
395 The audio format. Always `audio/pcmu`.
396
397 - `"audio/pcmu"`
398
399 - `PCMAAudioFormat object { type }`
400
401 The G.711 A-law format.
402
403 - `type: optional "audio/pcma"`
404
405 The audio format. Always `audio/pcma`.
406
407 - `"audio/pcma"`
408
409 - `noise_reduction: optional object { type }`
410
411 Configuration for input audio noise reduction.
412
413 - `type: optional NoiseReductionType`
414
415 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.
416
417 - `"near_field"`
418
419 - `"far_field"`
420
421 - `transcription: optional object { language, model, prompt }`
422
423 Configuration for input audio transcription.
424
425 - `language: optional string`
426
427 The language of the input audio.
428
429 - `model: optional string or "whisper-1" or "gpt-4o-mini-transcribe" or "gpt-4o-mini-transcribe-2025-12-15" or 3 more`
430
431 The model used for transcription. Current options are `whisper-1`, `gpt-4o-mini-transcribe`, `gpt-4o-mini-transcribe-2025-12-15`, `gpt-4o-transcribe`, `gpt-4o-transcribe-diarize`, and `gpt-realtime-whisper`.
432
433 - `string`
434
435 - `"whisper-1" or "gpt-4o-mini-transcribe" or "gpt-4o-mini-transcribe-2025-12-15" or 3 more`
436
437 The model used for transcription. Current options are `whisper-1`, `gpt-4o-mini-transcribe`, `gpt-4o-mini-transcribe-2025-12-15`, `gpt-4o-transcribe`, `gpt-4o-transcribe-diarize`, and `gpt-realtime-whisper`.
438
439 - `"whisper-1"`
440
441 - `"gpt-4o-mini-transcribe"`
442
443 - `"gpt-4o-mini-transcribe-2025-12-15"`
444
445 - `"gpt-4o-transcribe"`
446
447 - `"gpt-4o-transcribe-diarize"`
448
449 - `"gpt-realtime-whisper"`
450
451 - `prompt: optional string`
452
453 The prompt configured for input audio transcription, when present.
454
455 - `turn_detection: optional object { prefix_padding_ms, silence_duration_ms, threshold, type }`
456
457 Configuration for turn detection.
458
459 - `prefix_padding_ms: optional number`
460
461 - `silence_duration_ms: optional number`
462
463 - `threshold: optional number`
464
465 - `type: optional string`
466
467 Type of turn detection, only `server_vad` is currently supported.
468
469 - `output: optional object { format, speed, voice }`
470
471 - `format: optional RealtimeAudioFormats`
472
473 The PCM audio format. Only a 24kHz sample rate is supported.
474
475 - `speed: optional number`
476
477 - `voice: optional string or "alloy" or "ash" or "ballad" or 7 more`
478
479 - `string`
480
481 - `"alloy" or "ash" or "ballad" or 7 more`
482
483 - `"alloy"`
484
485 - `"ash"`
486
487 - `"ballad"`
488
489 - `"coral"`
490
491 - `"echo"`
492
493 - `"sage"`
494
495 - `"shimmer"`
496
497 - `"verse"`
498
499 - `"marin"`
500
501 - `"cedar"`
502
503- `expires_at: optional number`
504
505 Expiration timestamp for the session, in seconds since epoch.
506
507- `include: optional array of "item.input_audio_transcription.logprobs"`
508
509 Additional fields to include in server outputs.
510
511 - `item.input_audio_transcription.logprobs`: Include logprobs for input audio transcription.
512
513 - `"item.input_audio_transcription.logprobs"`
514
515- `instructions: optional string`
516
517 The default system instructions (i.e. system message) prepended to model
518 calls. This field allows the client to guide the model on desired
519 responses. The model can be instructed on response content and format,
520 (e.g. "be extremely succinct", "act friendly", "here are examples of good
521 responses") and on audio behavior (e.g. "talk quickly", "inject emotion
522 into your voice", "laugh frequently"). The instructions are not guaranteed
523 to be followed by the model, but they provide guidance to the model on the
524 desired behavior.
525
526 Note that the server sets default instructions which will be used if this
527 field is not set and are visible in the `session.created` event at the
528 start of the session.
529
530- `max_output_tokens: optional number or "inf"`
531
532 Maximum number of output tokens for a single assistant response,
533 inclusive of tool calls. Provide an integer between 1 and 4096 to
534 limit output tokens, or `inf` for the maximum available tokens for a
535 given model. Defaults to `inf`.
536
537 - `number`
538
539 - `"inf"`
540
541 - `"inf"`
542
543- `model: optional string`
544
545 The Realtime model used for this session.
546
547- `object: optional string`
548
549 The object type. Always `realtime.session`.
550
551- `output_modalities: optional array of "text" or "audio"`
552
553 The set of modalities the model can respond with. To disable audio,
554 set this to ["text"].
555
556 - `"text"`
557
558 - `"audio"`
559
560- `tool_choice: optional string`
561
562 How the model chooses tools. Options are `auto`, `none`, `required`, or
563 specify a function.
564
565- `tools: optional array of RealtimeFunctionTool`
566
567 Tools (functions) available to the model.
568
569 - `description: optional string`
570
571 The description of the function, including guidance on when and how
572 to call it, and guidance about what to tell the user when calling
573 (if anything).
574
575 - `name: optional string`
576
577 The name of the function.
578
579 - `parameters: optional unknown`
580
581 Parameters of the function in JSON Schema.
582
583 - `type: optional "function"`
584
585 The type of the tool, i.e. `function`.
586
587 - `"function"`
588
589- `tracing: optional "auto" or object { group_id, metadata, workflow_name }`
590
591 Configuration options for tracing. Set to null to disable tracing. Once
592 tracing is enabled for a session, the configuration cannot be modified.
593
594 `auto` will create a trace for the session with default values for the
595 workflow name, group id, and metadata.
596
597 - `"auto"`
598
599 Default tracing mode for the session.
600
601 - `"auto"`
602
603 - `TracingConfiguration object { group_id, metadata, workflow_name }`
604
605 Granular configuration for tracing.
606
607 - `group_id: optional string`
608
609 The group id to attach to this trace to enable filtering and
610 grouping in the traces dashboard.
611
612 - `metadata: optional unknown`
613
614 The arbitrary metadata to attach to this trace to enable
615 filtering in the traces dashboard.
616
617 - `workflow_name: optional string`
618
619 The name of the workflow to attach to this trace. This is used to
620 name the trace in the traces dashboard.
621
622- `turn_detection: optional object { prefix_padding_ms, silence_duration_ms, threshold, type }`
623
624 Configuration for turn detection. Can be set to `null` to turn off. Server
625 VAD means that the model will detect the start and end of speech based on
626 audio volume and respond at the end of user speech.
627
628 - `prefix_padding_ms: optional number`
629
630 Amount of audio to include before the VAD detected speech (in
631 milliseconds). Defaults to 300ms.
632
633 - `silence_duration_ms: optional number`
634
635 Duration of silence to detect speech stop (in milliseconds). Defaults
636 to 500ms. With shorter values the model will respond more quickly,
637 but may jump in on short pauses from the user.
638
639 - `threshold: optional number`
640
641 Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A
642 higher threshold will require louder audio to activate the model, and
643 thus might perform better in noisy environments.
644
645 - `type: optional string`
646
647 Type of turn detection, only `server_vad` is currently supported.
648
649### Example
650
651```http
652curl https://api.openai.com/v1/realtime/sessions \
653 -H 'Content-Type: application/json' \
654 -H "Authorization: Bearer $OPENAI_API_KEY" \
655 -d '{
656 "client_secret": {
657 "expires_at": 0,
658 "value": "value"
659 }
660 }'
661```
662
663#### Response
664
665```json
666{
667 "id": "id",
668 "audio": {
669 "input": {
670 "format": {
671 "rate": 24000,
672 "type": "audio/pcm"
673 },
674 "noise_reduction": {
675 "type": "near_field"
676 },
677 "transcription": {
678 "language": "language",
679 "model": "string",
680 "prompt": "prompt"
681 },
682 "turn_detection": {
683 "prefix_padding_ms": 0,
684 "silence_duration_ms": 0,
685 "threshold": 0,
686 "type": "type"
687 }
688 },
689 "output": {
690 "format": {
691 "rate": 24000,
692 "type": "audio/pcm"
693 },
694 "speed": 0,
695 "voice": "ash"
696 }
697 },
698 "expires_at": 0,
699 "include": [
700 "item.input_audio_transcription.logprobs"
701 ],
702 "instructions": "instructions",
703 "max_output_tokens": 0,
704 "model": "model",
705 "object": "object",
706 "output_modalities": [
707 "text"
708 ],
709 "tool_choice": "tool_choice",
710 "tools": [
711 {
712 "description": "description",
713 "name": "name",
714 "parameters": {},
715 "type": "function"
716 }
717 ],
718 "tracing": "auto",
719 "turn_detection": {
720 "prefix_padding_ms": 0,
721 "silence_duration_ms": 0,
722 "threshold": 0,
723 "type": "type"
724 }
725}
726```
727
728### Example
729
730```http
731curl -X POST https://api.openai.com/v1/realtime/sessions \
732 -H "Authorization: Bearer $OPENAI_API_KEY" \
733 -H "Content-Type: application/json" \
734 -d '{
735 "model": "gpt-realtime",
736 "modalities": ["audio", "text"],
737 "instructions": "You are a friendly assistant."
738 }'
739```
740
741#### Response
742
743```json
744{
745 "id": "sess_001",
746 "object": "realtime.session",
747 "model": "gpt-realtime-2025-08-25",
748 "modalities": ["audio", "text"],
749 "instructions": "You are a friendly assistant.",
750 "voice": "alloy",
751 "input_audio_format": "pcm16",
752 "output_audio_format": "pcm16",
753 "input_audio_transcription": {
754 "model": "whisper-1"
755 },
756 "turn_detection": null,
757 "tools": [],
758 "tool_choice": "none",
759 "temperature": 0.7,
760 "max_response_output_tokens": 200,
761 "speed": 1.1,
762 "tracing": "auto",
763 "client_secret": {
764 "value": "ek_abc123",
765 "expires_at": 1234567890
766 }
767}
768```