realtime.d.ts 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332
  1. import { APIResource } from "../../../core/resource.js";
  2. import * as RealtimeAPI from "./realtime.js";
  3. import * as Shared from "../../shared.js";
  4. import * as SessionsAPI from "./sessions.js";
  5. import { Session as SessionsAPISession, SessionCreateParams, SessionCreateResponse, Sessions } from "./sessions.js";
  6. import * as TranscriptionSessionsAPI from "./transcription-sessions.js";
  7. import { TranscriptionSession, TranscriptionSessionCreateParams, TranscriptionSessions } from "./transcription-sessions.js";
  8. /**
  9. * @deprecated Realtime has now launched and is generally available. The old beta API is now deprecated.
  10. */
  11. export declare class Realtime extends APIResource {
  12. sessions: SessionsAPI.Sessions;
  13. transcriptionSessions: TranscriptionSessionsAPI.TranscriptionSessions;
  14. }
  15. /**
  16. * Returned when a conversation is created. Emitted right after session creation.
  17. */
  18. export interface ConversationCreatedEvent {
  19. /**
  20. * The conversation resource.
  21. */
  22. conversation: ConversationCreatedEvent.Conversation;
  23. /**
  24. * The unique ID of the server event.
  25. */
  26. event_id: string;
  27. /**
  28. * The event type, must be `conversation.created`.
  29. */
  30. type: 'conversation.created';
  31. }
  32. export declare namespace ConversationCreatedEvent {
  33. /**
  34. * The conversation resource.
  35. */
  36. interface Conversation {
  37. /**
  38. * The unique ID of the conversation.
  39. */
  40. id?: string;
  41. /**
  42. * The object type, must be `realtime.conversation`.
  43. */
  44. object?: 'realtime.conversation';
  45. }
  46. }
  47. /**
  48. * The item to add to the conversation.
  49. */
  50. export interface ConversationItem {
  51. /**
  52. * The unique ID of the item, this can be generated by the client to help manage
  53. * server-side context, but is not required because the server will generate one if
  54. * not provided.
  55. */
  56. id?: string;
  57. /**
  58. * The arguments of the function call (for `function_call` items).
  59. */
  60. arguments?: string;
  61. /**
  62. * The ID of the function call (for `function_call` and `function_call_output`
  63. * items). If passed on a `function_call_output` item, the server will check that a
  64. * `function_call` item with the same ID exists in the conversation history.
  65. */
  66. call_id?: string;
  67. /**
  68. * The content of the message, applicable for `message` items.
  69. *
  70. * - Message items of role `system` support only `input_text` content
  71. * - Message items of role `user` support `input_text` and `input_audio` content
  72. * - Message items of role `assistant` support `text` content.
  73. */
  74. content?: Array<ConversationItemContent>;
  75. /**
  76. * The name of the function being called (for `function_call` items).
  77. */
  78. name?: string;
  79. /**
  80. * Identifier for the API object being returned - always `realtime.item`.
  81. */
  82. object?: 'realtime.item';
  83. /**
  84. * The output of the function call (for `function_call_output` items).
  85. */
  86. output?: string;
  87. /**
  88. * The role of the message sender (`user`, `assistant`, `system`), only applicable
  89. * for `message` items.
  90. */
  91. role?: 'user' | 'assistant' | 'system';
  92. /**
  93. * The status of the item (`completed`, `incomplete`, `in_progress`). These have no
  94. * effect on the conversation, but are accepted for consistency with the
  95. * `conversation.item.created` event.
  96. */
  97. status?: 'completed' | 'incomplete' | 'in_progress';
  98. /**
  99. * The type of the item (`message`, `function_call`, `function_call_output`).
  100. */
  101. type?: 'message' | 'function_call' | 'function_call_output';
  102. }
  103. export interface ConversationItemContent {
  104. /**
  105. * ID of a previous conversation item to reference (for `item_reference` content
  106. * types in `response.create` events). These can reference both client and server
  107. * created items.
  108. */
  109. id?: string;
  110. /**
  111. * Base64-encoded audio bytes, used for `input_audio` content type.
  112. */
  113. audio?: string;
  114. /**
  115. * The text content, used for `input_text` and `text` content types.
  116. */
  117. text?: string;
  118. /**
  119. * The transcript of the audio, used for `input_audio` and `audio` content types.
  120. */
  121. transcript?: string;
  122. /**
  123. * The content type (`input_text`, `input_audio`, `item_reference`, `text`,
  124. * `audio`).
  125. */
  126. type?: 'input_text' | 'input_audio' | 'item_reference' | 'text' | 'audio';
  127. }
  128. /**
  129. * Add a new Item to the Conversation's context, including messages, function
  130. * calls, and function call responses. This event can be used both to populate a
  131. * "history" of the conversation and to add new items mid-stream, but has the
  132. * current limitation that it cannot populate assistant audio messages.
  133. *
  134. * If successful, the server will respond with a `conversation.item.created` event,
  135. * otherwise an `error` event will be sent.
  136. */
  137. export interface ConversationItemCreateEvent {
  138. /**
  139. * The item to add to the conversation.
  140. */
  141. item: ConversationItem;
  142. /**
  143. * The event type, must be `conversation.item.create`.
  144. */
  145. type: 'conversation.item.create';
  146. /**
  147. * Optional client-generated ID used to identify this event.
  148. */
  149. event_id?: string;
  150. /**
  151. * The ID of the preceding item after which the new item will be inserted. If not
  152. * set, the new item will be appended to the end of the conversation. If set to
  153. * `root`, the new item will be added to the beginning of the conversation. If set
  154. * to an existing ID, it allows an item to be inserted mid-conversation. If the ID
  155. * cannot be found, an error will be returned and the item will not be added.
  156. */
  157. previous_item_id?: string;
  158. }
  159. /**
  160. * Returned when a conversation item is created. There are several scenarios that
  161. * produce this event:
  162. *
  163. * - The server is generating a Response, which if successful will produce either
  164. * one or two Items, which will be of type `message` (role `assistant`) or type
  165. * `function_call`.
  166. * - The input audio buffer has been committed, either by the client or the server
  167. * (in `server_vad` mode). The server will take the content of the input audio
  168. * buffer and add it to a new user message Item.
  169. * - The client has sent a `conversation.item.create` event to add a new Item to
  170. * the Conversation.
  171. */
  172. export interface ConversationItemCreatedEvent {
  173. /**
  174. * The unique ID of the server event.
  175. */
  176. event_id: string;
  177. /**
  178. * The item to add to the conversation.
  179. */
  180. item: ConversationItem;
  181. /**
  182. * The event type, must be `conversation.item.created`.
  183. */
  184. type: 'conversation.item.created';
  185. /**
  186. * The ID of the preceding item in the Conversation context, allows the client to
  187. * understand the order of the conversation. Can be `null` if the item has no
  188. * predecessor.
  189. */
  190. previous_item_id?: string | null;
  191. }
  192. /**
  193. * Send this event when you want to remove any item from the conversation history.
  194. * The server will respond with a `conversation.item.deleted` event, unless the
  195. * item does not exist in the conversation history, in which case the server will
  196. * respond with an error.
  197. */
  198. export interface ConversationItemDeleteEvent {
  199. /**
  200. * The ID of the item to delete.
  201. */
  202. item_id: string;
  203. /**
  204. * The event type, must be `conversation.item.delete`.
  205. */
  206. type: 'conversation.item.delete';
  207. /**
  208. * Optional client-generated ID used to identify this event.
  209. */
  210. event_id?: string;
  211. }
  212. /**
  213. * Returned when an item in the conversation is deleted by the client with a
  214. * `conversation.item.delete` event. This event is used to synchronize the server's
  215. * understanding of the conversation history with the client's view.
  216. */
  217. export interface ConversationItemDeletedEvent {
  218. /**
  219. * The unique ID of the server event.
  220. */
  221. event_id: string;
  222. /**
  223. * The ID of the item that was deleted.
  224. */
  225. item_id: string;
  226. /**
  227. * The event type, must be `conversation.item.deleted`.
  228. */
  229. type: 'conversation.item.deleted';
  230. }
  231. /**
  232. * This event is the output of audio transcription for user audio written to the
  233. * user audio buffer. Transcription begins when the input audio buffer is committed
  234. * by the client or server (in `server_vad` mode). Transcription runs
  235. * asynchronously with Response creation, so this event may come before or after
  236. * the Response events.
  237. *
  238. * Realtime API models accept audio natively, and thus input transcription is a
  239. * separate process run on a separate ASR (Automatic Speech Recognition) model. The
  240. * transcript may diverge somewhat from the model's interpretation, and should be
  241. * treated as a rough guide.
  242. */
  243. export interface ConversationItemInputAudioTranscriptionCompletedEvent {
  244. /**
  245. * The index of the content part containing the audio.
  246. */
  247. content_index: number;
  248. /**
  249. * The unique ID of the server event.
  250. */
  251. event_id: string;
  252. /**
  253. * The ID of the user message item containing the audio.
  254. */
  255. item_id: string;
  256. /**
  257. * The transcribed text.
  258. */
  259. transcript: string;
  260. /**
  261. * The event type, must be `conversation.item.input_audio_transcription.completed`.
  262. */
  263. type: 'conversation.item.input_audio_transcription.completed';
  264. /**
  265. * Usage statistics for the transcription.
  266. */
  267. usage: ConversationItemInputAudioTranscriptionCompletedEvent.TranscriptTextUsageTokens | ConversationItemInputAudioTranscriptionCompletedEvent.TranscriptTextUsageDuration;
  268. /**
  269. * The log probabilities of the transcription.
  270. */
  271. logprobs?: Array<ConversationItemInputAudioTranscriptionCompletedEvent.Logprob> | null;
  272. }
  273. export declare namespace ConversationItemInputAudioTranscriptionCompletedEvent {
  274. /**
  275. * Usage statistics for models billed by token usage.
  276. */
  277. interface TranscriptTextUsageTokens {
  278. /**
  279. * Number of input tokens billed for this request.
  280. */
  281. input_tokens: number;
  282. /**
  283. * Number of output tokens generated.
  284. */
  285. output_tokens: number;
  286. /**
  287. * Total number of tokens used (input + output).
  288. */
  289. total_tokens: number;
  290. /**
  291. * The type of the usage object. Always `tokens` for this variant.
  292. */
  293. type: 'tokens';
  294. /**
  295. * Details about the input tokens billed for this request.
  296. */
  297. input_token_details?: TranscriptTextUsageTokens.InputTokenDetails;
  298. }
  299. namespace TranscriptTextUsageTokens {
  300. /**
  301. * Details about the input tokens billed for this request.
  302. */
  303. interface InputTokenDetails {
  304. /**
  305. * Number of audio tokens billed for this request.
  306. */
  307. audio_tokens?: number;
  308. /**
  309. * Number of text tokens billed for this request.
  310. */
  311. text_tokens?: number;
  312. }
  313. }
  314. /**
  315. * Usage statistics for models billed by audio input duration.
  316. */
  317. interface TranscriptTextUsageDuration {
  318. /**
  319. * Duration of the input audio in seconds.
  320. */
  321. seconds: number;
  322. /**
  323. * The type of the usage object. Always `duration` for this variant.
  324. */
  325. type: 'duration';
  326. }
  327. /**
  328. * A log probability object.
  329. */
  330. interface Logprob {
  331. /**
  332. * The token that was used to generate the log probability.
  333. */
  334. token: string;
  335. /**
  336. * The bytes that were used to generate the log probability.
  337. */
  338. bytes: Array<number>;
  339. /**
  340. * The log probability of the token.
  341. */
  342. logprob: number;
  343. }
  344. }
  345. /**
  346. * Returned when the text value of an input audio transcription content part is
  347. * updated.
  348. */
  349. export interface ConversationItemInputAudioTranscriptionDeltaEvent {
  350. /**
  351. * The unique ID of the server event.
  352. */
  353. event_id: string;
  354. /**
  355. * The ID of the item.
  356. */
  357. item_id: string;
  358. /**
  359. * The event type, must be `conversation.item.input_audio_transcription.delta`.
  360. */
  361. type: 'conversation.item.input_audio_transcription.delta';
  362. /**
  363. * The index of the content part in the item's content array.
  364. */
  365. content_index?: number;
  366. /**
  367. * The text delta.
  368. */
  369. delta?: string;
  370. /**
  371. * The log probabilities of the transcription.
  372. */
  373. logprobs?: Array<ConversationItemInputAudioTranscriptionDeltaEvent.Logprob> | null;
  374. }
  375. export declare namespace ConversationItemInputAudioTranscriptionDeltaEvent {
  376. /**
  377. * A log probability object.
  378. */
  379. interface Logprob {
  380. /**
  381. * The token that was used to generate the log probability.
  382. */
  383. token: string;
  384. /**
  385. * The bytes that were used to generate the log probability.
  386. */
  387. bytes: Array<number>;
  388. /**
  389. * The log probability of the token.
  390. */
  391. logprob: number;
  392. }
  393. }
  394. /**
  395. * Returned when input audio transcription is configured, and a transcription
  396. * request for a user message failed. These events are separate from other `error`
  397. * events so that the client can identify the related Item.
  398. */
  399. export interface ConversationItemInputAudioTranscriptionFailedEvent {
  400. /**
  401. * The index of the content part containing the audio.
  402. */
  403. content_index: number;
  404. /**
  405. * Details of the transcription error.
  406. */
  407. error: ConversationItemInputAudioTranscriptionFailedEvent.Error;
  408. /**
  409. * The unique ID of the server event.
  410. */
  411. event_id: string;
  412. /**
  413. * The ID of the user message item.
  414. */
  415. item_id: string;
  416. /**
  417. * The event type, must be `conversation.item.input_audio_transcription.failed`.
  418. */
  419. type: 'conversation.item.input_audio_transcription.failed';
  420. }
  421. export declare namespace ConversationItemInputAudioTranscriptionFailedEvent {
  422. /**
  423. * Details of the transcription error.
  424. */
  425. interface Error {
  426. /**
  427. * Error code, if any.
  428. */
  429. code?: string;
  430. /**
  431. * A human-readable error message.
  432. */
  433. message?: string;
  434. /**
  435. * Parameter related to the error, if any.
  436. */
  437. param?: string;
  438. /**
  439. * The type of error.
  440. */
  441. type?: string;
  442. }
  443. }
  444. /**
  445. * Send this event when you want to retrieve the server's representation of a
  446. * specific item in the conversation history. This is useful, for example, to
  447. * inspect user audio after noise cancellation and VAD. The server will respond
  448. * with a `conversation.item.retrieved` event, unless the item does not exist in
  449. * the conversation history, in which case the server will respond with an error.
  450. */
  451. export interface ConversationItemRetrieveEvent {
  452. /**
  453. * The ID of the item to retrieve.
  454. */
  455. item_id: string;
  456. /**
  457. * The event type, must be `conversation.item.retrieve`.
  458. */
  459. type: 'conversation.item.retrieve';
  460. /**
  461. * Optional client-generated ID used to identify this event.
  462. */
  463. event_id?: string;
  464. }
  465. /**
  466. * Send this event to truncate a previous assistant message’s audio. The server
  467. * will produce audio faster than realtime, so this event is useful when the user
  468. * interrupts to truncate audio that has already been sent to the client but not
  469. * yet played. This will synchronize the server's understanding of the audio with
  470. * the client's playback.
  471. *
  472. * Truncating audio will delete the server-side text transcript to ensure there is
  473. * not text in the context that hasn't been heard by the user.
  474. *
  475. * If successful, the server will respond with a `conversation.item.truncated`
  476. * event.
  477. */
  478. export interface ConversationItemTruncateEvent {
  479. /**
  480. * Inclusive duration up to which audio is truncated, in milliseconds. If the
  481. * audio_end_ms is greater than the actual audio duration, the server will respond
  482. * with an error.
  483. */
  484. audio_end_ms: number;
  485. /**
  486. * The index of the content part to truncate. Set this to 0.
  487. */
  488. content_index: number;
  489. /**
  490. * The ID of the assistant message item to truncate. Only assistant message items
  491. * can be truncated.
  492. */
  493. item_id: string;
  494. /**
  495. * The event type, must be `conversation.item.truncate`.
  496. */
  497. type: 'conversation.item.truncate';
  498. /**
  499. * Optional client-generated ID used to identify this event.
  500. */
  501. event_id?: string;
  502. }
  503. /**
  504. * Returned when an earlier assistant audio message item is truncated by the client
  505. * with a `conversation.item.truncate` event. This event is used to synchronize the
  506. * server's understanding of the audio with the client's playback.
  507. *
  508. * This action will truncate the audio and remove the server-side text transcript
  509. * to ensure there is no text in the context that hasn't been heard by the user.
  510. */
  511. export interface ConversationItemTruncatedEvent {
  512. /**
  513. * The duration up to which the audio was truncated, in milliseconds.
  514. */
  515. audio_end_ms: number;
  516. /**
  517. * The index of the content part that was truncated.
  518. */
  519. content_index: number;
  520. /**
  521. * The unique ID of the server event.
  522. */
  523. event_id: string;
  524. /**
  525. * The ID of the assistant message item that was truncated.
  526. */
  527. item_id: string;
  528. /**
  529. * The event type, must be `conversation.item.truncated`.
  530. */
  531. type: 'conversation.item.truncated';
  532. }
  533. /**
  534. * The item to add to the conversation.
  535. */
  536. export interface ConversationItemWithReference {
  537. /**
  538. * For an item of type (`message` | `function_call` | `function_call_output`) this
  539. * field allows the client to assign the unique ID of the item. It is not required
  540. * because the server will generate one if not provided.
  541. *
  542. * For an item of type `item_reference`, this field is required and is a reference
  543. * to any item that has previously existed in the conversation.
  544. */
  545. id?: string;
  546. /**
  547. * The arguments of the function call (for `function_call` items).
  548. */
  549. arguments?: string;
  550. /**
  551. * The ID of the function call (for `function_call` and `function_call_output`
  552. * items). If passed on a `function_call_output` item, the server will check that a
  553. * `function_call` item with the same ID exists in the conversation history.
  554. */
  555. call_id?: string;
  556. /**
  557. * The content of the message, applicable for `message` items.
  558. *
  559. * - Message items of role `system` support only `input_text` content
  560. * - Message items of role `user` support `input_text` and `input_audio` content
  561. * - Message items of role `assistant` support `text` content.
  562. */
  563. content?: Array<ConversationItemWithReference.Content>;
  564. /**
  565. * The name of the function being called (for `function_call` items).
  566. */
  567. name?: string;
  568. /**
  569. * Identifier for the API object being returned - always `realtime.item`.
  570. */
  571. object?: 'realtime.item';
  572. /**
  573. * The output of the function call (for `function_call_output` items).
  574. */
  575. output?: string;
  576. /**
  577. * The role of the message sender (`user`, `assistant`, `system`), only applicable
  578. * for `message` items.
  579. */
  580. role?: 'user' | 'assistant' | 'system';
  581. /**
  582. * The status of the item (`completed`, `incomplete`, `in_progress`). These have no
  583. * effect on the conversation, but are accepted for consistency with the
  584. * `conversation.item.created` event.
  585. */
  586. status?: 'completed' | 'incomplete' | 'in_progress';
  587. /**
  588. * The type of the item (`message`, `function_call`, `function_call_output`,
  589. * `item_reference`).
  590. */
  591. type?: 'message' | 'function_call' | 'function_call_output' | 'item_reference';
  592. }
  593. export declare namespace ConversationItemWithReference {
  594. interface Content {
  595. /**
  596. * ID of a previous conversation item to reference (for `item_reference` content
  597. * types in `response.create` events). These can reference both client and server
  598. * created items.
  599. */
  600. id?: string;
  601. /**
  602. * Base64-encoded audio bytes, used for `input_audio` content type.
  603. */
  604. audio?: string;
  605. /**
  606. * The text content, used for `input_text` and `text` content types.
  607. */
  608. text?: string;
  609. /**
  610. * The transcript of the audio, used for `input_audio` content type.
  611. */
  612. transcript?: string;
  613. /**
  614. * The content type (`input_text`, `input_audio`, `item_reference`, `text`).
  615. */
  616. type?: 'input_text' | 'input_audio' | 'item_reference' | 'text';
  617. }
  618. }
  619. /**
  620. * Returned when an error occurs, which could be a client problem or a server
  621. * problem. Most errors are recoverable and the session will stay open, we
  622. * recommend to implementors to monitor and log error messages by default.
  623. */
  624. export interface ErrorEvent {
  625. /**
  626. * Details of the error.
  627. */
  628. error: ErrorEvent.Error;
  629. /**
  630. * The unique ID of the server event.
  631. */
  632. event_id: string;
  633. /**
  634. * The event type, must be `error`.
  635. */
  636. type: 'error';
  637. }
  638. export declare namespace ErrorEvent {
  639. /**
  640. * Details of the error.
  641. */
  642. interface Error {
  643. /**
  644. * A human-readable error message.
  645. */
  646. message: string;
  647. /**
  648. * The type of error (e.g., "invalid_request_error", "server_error").
  649. */
  650. type: string;
  651. /**
  652. * Error code, if any.
  653. */
  654. code?: string | null;
  655. /**
  656. * The event_id of the client event that caused the error, if applicable.
  657. */
  658. event_id?: string | null;
  659. /**
  660. * Parameter related to the error, if any.
  661. */
  662. param?: string | null;
  663. }
  664. }
  665. /**
  666. * Send this event to append audio bytes to the input audio buffer. The audio
  667. * buffer is temporary storage you can write to and later commit. In Server VAD
  668. * mode, the audio buffer is used to detect speech and the server will decide when
  669. * to commit. When Server VAD is disabled, you must commit the audio buffer
  670. * manually.
  671. *
  672. * The client may choose how much audio to place in each event up to a maximum of
  673. * 15 MiB, for example streaming smaller chunks from the client may allow the VAD
  674. * to be more responsive. Unlike made other client events, the server will not send
  675. * a confirmation response to this event.
  676. */
  677. export interface InputAudioBufferAppendEvent {
  678. /**
  679. * Base64-encoded audio bytes. This must be in the format specified by the
  680. * `input_audio_format` field in the session configuration.
  681. */
  682. audio: string;
  683. /**
  684. * The event type, must be `input_audio_buffer.append`.
  685. */
  686. type: 'input_audio_buffer.append';
  687. /**
  688. * Optional client-generated ID used to identify this event.
  689. */
  690. event_id?: string;
  691. }
  692. /**
  693. * Send this event to clear the audio bytes in the buffer. The server will respond
  694. * with an `input_audio_buffer.cleared` event.
  695. */
  696. export interface InputAudioBufferClearEvent {
  697. /**
  698. * The event type, must be `input_audio_buffer.clear`.
  699. */
  700. type: 'input_audio_buffer.clear';
  701. /**
  702. * Optional client-generated ID used to identify this event.
  703. */
  704. event_id?: string;
  705. }
  706. /**
  707. * Returned when the input audio buffer is cleared by the client with a
  708. * `input_audio_buffer.clear` event.
  709. */
  710. export interface InputAudioBufferClearedEvent {
  711. /**
  712. * The unique ID of the server event.
  713. */
  714. event_id: string;
  715. /**
  716. * The event type, must be `input_audio_buffer.cleared`.
  717. */
  718. type: 'input_audio_buffer.cleared';
  719. }
  720. /**
  721. * Send this event to commit the user input audio buffer, which will create a new
  722. * user message item in the conversation. This event will produce an error if the
  723. * input audio buffer is empty. When in Server VAD mode, the client does not need
  724. * to send this event, the server will commit the audio buffer automatically.
  725. *
  726. * Committing the input audio buffer will trigger input audio transcription (if
  727. * enabled in session configuration), but it will not create a response from the
  728. * model. The server will respond with an `input_audio_buffer.committed` event.
  729. */
  730. export interface InputAudioBufferCommitEvent {
  731. /**
  732. * The event type, must be `input_audio_buffer.commit`.
  733. */
  734. type: 'input_audio_buffer.commit';
  735. /**
  736. * Optional client-generated ID used to identify this event.
  737. */
  738. event_id?: string;
  739. }
  740. /**
  741. * Returned when an input audio buffer is committed, either by the client or
  742. * automatically in server VAD mode. The `item_id` property is the ID of the user
  743. * message item that will be created, thus a `conversation.item.created` event will
  744. * also be sent to the client.
  745. */
  746. export interface InputAudioBufferCommittedEvent {
  747. /**
  748. * The unique ID of the server event.
  749. */
  750. event_id: string;
  751. /**
  752. * The ID of the user message item that will be created.
  753. */
  754. item_id: string;
  755. /**
  756. * The event type, must be `input_audio_buffer.committed`.
  757. */
  758. type: 'input_audio_buffer.committed';
  759. /**
  760. * The ID of the preceding item after which the new item will be inserted. Can be
  761. * `null` if the item has no predecessor.
  762. */
  763. previous_item_id?: string | null;
  764. }
  765. /**
  766. * Sent by the server when in `server_vad` mode to indicate that speech has been
  767. * detected in the audio buffer. This can happen any time audio is added to the
  768. * buffer (unless speech is already detected). The client may want to use this
  769. * event to interrupt audio playback or provide visual feedback to the user.
  770. *
  771. * The client should expect to receive a `input_audio_buffer.speech_stopped` event
  772. * when speech stops. The `item_id` property is the ID of the user message item
  773. * that will be created when speech stops and will also be included in the
  774. * `input_audio_buffer.speech_stopped` event (unless the client manually commits
  775. * the audio buffer during VAD activation).
  776. */
  777. export interface InputAudioBufferSpeechStartedEvent {
  778. /**
  779. * Milliseconds from the start of all audio written to the buffer during the
  780. * session when speech was first detected. This will correspond to the beginning of
  781. * audio sent to the model, and thus includes the `prefix_padding_ms` configured in
  782. * the Session.
  783. */
  784. audio_start_ms: number;
  785. /**
  786. * The unique ID of the server event.
  787. */
  788. event_id: string;
  789. /**
  790. * The ID of the user message item that will be created when speech stops.
  791. */
  792. item_id: string;
  793. /**
  794. * The event type, must be `input_audio_buffer.speech_started`.
  795. */
  796. type: 'input_audio_buffer.speech_started';
  797. }
  798. /**
  799. * Returned in `server_vad` mode when the server detects the end of speech in the
  800. * audio buffer. The server will also send an `conversation.item.created` event
  801. * with the user message item that is created from the audio buffer.
  802. */
  803. export interface InputAudioBufferSpeechStoppedEvent {
  804. /**
  805. * Milliseconds since the session started when speech stopped. This will correspond
  806. * to the end of audio sent to the model, and thus includes the
  807. * `min_silence_duration_ms` configured in the Session.
  808. */
  809. audio_end_ms: number;
  810. /**
  811. * The unique ID of the server event.
  812. */
  813. event_id: string;
  814. /**
  815. * The ID of the user message item that will be created.
  816. */
  817. item_id: string;
  818. /**
  819. * The event type, must be `input_audio_buffer.speech_stopped`.
  820. */
  821. type: 'input_audio_buffer.speech_stopped';
  822. }
  823. /**
  824. * Emitted at the beginning of a Response to indicate the updated rate limits. When
  825. * a Response is created some tokens will be "reserved" for the output tokens, the
  826. * rate limits shown here reflect that reservation, which is then adjusted
  827. * accordingly once the Response is completed.
  828. */
  829. export interface RateLimitsUpdatedEvent {
  830. /**
  831. * The unique ID of the server event.
  832. */
  833. event_id: string;
  834. /**
  835. * List of rate limit information.
  836. */
  837. rate_limits: Array<RateLimitsUpdatedEvent.RateLimit>;
  838. /**
  839. * The event type, must be `rate_limits.updated`.
  840. */
  841. type: 'rate_limits.updated';
  842. }
  843. export declare namespace RateLimitsUpdatedEvent {
  844. interface RateLimit {
  845. /**
  846. * The maximum allowed value for the rate limit.
  847. */
  848. limit?: number;
  849. /**
  850. * The name of the rate limit (`requests`, `tokens`).
  851. */
  852. name?: 'requests' | 'tokens';
  853. /**
  854. * The remaining value before the limit is reached.
  855. */
  856. remaining?: number;
  857. /**
  858. * Seconds until the rate limit resets.
  859. */
  860. reset_seconds?: number;
  861. }
  862. }
  863. /**
  864. * A realtime client event.
  865. */
  866. export type RealtimeClientEvent = ConversationItemCreateEvent | ConversationItemDeleteEvent | ConversationItemRetrieveEvent | ConversationItemTruncateEvent | InputAudioBufferAppendEvent | InputAudioBufferClearEvent | RealtimeClientEvent.OutputAudioBufferClear | InputAudioBufferCommitEvent | ResponseCancelEvent | ResponseCreateEvent | SessionUpdateEvent | TranscriptionSessionUpdate;
  867. export declare namespace RealtimeClientEvent {
  868. /**
  869. * **WebRTC Only:** Emit to cut off the current audio response. This will trigger
  870. * the server to stop generating audio and emit a `output_audio_buffer.cleared`
  871. * event. This event should be preceded by a `response.cancel` client event to stop
  872. * the generation of the current response.
  873. * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).
  874. */
  875. interface OutputAudioBufferClear {
  876. /**
  877. * The event type, must be `output_audio_buffer.clear`.
  878. */
  879. type: 'output_audio_buffer.clear';
  880. /**
  881. * The unique ID of the client event used for error handling.
  882. */
  883. event_id?: string;
  884. }
  885. }
  886. /**
  887. * The response resource.
  888. */
  889. export interface RealtimeResponse {
  890. /**
  891. * The unique ID of the response.
  892. */
  893. id?: string;
  894. /**
  895. * Which conversation the response is added to, determined by the `conversation`
  896. * field in the `response.create` event. If `auto`, the response will be added to
  897. * the default conversation and the value of `conversation_id` will be an id like
  898. * `conv_1234`. If `none`, the response will not be added to any conversation and
  899. * the value of `conversation_id` will be `null`. If responses are being triggered
  900. * by server VAD, the response will be added to the default conversation, thus the
  901. * `conversation_id` will be an id like `conv_1234`.
  902. */
  903. conversation_id?: string;
  904. /**
  905. * Maximum number of output tokens for a single assistant response, inclusive of
  906. * tool calls, that was used in this response.
  907. */
  908. max_output_tokens?: number | 'inf';
  909. /**
  910. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  911. * for storing additional information about the object in a structured format, and
  912. * querying for objects via API or the dashboard.
  913. *
  914. * Keys are strings with a maximum length of 64 characters. Values are strings with
  915. * a maximum length of 512 characters.
  916. */
  917. metadata?: Shared.Metadata | null;
  918. /**
  919. * The set of modalities the model used to respond. If there are multiple
  920. * modalities, the model will pick one, for example if `modalities` is
  921. * `["text", "audio"]`, the model could be responding in either text or audio.
  922. */
  923. modalities?: Array<'text' | 'audio'>;
  924. /**
  925. * The object type, must be `realtime.response`.
  926. */
  927. object?: 'realtime.response';
  928. /**
  929. * The list of output items generated by the response.
  930. */
  931. output?: Array<ConversationItem>;
  932. /**
  933. * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.
  934. */
  935. output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';
  936. /**
  937. * The final status of the response (`completed`, `cancelled`, `failed`, or
  938. * `incomplete`, `in_progress`).
  939. */
  940. status?: 'completed' | 'cancelled' | 'failed' | 'incomplete' | 'in_progress';
  941. /**
  942. * Additional details about the status.
  943. */
  944. status_details?: RealtimeResponseStatus;
  945. /**
  946. * Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.
  947. */
  948. temperature?: number;
  949. /**
  950. * Usage statistics for the Response, this will correspond to billing. A Realtime
  951. * API session will maintain a conversation context and append new Items to the
  952. * Conversation, thus output from previous turns (text and audio tokens) will
  953. * become the input for later turns.
  954. */
  955. usage?: RealtimeResponseUsage;
  956. /**
  957. * The voice the model used to respond. Current voice options are `alloy`, `ash`,
  958. * `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.
  959. */
  960. voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';
  961. }
  962. /**
  963. * Additional details about the status.
  964. */
  965. export interface RealtimeResponseStatus {
  966. /**
  967. * A description of the error that caused the response to fail, populated when the
  968. * `status` is `failed`.
  969. */
  970. error?: RealtimeResponseStatus.Error;
  971. /**
  972. * The reason the Response did not complete. For a `cancelled` Response, one of
  973. * `turn_detected` (the server VAD detected a new start of speech) or
  974. * `client_cancelled` (the client sent a cancel event). For an `incomplete`
  975. * Response, one of `max_output_tokens` or `content_filter` (the server-side safety
  976. * filter activated and cut off the response).
  977. */
  978. reason?: 'turn_detected' | 'client_cancelled' | 'max_output_tokens' | 'content_filter';
  979. /**
  980. * The type of error that caused the response to fail, corresponding with the
  981. * `status` field (`completed`, `cancelled`, `incomplete`, `failed`).
  982. */
  983. type?: 'completed' | 'cancelled' | 'incomplete' | 'failed';
  984. }
  985. export declare namespace RealtimeResponseStatus {
  986. /**
  987. * A description of the error that caused the response to fail, populated when the
  988. * `status` is `failed`.
  989. */
  990. interface Error {
  991. /**
  992. * Error code, if any.
  993. */
  994. code?: string;
  995. /**
  996. * The type of error.
  997. */
  998. type?: string;
  999. }
  1000. }
  1001. /**
  1002. * Usage statistics for the Response, this will correspond to billing. A Realtime
  1003. * API session will maintain a conversation context and append new Items to the
  1004. * Conversation, thus output from previous turns (text and audio tokens) will
  1005. * become the input for later turns.
  1006. */
  1007. export interface RealtimeResponseUsage {
  1008. /**
  1009. * Details about the input tokens used in the Response.
  1010. */
  1011. input_token_details?: RealtimeResponseUsage.InputTokenDetails;
  1012. /**
  1013. * The number of input tokens used in the Response, including text and audio
  1014. * tokens.
  1015. */
  1016. input_tokens?: number;
  1017. /**
  1018. * Details about the output tokens used in the Response.
  1019. */
  1020. output_token_details?: RealtimeResponseUsage.OutputTokenDetails;
  1021. /**
  1022. * The number of output tokens sent in the Response, including text and audio
  1023. * tokens.
  1024. */
  1025. output_tokens?: number;
  1026. /**
  1027. * The total number of tokens in the Response including input and output text and
  1028. * audio tokens.
  1029. */
  1030. total_tokens?: number;
  1031. }
  1032. export declare namespace RealtimeResponseUsage {
  1033. /**
  1034. * Details about the input tokens used in the Response.
  1035. */
  1036. interface InputTokenDetails {
  1037. /**
  1038. * The number of audio tokens used in the Response.
  1039. */
  1040. audio_tokens?: number;
  1041. /**
  1042. * The number of cached tokens used in the Response.
  1043. */
  1044. cached_tokens?: number;
  1045. /**
  1046. * The number of text tokens used in the Response.
  1047. */
  1048. text_tokens?: number;
  1049. }
  1050. /**
  1051. * Details about the output tokens used in the Response.
  1052. */
  1053. interface OutputTokenDetails {
  1054. /**
  1055. * The number of audio tokens used in the Response.
  1056. */
  1057. audio_tokens?: number;
  1058. /**
  1059. * The number of text tokens used in the Response.
  1060. */
  1061. text_tokens?: number;
  1062. }
  1063. }
  1064. /**
  1065. * A realtime server event.
  1066. */
  1067. export type RealtimeServerEvent = ConversationCreatedEvent | ConversationItemCreatedEvent | ConversationItemDeletedEvent | ConversationItemInputAudioTranscriptionCompletedEvent | ConversationItemInputAudioTranscriptionDeltaEvent | ConversationItemInputAudioTranscriptionFailedEvent | RealtimeServerEvent.ConversationItemRetrieved | ConversationItemTruncatedEvent | ErrorEvent | InputAudioBufferClearedEvent | InputAudioBufferCommittedEvent | InputAudioBufferSpeechStartedEvent | InputAudioBufferSpeechStoppedEvent | RateLimitsUpdatedEvent | ResponseAudioDeltaEvent | ResponseAudioDoneEvent | ResponseAudioTranscriptDeltaEvent | ResponseAudioTranscriptDoneEvent | ResponseContentPartAddedEvent | ResponseContentPartDoneEvent | ResponseCreatedEvent | ResponseDoneEvent | ResponseFunctionCallArgumentsDeltaEvent | ResponseFunctionCallArgumentsDoneEvent | ResponseOutputItemAddedEvent | ResponseOutputItemDoneEvent | ResponseTextDeltaEvent | ResponseTextDoneEvent | SessionCreatedEvent | SessionUpdatedEvent | TranscriptionSessionUpdatedEvent | RealtimeServerEvent.OutputAudioBufferStarted | RealtimeServerEvent.OutputAudioBufferStopped | RealtimeServerEvent.OutputAudioBufferCleared;
  1068. export declare namespace RealtimeServerEvent {
  1069. /**
  1070. * Returned when a conversation item is retrieved with
  1071. * `conversation.item.retrieve`.
  1072. */
  1073. interface ConversationItemRetrieved {
  1074. /**
  1075. * The unique ID of the server event.
  1076. */
  1077. event_id: string;
  1078. /**
  1079. * The item to add to the conversation.
  1080. */
  1081. item: RealtimeAPI.ConversationItem;
  1082. /**
  1083. * The event type, must be `conversation.item.retrieved`.
  1084. */
  1085. type: 'conversation.item.retrieved';
  1086. }
  1087. /**
  1088. * **WebRTC Only:** Emitted when the server begins streaming audio to the client.
  1089. * This event is emitted after an audio content part has been added
  1090. * (`response.content_part.added`) to the response.
  1091. * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).
  1092. */
  1093. interface OutputAudioBufferStarted {
  1094. /**
  1095. * The unique ID of the server event.
  1096. */
  1097. event_id: string;
  1098. /**
  1099. * The unique ID of the response that produced the audio.
  1100. */
  1101. response_id: string;
  1102. /**
  1103. * The event type, must be `output_audio_buffer.started`.
  1104. */
  1105. type: 'output_audio_buffer.started';
  1106. }
  1107. /**
  1108. * **WebRTC Only:** Emitted when the output audio buffer has been completely
  1109. * drained on the server, and no more audio is forthcoming. This event is emitted
  1110. * after the full response data has been sent to the client (`response.done`).
  1111. * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).
  1112. */
  1113. interface OutputAudioBufferStopped {
  1114. /**
  1115. * The unique ID of the server event.
  1116. */
  1117. event_id: string;
  1118. /**
  1119. * The unique ID of the response that produced the audio.
  1120. */
  1121. response_id: string;
  1122. /**
  1123. * The event type, must be `output_audio_buffer.stopped`.
  1124. */
  1125. type: 'output_audio_buffer.stopped';
  1126. }
  1127. /**
  1128. * **WebRTC Only:** Emitted when the output audio buffer is cleared. This happens
  1129. * either in VAD mode when the user has interrupted
  1130. * (`input_audio_buffer.speech_started`), or when the client has emitted the
  1131. * `output_audio_buffer.clear` event to manually cut off the current audio
  1132. * response.
  1133. * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).
  1134. */
  1135. interface OutputAudioBufferCleared {
  1136. /**
  1137. * The unique ID of the server event.
  1138. */
  1139. event_id: string;
  1140. /**
  1141. * The unique ID of the response that produced the audio.
  1142. */
  1143. response_id: string;
  1144. /**
  1145. * The event type, must be `output_audio_buffer.cleared`.
  1146. */
  1147. type: 'output_audio_buffer.cleared';
  1148. }
  1149. }
  1150. /**
  1151. * Returned when the model-generated audio is updated.
  1152. */
  1153. export interface ResponseAudioDeltaEvent {
  1154. /**
  1155. * The index of the content part in the item's content array.
  1156. */
  1157. content_index: number;
  1158. /**
  1159. * Base64-encoded audio data delta.
  1160. */
  1161. delta: string;
  1162. /**
  1163. * The unique ID of the server event.
  1164. */
  1165. event_id: string;
  1166. /**
  1167. * The ID of the item.
  1168. */
  1169. item_id: string;
  1170. /**
  1171. * The index of the output item in the response.
  1172. */
  1173. output_index: number;
  1174. /**
  1175. * The ID of the response.
  1176. */
  1177. response_id: string;
  1178. /**
  1179. * The event type, must be `response.audio.delta`.
  1180. */
  1181. type: 'response.audio.delta';
  1182. }
  1183. /**
  1184. * Returned when the model-generated audio is done. Also emitted when a Response is
  1185. * interrupted, incomplete, or cancelled.
  1186. */
  1187. export interface ResponseAudioDoneEvent {
  1188. /**
  1189. * The index of the content part in the item's content array.
  1190. */
  1191. content_index: number;
  1192. /**
  1193. * The unique ID of the server event.
  1194. */
  1195. event_id: string;
  1196. /**
  1197. * The ID of the item.
  1198. */
  1199. item_id: string;
  1200. /**
  1201. * The index of the output item in the response.
  1202. */
  1203. output_index: number;
  1204. /**
  1205. * The ID of the response.
  1206. */
  1207. response_id: string;
  1208. /**
  1209. * The event type, must be `response.audio.done`.
  1210. */
  1211. type: 'response.audio.done';
  1212. }
  1213. /**
  1214. * Returned when the model-generated transcription of audio output is updated.
  1215. */
  1216. export interface ResponseAudioTranscriptDeltaEvent {
  1217. /**
  1218. * The index of the content part in the item's content array.
  1219. */
  1220. content_index: number;
  1221. /**
  1222. * The transcript delta.
  1223. */
  1224. delta: string;
  1225. /**
  1226. * The unique ID of the server event.
  1227. */
  1228. event_id: string;
  1229. /**
  1230. * The ID of the item.
  1231. */
  1232. item_id: string;
  1233. /**
  1234. * The index of the output item in the response.
  1235. */
  1236. output_index: number;
  1237. /**
  1238. * The ID of the response.
  1239. */
  1240. response_id: string;
  1241. /**
  1242. * The event type, must be `response.audio_transcript.delta`.
  1243. */
  1244. type: 'response.audio_transcript.delta';
  1245. }
  1246. /**
  1247. * Returned when the model-generated transcription of audio output is done
  1248. * streaming. Also emitted when a Response is interrupted, incomplete, or
  1249. * cancelled.
  1250. */
  1251. export interface ResponseAudioTranscriptDoneEvent {
  1252. /**
  1253. * The index of the content part in the item's content array.
  1254. */
  1255. content_index: number;
  1256. /**
  1257. * The unique ID of the server event.
  1258. */
  1259. event_id: string;
  1260. /**
  1261. * The ID of the item.
  1262. */
  1263. item_id: string;
  1264. /**
  1265. * The index of the output item in the response.
  1266. */
  1267. output_index: number;
  1268. /**
  1269. * The ID of the response.
  1270. */
  1271. response_id: string;
  1272. /**
  1273. * The final transcript of the audio.
  1274. */
  1275. transcript: string;
  1276. /**
  1277. * The event type, must be `response.audio_transcript.done`.
  1278. */
  1279. type: 'response.audio_transcript.done';
  1280. }
  1281. /**
  1282. * Send this event to cancel an in-progress response. The server will respond with
  1283. * a `response.done` event with a status of `response.status=cancelled`. If there
  1284. * is no response to cancel, the server will respond with an error.
  1285. */
  1286. export interface ResponseCancelEvent {
  1287. /**
  1288. * The event type, must be `response.cancel`.
  1289. */
  1290. type: 'response.cancel';
  1291. /**
  1292. * Optional client-generated ID used to identify this event.
  1293. */
  1294. event_id?: string;
  1295. /**
  1296. * A specific response ID to cancel - if not provided, will cancel an in-progress
  1297. * response in the default conversation.
  1298. */
  1299. response_id?: string;
  1300. }
  1301. /**
  1302. * Returned when a new content part is added to an assistant message item during
  1303. * response generation.
  1304. */
  1305. export interface ResponseContentPartAddedEvent {
  1306. /**
  1307. * The index of the content part in the item's content array.
  1308. */
  1309. content_index: number;
  1310. /**
  1311. * The unique ID of the server event.
  1312. */
  1313. event_id: string;
  1314. /**
  1315. * The ID of the item to which the content part was added.
  1316. */
  1317. item_id: string;
  1318. /**
  1319. * The index of the output item in the response.
  1320. */
  1321. output_index: number;
  1322. /**
  1323. * The content part that was added.
  1324. */
  1325. part: ResponseContentPartAddedEvent.Part;
  1326. /**
  1327. * The ID of the response.
  1328. */
  1329. response_id: string;
  1330. /**
  1331. * The event type, must be `response.content_part.added`.
  1332. */
  1333. type: 'response.content_part.added';
  1334. }
  1335. export declare namespace ResponseContentPartAddedEvent {
  1336. /**
  1337. * The content part that was added.
  1338. */
  1339. interface Part {
  1340. /**
  1341. * Base64-encoded audio data (if type is "audio").
  1342. */
  1343. audio?: string;
  1344. /**
  1345. * The text content (if type is "text").
  1346. */
  1347. text?: string;
  1348. /**
  1349. * The transcript of the audio (if type is "audio").
  1350. */
  1351. transcript?: string;
  1352. /**
  1353. * The content type ("text", "audio").
  1354. */
  1355. type?: 'text' | 'audio';
  1356. }
  1357. }
  1358. /**
  1359. * Returned when a content part is done streaming in an assistant message item.
  1360. * Also emitted when a Response is interrupted, incomplete, or cancelled.
  1361. */
  1362. export interface ResponseContentPartDoneEvent {
  1363. /**
  1364. * The index of the content part in the item's content array.
  1365. */
  1366. content_index: number;
  1367. /**
  1368. * The unique ID of the server event.
  1369. */
  1370. event_id: string;
  1371. /**
  1372. * The ID of the item.
  1373. */
  1374. item_id: string;
  1375. /**
  1376. * The index of the output item in the response.
  1377. */
  1378. output_index: number;
  1379. /**
  1380. * The content part that is done.
  1381. */
  1382. part: ResponseContentPartDoneEvent.Part;
  1383. /**
  1384. * The ID of the response.
  1385. */
  1386. response_id: string;
  1387. /**
  1388. * The event type, must be `response.content_part.done`.
  1389. */
  1390. type: 'response.content_part.done';
  1391. }
  1392. export declare namespace ResponseContentPartDoneEvent {
  1393. /**
  1394. * The content part that is done.
  1395. */
  1396. interface Part {
  1397. /**
  1398. * Base64-encoded audio data (if type is "audio").
  1399. */
  1400. audio?: string;
  1401. /**
  1402. * The text content (if type is "text").
  1403. */
  1404. text?: string;
  1405. /**
  1406. * The transcript of the audio (if type is "audio").
  1407. */
  1408. transcript?: string;
  1409. /**
  1410. * The content type ("text", "audio").
  1411. */
  1412. type?: 'text' | 'audio';
  1413. }
  1414. }
  1415. /**
  1416. * This event instructs the server to create a Response, which means triggering
  1417. * model inference. When in Server VAD mode, the server will create Responses
  1418. * automatically.
  1419. *
  1420. * A Response will include at least one Item, and may have two, in which case the
  1421. * second will be a function call. These Items will be appended to the conversation
  1422. * history.
  1423. *
  1424. * The server will respond with a `response.created` event, events for Items and
  1425. * content created, and finally a `response.done` event to indicate the Response is
  1426. * complete.
  1427. *
  1428. * The `response.create` event includes inference configuration like
  1429. * `instructions`, and `temperature`. These fields will override the Session's
  1430. * configuration for this Response only.
  1431. */
  1432. export interface ResponseCreateEvent {
  1433. /**
  1434. * The event type, must be `response.create`.
  1435. */
  1436. type: 'response.create';
  1437. /**
  1438. * Optional client-generated ID used to identify this event.
  1439. */
  1440. event_id?: string;
  1441. /**
  1442. * Create a new Realtime response with these parameters
  1443. */
  1444. response?: ResponseCreateEvent.Response;
  1445. }
  1446. export declare namespace ResponseCreateEvent {
  1447. /**
  1448. * Create a new Realtime response with these parameters
  1449. */
  1450. interface Response {
  1451. /**
  1452. * Controls which conversation the response is added to. Currently supports `auto`
  1453. * and `none`, with `auto` as the default value. The `auto` value means that the
  1454. * contents of the response will be added to the default conversation. Set this to
  1455. * `none` to create an out-of-band response which will not add items to default
  1456. * conversation.
  1457. */
  1458. conversation?: (string & {}) | 'auto' | 'none';
  1459. /**
  1460. * Input items to include in the prompt for the model. Using this field creates a
  1461. * new context for this Response instead of using the default conversation. An
  1462. * empty array `[]` will clear the context for this Response. Note that this can
  1463. * include references to items from the default conversation.
  1464. */
  1465. input?: Array<RealtimeAPI.ConversationItemWithReference>;
  1466. /**
  1467. * The default system instructions (i.e. system message) prepended to model calls.
  1468. * This field allows the client to guide the model on desired responses. The model
  1469. * can be instructed on response content and format, (e.g. "be extremely succinct",
  1470. * "act friendly", "here are examples of good responses") and on audio behavior
  1471. * (e.g. "talk quickly", "inject emotion into your voice", "laugh frequently"). The
  1472. * instructions are not guaranteed to be followed by the model, but they provide
  1473. * guidance to the model on the desired behavior.
  1474. *
  1475. * Note that the server sets default instructions which will be used if this field
  1476. * is not set and are visible in the `session.created` event at the start of the
  1477. * session.
  1478. */
  1479. instructions?: string;
  1480. /**
  1481. * Maximum number of output tokens for a single assistant response, inclusive of
  1482. * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or
  1483. * `inf` for the maximum available tokens for a given model. Defaults to `inf`.
  1484. */
  1485. max_response_output_tokens?: number | 'inf';
  1486. /**
  1487. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  1488. * for storing additional information about the object in a structured format, and
  1489. * querying for objects via API or the dashboard.
  1490. *
  1491. * Keys are strings with a maximum length of 64 characters. Values are strings with
  1492. * a maximum length of 512 characters.
  1493. */
  1494. metadata?: Shared.Metadata | null;
  1495. /**
  1496. * The set of modalities the model can respond with. To disable audio, set this to
  1497. * ["text"].
  1498. */
  1499. modalities?: Array<'text' | 'audio'>;
  1500. /**
  1501. * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.
  1502. */
  1503. output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';
  1504. /**
  1505. * Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.
  1506. */
  1507. temperature?: number;
  1508. /**
  1509. * How the model chooses tools. Options are `auto`, `none`, `required`, or specify
  1510. * a function, like `{"type": "function", "function": {"name": "my_function"}}`.
  1511. */
  1512. tool_choice?: string;
  1513. /**
  1514. * Tools (functions) available to the model.
  1515. */
  1516. tools?: Array<Response.Tool>;
  1517. /**
  1518. * The voice the model uses to respond. Voice cannot be changed during the session
  1519. * once the model has responded with audio at least once. Current voice options are
  1520. * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.
  1521. */
  1522. voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';
  1523. }
  1524. namespace Response {
  1525. interface Tool {
  1526. /**
  1527. * The description of the function, including guidance on when and how to call it,
  1528. * and guidance about what to tell the user when calling (if anything).
  1529. */
  1530. description?: string;
  1531. /**
  1532. * The name of the function.
  1533. */
  1534. name?: string;
  1535. /**
  1536. * Parameters of the function in JSON Schema.
  1537. */
  1538. parameters?: unknown;
  1539. /**
  1540. * The type of the tool, i.e. `function`.
  1541. */
  1542. type?: 'function';
  1543. }
  1544. }
  1545. }
  1546. /**
  1547. * Returned when a new Response is created. The first event of response creation,
  1548. * where the response is in an initial state of `in_progress`.
  1549. */
  1550. export interface ResponseCreatedEvent {
  1551. /**
  1552. * The unique ID of the server event.
  1553. */
  1554. event_id: string;
  1555. /**
  1556. * The response resource.
  1557. */
  1558. response: RealtimeResponse;
  1559. /**
  1560. * The event type, must be `response.created`.
  1561. */
  1562. type: 'response.created';
  1563. }
  1564. /**
  1565. * Returned when a Response is done streaming. Always emitted, no matter the final
  1566. * state. The Response object included in the `response.done` event will include
  1567. * all output Items in the Response but will omit the raw audio data.
  1568. */
  1569. export interface ResponseDoneEvent {
  1570. /**
  1571. * The unique ID of the server event.
  1572. */
  1573. event_id: string;
  1574. /**
  1575. * The response resource.
  1576. */
  1577. response: RealtimeResponse;
  1578. /**
  1579. * The event type, must be `response.done`.
  1580. */
  1581. type: 'response.done';
  1582. }
  1583. /**
  1584. * Returned when the model-generated function call arguments are updated.
  1585. */
  1586. export interface ResponseFunctionCallArgumentsDeltaEvent {
  1587. /**
  1588. * The ID of the function call.
  1589. */
  1590. call_id: string;
  1591. /**
  1592. * The arguments delta as a JSON string.
  1593. */
  1594. delta: string;
  1595. /**
  1596. * The unique ID of the server event.
  1597. */
  1598. event_id: string;
  1599. /**
  1600. * The ID of the function call item.
  1601. */
  1602. item_id: string;
  1603. /**
  1604. * The index of the output item in the response.
  1605. */
  1606. output_index: number;
  1607. /**
  1608. * The ID of the response.
  1609. */
  1610. response_id: string;
  1611. /**
  1612. * The event type, must be `response.function_call_arguments.delta`.
  1613. */
  1614. type: 'response.function_call_arguments.delta';
  1615. }
  1616. /**
  1617. * Returned when the model-generated function call arguments are done streaming.
  1618. * Also emitted when a Response is interrupted, incomplete, or cancelled.
  1619. */
  1620. export interface ResponseFunctionCallArgumentsDoneEvent {
  1621. /**
  1622. * The final arguments as a JSON string.
  1623. */
  1624. arguments: string;
  1625. /**
  1626. * The ID of the function call.
  1627. */
  1628. call_id: string;
  1629. /**
  1630. * The unique ID of the server event.
  1631. */
  1632. event_id: string;
  1633. /**
  1634. * The ID of the function call item.
  1635. */
  1636. item_id: string;
  1637. /**
  1638. * The index of the output item in the response.
  1639. */
  1640. output_index: number;
  1641. /**
  1642. * The ID of the response.
  1643. */
  1644. response_id: string;
  1645. /**
  1646. * The event type, must be `response.function_call_arguments.done`.
  1647. */
  1648. type: 'response.function_call_arguments.done';
  1649. }
  1650. /**
  1651. * Returned when a new Item is created during Response generation.
  1652. */
  1653. export interface ResponseOutputItemAddedEvent {
  1654. /**
  1655. * The unique ID of the server event.
  1656. */
  1657. event_id: string;
  1658. /**
  1659. * The item to add to the conversation.
  1660. */
  1661. item: ConversationItem;
  1662. /**
  1663. * The index of the output item in the Response.
  1664. */
  1665. output_index: number;
  1666. /**
  1667. * The ID of the Response to which the item belongs.
  1668. */
  1669. response_id: string;
  1670. /**
  1671. * The event type, must be `response.output_item.added`.
  1672. */
  1673. type: 'response.output_item.added';
  1674. }
  1675. /**
  1676. * Returned when an Item is done streaming. Also emitted when a Response is
  1677. * interrupted, incomplete, or cancelled.
  1678. */
  1679. export interface ResponseOutputItemDoneEvent {
  1680. /**
  1681. * The unique ID of the server event.
  1682. */
  1683. event_id: string;
  1684. /**
  1685. * The item to add to the conversation.
  1686. */
  1687. item: ConversationItem;
  1688. /**
  1689. * The index of the output item in the Response.
  1690. */
  1691. output_index: number;
  1692. /**
  1693. * The ID of the Response to which the item belongs.
  1694. */
  1695. response_id: string;
  1696. /**
  1697. * The event type, must be `response.output_item.done`.
  1698. */
  1699. type: 'response.output_item.done';
  1700. }
  1701. /**
  1702. * Returned when the text value of a "text" content part is updated.
  1703. */
  1704. export interface ResponseTextDeltaEvent {
  1705. /**
  1706. * The index of the content part in the item's content array.
  1707. */
  1708. content_index: number;
  1709. /**
  1710. * The text delta.
  1711. */
  1712. delta: string;
  1713. /**
  1714. * The unique ID of the server event.
  1715. */
  1716. event_id: string;
  1717. /**
  1718. * The ID of the item.
  1719. */
  1720. item_id: string;
  1721. /**
  1722. * The index of the output item in the response.
  1723. */
  1724. output_index: number;
  1725. /**
  1726. * The ID of the response.
  1727. */
  1728. response_id: string;
  1729. /**
  1730. * The event type, must be `response.text.delta`.
  1731. */
  1732. type: 'response.text.delta';
  1733. }
  1734. /**
  1735. * Returned when the text value of a "text" content part is done streaming. Also
  1736. * emitted when a Response is interrupted, incomplete, or cancelled.
  1737. */
  1738. export interface ResponseTextDoneEvent {
  1739. /**
  1740. * The index of the content part in the item's content array.
  1741. */
  1742. content_index: number;
  1743. /**
  1744. * The unique ID of the server event.
  1745. */
  1746. event_id: string;
  1747. /**
  1748. * The ID of the item.
  1749. */
  1750. item_id: string;
  1751. /**
  1752. * The index of the output item in the response.
  1753. */
  1754. output_index: number;
  1755. /**
  1756. * The ID of the response.
  1757. */
  1758. response_id: string;
  1759. /**
  1760. * The final text content.
  1761. */
  1762. text: string;
  1763. /**
  1764. * The event type, must be `response.text.done`.
  1765. */
  1766. type: 'response.text.done';
  1767. }
  1768. /**
  1769. * Returned when a Session is created. Emitted automatically when a new connection
  1770. * is established as the first server event. This event will contain the default
  1771. * Session configuration.
  1772. */
  1773. export interface SessionCreatedEvent {
  1774. /**
  1775. * The unique ID of the server event.
  1776. */
  1777. event_id: string;
  1778. /**
  1779. * Realtime session object configuration.
  1780. */
  1781. session: SessionsAPI.Session;
  1782. /**
  1783. * The event type, must be `session.created`.
  1784. */
  1785. type: 'session.created';
  1786. }
  1787. /**
  1788. * Send this event to update the session’s default configuration. The client may
  1789. * send this event at any time to update any field, except for `voice`. However,
  1790. * note that once a session has been initialized with a particular `model`, it
  1791. * can’t be changed to another model using `session.update`.
  1792. *
  1793. * When the server receives a `session.update`, it will respond with a
  1794. * `session.updated` event showing the full, effective configuration. Only the
  1795. * fields that are present are updated. To clear a field like `instructions`, pass
  1796. * an empty string.
  1797. */
  1798. export interface SessionUpdateEvent {
  1799. /**
  1800. * Realtime session object configuration.
  1801. */
  1802. session: SessionUpdateEvent.Session;
  1803. /**
  1804. * The event type, must be `session.update`.
  1805. */
  1806. type: 'session.update';
  1807. /**
  1808. * Optional client-generated ID used to identify this event.
  1809. */
  1810. event_id?: string;
  1811. }
  1812. export declare namespace SessionUpdateEvent {
  1813. /**
  1814. * Realtime session object configuration.
  1815. */
  1816. interface Session {
  1817. /**
  1818. * Configuration options for the generated client secret.
  1819. */
  1820. client_secret?: Session.ClientSecret;
  1821. /**
  1822. * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For
  1823. * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel
  1824. * (mono), and little-endian byte order.
  1825. */
  1826. input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';
  1827. /**
  1828. * Configuration for input audio noise reduction. This can be set to `null` to turn
  1829. * off. Noise reduction filters audio added to the input audio buffer before it is
  1830. * sent to VAD and the model. Filtering the audio can improve VAD and turn
  1831. * detection accuracy (reducing false positives) and model performance by improving
  1832. * perception of the input audio.
  1833. */
  1834. input_audio_noise_reduction?: Session.InputAudioNoiseReduction;
  1835. /**
  1836. * Configuration for input audio transcription, defaults to off and can be set to
  1837. * `null` to turn off once on. Input audio transcription is not native to the
  1838. * model, since the model consumes audio directly. Transcription runs
  1839. * asynchronously through
  1840. * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)
  1841. * and should be treated as guidance of input audio content rather than precisely
  1842. * what the model heard. The client can optionally set the language and prompt for
  1843. * transcription, these offer additional guidance to the transcription service.
  1844. */
  1845. input_audio_transcription?: Session.InputAudioTranscription;
  1846. /**
  1847. * The default system instructions (i.e. system message) prepended to model calls.
  1848. * This field allows the client to guide the model on desired responses. The model
  1849. * can be instructed on response content and format, (e.g. "be extremely succinct",
  1850. * "act friendly", "here are examples of good responses") and on audio behavior
  1851. * (e.g. "talk quickly", "inject emotion into your voice", "laugh frequently"). The
  1852. * instructions are not guaranteed to be followed by the model, but they provide
  1853. * guidance to the model on the desired behavior.
  1854. *
  1855. * Note that the server sets default instructions which will be used if this field
  1856. * is not set and are visible in the `session.created` event at the start of the
  1857. * session.
  1858. */
  1859. instructions?: string;
  1860. /**
  1861. * Maximum number of output tokens for a single assistant response, inclusive of
  1862. * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or
  1863. * `inf` for the maximum available tokens for a given model. Defaults to `inf`.
  1864. */
  1865. max_response_output_tokens?: number | 'inf';
  1866. /**
  1867. * The set of modalities the model can respond with. To disable audio, set this to
  1868. * ["text"].
  1869. */
  1870. modalities?: Array<'text' | 'audio'>;
  1871. /**
  1872. * The Realtime model used for this session.
  1873. */
  1874. model?: 'gpt-4o-realtime-preview' | 'gpt-4o-realtime-preview-2024-10-01' | 'gpt-4o-realtime-preview-2024-12-17' | 'gpt-4o-realtime-preview-2025-06-03' | 'gpt-4o-mini-realtime-preview' | 'gpt-4o-mini-realtime-preview-2024-12-17';
  1875. /**
  1876. * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.
  1877. * For `pcm16`, output audio is sampled at a rate of 24kHz.
  1878. */
  1879. output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';
  1880. /**
  1881. * The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the
  1882. * minimum speed. 1.5 is the maximum speed. This value can only be changed in
  1883. * between model turns, not while a response is in progress.
  1884. */
  1885. speed?: number;
  1886. /**
  1887. * Sampling temperature for the model, limited to [0.6, 1.2]. For audio models a
  1888. * temperature of 0.8 is highly recommended for best performance.
  1889. */
  1890. temperature?: number;
  1891. /**
  1892. * How the model chooses tools. Options are `auto`, `none`, `required`, or specify
  1893. * a function.
  1894. */
  1895. tool_choice?: string;
  1896. /**
  1897. * Tools (functions) available to the model.
  1898. */
  1899. tools?: Array<Session.Tool>;
  1900. /**
  1901. * Configuration options for tracing. Set to null to disable tracing. Once tracing
  1902. * is enabled for a session, the configuration cannot be modified.
  1903. *
  1904. * `auto` will create a trace for the session with default values for the workflow
  1905. * name, group id, and metadata.
  1906. */
  1907. tracing?: 'auto' | Session.TracingConfiguration;
  1908. /**
  1909. * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be
  1910. * set to `null` to turn off, in which case the client must manually trigger model
  1911. * response. Server VAD means that the model will detect the start and end of
  1912. * speech based on audio volume and respond at the end of user speech. Semantic VAD
  1913. * is more advanced and uses a turn detection model (in conjunction with VAD) to
  1914. * semantically estimate whether the user has finished speaking, then dynamically
  1915. * sets a timeout based on this probability. For example, if user audio trails off
  1916. * with "uhhm", the model will score a low probability of turn end and wait longer
  1917. * for the user to continue speaking. This can be useful for more natural
  1918. * conversations, but may have a higher latency.
  1919. */
  1920. turn_detection?: Session.TurnDetection;
  1921. /**
  1922. * The voice the model uses to respond. Voice cannot be changed during the session
  1923. * once the model has responded with audio at least once. Current voice options are
  1924. * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.
  1925. */
  1926. voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';
  1927. }
  1928. namespace Session {
  1929. /**
  1930. * Configuration options for the generated client secret.
  1931. */
  1932. interface ClientSecret {
  1933. /**
  1934. * Configuration for the ephemeral token expiration.
  1935. */
  1936. expires_after?: ClientSecret.ExpiresAfter;
  1937. }
  1938. namespace ClientSecret {
  1939. /**
  1940. * Configuration for the ephemeral token expiration.
  1941. */
  1942. interface ExpiresAfter {
  1943. /**
  1944. * The anchor point for the ephemeral token expiration. Only `created_at` is
  1945. * currently supported.
  1946. */
  1947. anchor: 'created_at';
  1948. /**
  1949. * The number of seconds from the anchor point to the expiration. Select a value
  1950. * between `10` and `7200`.
  1951. */
  1952. seconds?: number;
  1953. }
  1954. }
  1955. /**
  1956. * Configuration for input audio noise reduction. This can be set to `null` to turn
  1957. * off. Noise reduction filters audio added to the input audio buffer before it is
  1958. * sent to VAD and the model. Filtering the audio can improve VAD and turn
  1959. * detection accuracy (reducing false positives) and model performance by improving
  1960. * perception of the input audio.
  1961. */
  1962. interface InputAudioNoiseReduction {
  1963. /**
  1964. * Type of noise reduction. `near_field` is for close-talking microphones such as
  1965. * headphones, `far_field` is for far-field microphones such as laptop or
  1966. * conference room microphones.
  1967. */
  1968. type?: 'near_field' | 'far_field';
  1969. }
  1970. /**
  1971. * Configuration for input audio transcription, defaults to off and can be set to
  1972. * `null` to turn off once on. Input audio transcription is not native to the
  1973. * model, since the model consumes audio directly. Transcription runs
  1974. * asynchronously through
  1975. * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)
  1976. * and should be treated as guidance of input audio content rather than precisely
  1977. * what the model heard. The client can optionally set the language and prompt for
  1978. * transcription, these offer additional guidance to the transcription service.
  1979. */
  1980. interface InputAudioTranscription {
  1981. /**
  1982. * The language of the input audio. Supplying the input language in
  1983. * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)
  1984. * format will improve accuracy and latency.
  1985. */
  1986. language?: string;
  1987. /**
  1988. * The model to use for transcription, current options are `gpt-4o-transcribe`,
  1989. * `gpt-4o-mini-transcribe`, and `whisper-1`.
  1990. */
  1991. model?: string;
  1992. /**
  1993. * An optional text to guide the model's style or continue a previous audio
  1994. * segment. For `whisper-1`, the
  1995. * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).
  1996. * For `gpt-4o-transcribe` models, the prompt is a free text string, for example
  1997. * "expect words related to technology".
  1998. */
  1999. prompt?: string;
  2000. }
  2001. interface Tool {
  2002. /**
  2003. * The description of the function, including guidance on when and how to call it,
  2004. * and guidance about what to tell the user when calling (if anything).
  2005. */
  2006. description?: string;
  2007. /**
  2008. * The name of the function.
  2009. */
  2010. name?: string;
  2011. /**
  2012. * Parameters of the function in JSON Schema.
  2013. */
  2014. parameters?: unknown;
  2015. /**
  2016. * The type of the tool, i.e. `function`.
  2017. */
  2018. type?: 'function';
  2019. }
  2020. /**
  2021. * Granular configuration for tracing.
  2022. */
  2023. interface TracingConfiguration {
  2024. /**
  2025. * The group id to attach to this trace to enable filtering and grouping in the
  2026. * traces dashboard.
  2027. */
  2028. group_id?: string;
  2029. /**
  2030. * The arbitrary metadata to attach to this trace to enable filtering in the traces
  2031. * dashboard.
  2032. */
  2033. metadata?: unknown;
  2034. /**
  2035. * The name of the workflow to attach to this trace. This is used to name the trace
  2036. * in the traces dashboard.
  2037. */
  2038. workflow_name?: string;
  2039. }
  2040. /**
  2041. * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be
  2042. * set to `null` to turn off, in which case the client must manually trigger model
  2043. * response. Server VAD means that the model will detect the start and end of
  2044. * speech based on audio volume and respond at the end of user speech. Semantic VAD
  2045. * is more advanced and uses a turn detection model (in conjunction with VAD) to
  2046. * semantically estimate whether the user has finished speaking, then dynamically
  2047. * sets a timeout based on this probability. For example, if user audio trails off
  2048. * with "uhhm", the model will score a low probability of turn end and wait longer
  2049. * for the user to continue speaking. This can be useful for more natural
  2050. * conversations, but may have a higher latency.
  2051. */
  2052. interface TurnDetection {
  2053. /**
  2054. * Whether or not to automatically generate a response when a VAD stop event
  2055. * occurs.
  2056. */
  2057. create_response?: boolean;
  2058. /**
  2059. * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`
  2060. * will wait longer for the user to continue speaking, `high` will respond more
  2061. * quickly. `auto` is the default and is equivalent to `medium`.
  2062. */
  2063. eagerness?: 'low' | 'medium' | 'high' | 'auto';
  2064. /**
  2065. * Whether or not to automatically interrupt any ongoing response with output to
  2066. * the default conversation (i.e. `conversation` of `auto`) when a VAD start event
  2067. * occurs.
  2068. */
  2069. interrupt_response?: boolean;
  2070. /**
  2071. * Used only for `server_vad` mode. Amount of audio to include before the VAD
  2072. * detected speech (in milliseconds). Defaults to 300ms.
  2073. */
  2074. prefix_padding_ms?: number;
  2075. /**
  2076. * Used only for `server_vad` mode. Duration of silence to detect speech stop (in
  2077. * milliseconds). Defaults to 500ms. With shorter values the model will respond
  2078. * more quickly, but may jump in on short pauses from the user.
  2079. */
  2080. silence_duration_ms?: number;
  2081. /**
  2082. * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this
  2083. * defaults to 0.5. A higher threshold will require louder audio to activate the
  2084. * model, and thus might perform better in noisy environments.
  2085. */
  2086. threshold?: number;
  2087. /**
  2088. * Type of turn detection.
  2089. */
  2090. type?: 'server_vad' | 'semantic_vad';
  2091. }
  2092. }
  2093. }
  2094. /**
  2095. * Returned when a session is updated with a `session.update` event, unless there
  2096. * is an error.
  2097. */
  2098. export interface SessionUpdatedEvent {
  2099. /**
  2100. * The unique ID of the server event.
  2101. */
  2102. event_id: string;
  2103. /**
  2104. * Realtime session object configuration.
  2105. */
  2106. session: SessionsAPI.Session;
  2107. /**
  2108. * The event type, must be `session.updated`.
  2109. */
  2110. type: 'session.updated';
  2111. }
  2112. /**
  2113. * Send this event to update a transcription session.
  2114. */
  2115. export interface TranscriptionSessionUpdate {
  2116. /**
  2117. * Realtime transcription session object configuration.
  2118. */
  2119. session: TranscriptionSessionUpdate.Session;
  2120. /**
  2121. * The event type, must be `transcription_session.update`.
  2122. */
  2123. type: 'transcription_session.update';
  2124. /**
  2125. * Optional client-generated ID used to identify this event.
  2126. */
  2127. event_id?: string;
  2128. }
  2129. export declare namespace TranscriptionSessionUpdate {
  2130. /**
  2131. * Realtime transcription session object configuration.
  2132. */
  2133. interface Session {
  2134. /**
  2135. * Configuration options for the generated client secret.
  2136. */
  2137. client_secret?: Session.ClientSecret;
  2138. /**
  2139. * The set of items to include in the transcription. Current available items are:
  2140. *
  2141. * - `item.input_audio_transcription.logprobs`
  2142. */
  2143. include?: Array<string>;
  2144. /**
  2145. * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For
  2146. * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel
  2147. * (mono), and little-endian byte order.
  2148. */
  2149. input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';
  2150. /**
  2151. * Configuration for input audio noise reduction. This can be set to `null` to turn
  2152. * off. Noise reduction filters audio added to the input audio buffer before it is
  2153. * sent to VAD and the model. Filtering the audio can improve VAD and turn
  2154. * detection accuracy (reducing false positives) and model performance by improving
  2155. * perception of the input audio.
  2156. */
  2157. input_audio_noise_reduction?: Session.InputAudioNoiseReduction;
  2158. /**
  2159. * Configuration for input audio transcription. The client can optionally set the
  2160. * language and prompt for transcription, these offer additional guidance to the
  2161. * transcription service.
  2162. */
  2163. input_audio_transcription?: Session.InputAudioTranscription;
  2164. /**
  2165. * The set of modalities the model can respond with. To disable audio, set this to
  2166. * ["text"].
  2167. */
  2168. modalities?: Array<'text' | 'audio'>;
  2169. /**
  2170. * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be
  2171. * set to `null` to turn off, in which case the client must manually trigger model
  2172. * response. Server VAD means that the model will detect the start and end of
  2173. * speech based on audio volume and respond at the end of user speech. Semantic VAD
  2174. * is more advanced and uses a turn detection model (in conjunction with VAD) to
  2175. * semantically estimate whether the user has finished speaking, then dynamically
  2176. * sets a timeout based on this probability. For example, if user audio trails off
  2177. * with "uhhm", the model will score a low probability of turn end and wait longer
  2178. * for the user to continue speaking. This can be useful for more natural
  2179. * conversations, but may have a higher latency.
  2180. */
  2181. turn_detection?: Session.TurnDetection;
  2182. }
  2183. namespace Session {
  2184. /**
  2185. * Configuration options for the generated client secret.
  2186. */
  2187. interface ClientSecret {
  2188. /**
  2189. * Configuration for the ephemeral token expiration.
  2190. */
  2191. expires_at?: ClientSecret.ExpiresAt;
  2192. }
  2193. namespace ClientSecret {
  2194. /**
  2195. * Configuration for the ephemeral token expiration.
  2196. */
  2197. interface ExpiresAt {
  2198. /**
  2199. * The anchor point for the ephemeral token expiration. Only `created_at` is
  2200. * currently supported.
  2201. */
  2202. anchor?: 'created_at';
  2203. /**
  2204. * The number of seconds from the anchor point to the expiration. Select a value
  2205. * between `10` and `7200`.
  2206. */
  2207. seconds?: number;
  2208. }
  2209. }
  2210. /**
  2211. * Configuration for input audio noise reduction. This can be set to `null` to turn
  2212. * off. Noise reduction filters audio added to the input audio buffer before it is
  2213. * sent to VAD and the model. Filtering the audio can improve VAD and turn
  2214. * detection accuracy (reducing false positives) and model performance by improving
  2215. * perception of the input audio.
  2216. */
  2217. interface InputAudioNoiseReduction {
  2218. /**
  2219. * Type of noise reduction. `near_field` is for close-talking microphones such as
  2220. * headphones, `far_field` is for far-field microphones such as laptop or
  2221. * conference room microphones.
  2222. */
  2223. type?: 'near_field' | 'far_field';
  2224. }
  2225. /**
  2226. * Configuration for input audio transcription. The client can optionally set the
  2227. * language and prompt for transcription, these offer additional guidance to the
  2228. * transcription service.
  2229. */
  2230. interface InputAudioTranscription {
  2231. /**
  2232. * The language of the input audio. Supplying the input language in
  2233. * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)
  2234. * format will improve accuracy and latency.
  2235. */
  2236. language?: string;
  2237. /**
  2238. * The model to use for transcription, current options are `gpt-4o-transcribe`,
  2239. * `gpt-4o-mini-transcribe`, and `whisper-1`.
  2240. */
  2241. model?: 'gpt-4o-transcribe' | 'gpt-4o-mini-transcribe' | 'whisper-1';
  2242. /**
  2243. * An optional text to guide the model's style or continue a previous audio
  2244. * segment. For `whisper-1`, the
  2245. * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).
  2246. * For `gpt-4o-transcribe` models, the prompt is a free text string, for example
  2247. * "expect words related to technology".
  2248. */
  2249. prompt?: string;
  2250. }
  2251. /**
  2252. * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be
  2253. * set to `null` to turn off, in which case the client must manually trigger model
  2254. * response. Server VAD means that the model will detect the start and end of
  2255. * speech based on audio volume and respond at the end of user speech. Semantic VAD
  2256. * is more advanced and uses a turn detection model (in conjunction with VAD) to
  2257. * semantically estimate whether the user has finished speaking, then dynamically
  2258. * sets a timeout based on this probability. For example, if user audio trails off
  2259. * with "uhhm", the model will score a low probability of turn end and wait longer
  2260. * for the user to continue speaking. This can be useful for more natural
  2261. * conversations, but may have a higher latency.
  2262. */
  2263. interface TurnDetection {
  2264. /**
  2265. * Whether or not to automatically generate a response when a VAD stop event
  2266. * occurs. Not available for transcription sessions.
  2267. */
  2268. create_response?: boolean;
  2269. /**
  2270. * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`
  2271. * will wait longer for the user to continue speaking, `high` will respond more
  2272. * quickly. `auto` is the default and is equivalent to `medium`.
  2273. */
  2274. eagerness?: 'low' | 'medium' | 'high' | 'auto';
  2275. /**
  2276. * Whether or not to automatically interrupt any ongoing response with output to
  2277. * the default conversation (i.e. `conversation` of `auto`) when a VAD start event
  2278. * occurs. Not available for transcription sessions.
  2279. */
  2280. interrupt_response?: boolean;
  2281. /**
  2282. * Used only for `server_vad` mode. Amount of audio to include before the VAD
  2283. * detected speech (in milliseconds). Defaults to 300ms.
  2284. */
  2285. prefix_padding_ms?: number;
  2286. /**
  2287. * Used only for `server_vad` mode. Duration of silence to detect speech stop (in
  2288. * milliseconds). Defaults to 500ms. With shorter values the model will respond
  2289. * more quickly, but may jump in on short pauses from the user.
  2290. */
  2291. silence_duration_ms?: number;
  2292. /**
  2293. * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this
  2294. * defaults to 0.5. A higher threshold will require louder audio to activate the
  2295. * model, and thus might perform better in noisy environments.
  2296. */
  2297. threshold?: number;
  2298. /**
  2299. * Type of turn detection.
  2300. */
  2301. type?: 'server_vad' | 'semantic_vad';
  2302. }
  2303. }
  2304. }
  2305. /**
  2306. * Returned when a transcription session is updated with a
  2307. * `transcription_session.update` event, unless there is an error.
  2308. */
  2309. export interface TranscriptionSessionUpdatedEvent {
  2310. /**
  2311. * The unique ID of the server event.
  2312. */
  2313. event_id: string;
  2314. /**
  2315. * A new Realtime transcription session configuration.
  2316. *
  2317. * When a session is created on the server via REST API, the session object also
  2318. * contains an ephemeral key. Default TTL for keys is 10 minutes. This property is
  2319. * not present when a session is updated via the WebSocket API.
  2320. */
  2321. session: TranscriptionSessionsAPI.TranscriptionSession;
  2322. /**
  2323. * The event type, must be `transcription_session.updated`.
  2324. */
  2325. type: 'transcription_session.updated';
  2326. }
  2327. export declare namespace Realtime {
  2328. export { type ConversationCreatedEvent as ConversationCreatedEvent, type ConversationItem as ConversationItem, type ConversationItemContent as ConversationItemContent, type ConversationItemCreateEvent as ConversationItemCreateEvent, type ConversationItemCreatedEvent as ConversationItemCreatedEvent, type ConversationItemDeleteEvent as ConversationItemDeleteEvent, type ConversationItemDeletedEvent as ConversationItemDeletedEvent, type ConversationItemInputAudioTranscriptionCompletedEvent as ConversationItemInputAudioTranscriptionCompletedEvent, type ConversationItemInputAudioTranscriptionDeltaEvent as ConversationItemInputAudioTranscriptionDeltaEvent, type ConversationItemInputAudioTranscriptionFailedEvent as ConversationItemInputAudioTranscriptionFailedEvent, type ConversationItemRetrieveEvent as ConversationItemRetrieveEvent, type ConversationItemTruncateEvent as ConversationItemTruncateEvent, type ConversationItemTruncatedEvent as ConversationItemTruncatedEvent, type ConversationItemWithReference as ConversationItemWithReference, type ErrorEvent as ErrorEvent, type InputAudioBufferAppendEvent as InputAudioBufferAppendEvent, type InputAudioBufferClearEvent as InputAudioBufferClearEvent, type InputAudioBufferClearedEvent as InputAudioBufferClearedEvent, type InputAudioBufferCommitEvent as InputAudioBufferCommitEvent, type InputAudioBufferCommittedEvent as InputAudioBufferCommittedEvent, type InputAudioBufferSpeechStartedEvent as InputAudioBufferSpeechStartedEvent, type InputAudioBufferSpeechStoppedEvent as InputAudioBufferSpeechStoppedEvent, type RateLimitsUpdatedEvent as RateLimitsUpdatedEvent, type RealtimeClientEvent as RealtimeClientEvent, type RealtimeResponse as RealtimeResponse, type RealtimeResponseStatus as RealtimeResponseStatus, type RealtimeResponseUsage as RealtimeResponseUsage, type RealtimeServerEvent as RealtimeServerEvent, type ResponseAudioDeltaEvent as ResponseAudioDeltaEvent, type ResponseAudioDoneEvent as ResponseAudioDoneEvent, type ResponseAudioTranscriptDeltaEvent as ResponseAudioTranscriptDeltaEvent, type ResponseAudioTranscriptDoneEvent as ResponseAudioTranscriptDoneEvent, type ResponseCancelEvent as ResponseCancelEvent, type ResponseContentPartAddedEvent as ResponseContentPartAddedEvent, type ResponseContentPartDoneEvent as ResponseContentPartDoneEvent, type ResponseCreateEvent as ResponseCreateEvent, type ResponseCreatedEvent as ResponseCreatedEvent, type ResponseDoneEvent as ResponseDoneEvent, type ResponseFunctionCallArgumentsDeltaEvent as ResponseFunctionCallArgumentsDeltaEvent, type ResponseFunctionCallArgumentsDoneEvent as ResponseFunctionCallArgumentsDoneEvent, type ResponseOutputItemAddedEvent as ResponseOutputItemAddedEvent, type ResponseOutputItemDoneEvent as ResponseOutputItemDoneEvent, type ResponseTextDeltaEvent as ResponseTextDeltaEvent, type ResponseTextDoneEvent as ResponseTextDoneEvent, type SessionCreatedEvent as SessionCreatedEvent, type SessionUpdateEvent as SessionUpdateEvent, type SessionUpdatedEvent as SessionUpdatedEvent, type TranscriptionSessionUpdate as TranscriptionSessionUpdate, type TranscriptionSessionUpdatedEvent as TranscriptionSessionUpdatedEvent, };
  2329. export { Sessions as Sessions, type SessionsAPISession as Session, type SessionCreateResponse as SessionCreateResponse, type SessionCreateParams as SessionCreateParams, };
  2330. export { TranscriptionSessions as TranscriptionSessions, type TranscriptionSession as TranscriptionSession, type TranscriptionSessionCreateParams as TranscriptionSessionCreateParams, };
  2331. }
  2332. //# sourceMappingURL=realtime.d.ts.map