@perplexity-ai/perplexity_ai 0.32.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/client.d.mts +2 -2
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +2 -2
  5. package/client.d.ts.map +1 -1
  6. package/client.js +10 -2
  7. package/client.js.map +1 -1
  8. package/client.mjs +10 -2
  9. package/client.mjs.map +1 -1
  10. package/package.json +1 -1
  11. package/resources/index.d.mts +1 -1
  12. package/resources/index.d.mts.map +1 -1
  13. package/resources/index.d.ts +1 -1
  14. package/resources/index.d.ts.map +1 -1
  15. package/resources/index.js +1 -1
  16. package/resources/index.js.map +1 -1
  17. package/resources/index.mjs +1 -1
  18. package/resources/index.mjs.map +1 -1
  19. package/resources/responses/files.d.mts +26 -0
  20. package/resources/responses/files.d.mts.map +1 -0
  21. package/resources/responses/files.d.ts +26 -0
  22. package/resources/responses/files.d.ts.map +1 -0
  23. package/resources/responses/files.js +30 -0
  24. package/resources/responses/files.js.map +1 -0
  25. package/resources/responses/files.mjs +26 -0
  26. package/resources/responses/files.mjs.map +1 -0
  27. package/resources/responses/index.d.mts +3 -0
  28. package/resources/responses/index.d.mts.map +1 -0
  29. package/resources/responses/index.d.ts +3 -0
  30. package/resources/responses/index.d.ts.map +1 -0
  31. package/resources/responses/index.js +9 -0
  32. package/resources/responses/index.js.map +1 -0
  33. package/resources/responses/index.mjs +4 -0
  34. package/resources/responses/index.mjs.map +1 -0
  35. package/resources/responses/responses.d.mts +1096 -0
  36. package/resources/responses/responses.d.mts.map +1 -0
  37. package/resources/responses/responses.d.ts +1096 -0
  38. package/resources/responses/responses.d.ts.map +1 -0
  39. package/resources/responses/responses.js +38 -0
  40. package/resources/responses/responses.js.map +1 -0
  41. package/resources/responses/responses.mjs +33 -0
  42. package/resources/responses/responses.mjs.map +1 -0
  43. package/resources/responses.d.mts +1 -927
  44. package/resources/responses.d.mts.map +1 -1
  45. package/resources/responses.d.ts +1 -927
  46. package/resources/responses.d.ts.map +1 -1
  47. package/resources/responses.js +2 -26
  48. package/resources/responses.js.map +1 -1
  49. package/resources/responses.mjs +1 -24
  50. package/resources/responses.mjs.map +1 -1
  51. package/src/client.ts +18 -6
  52. package/src/resources/index.ts +3 -1
  53. package/src/resources/responses/files.ts +42 -0
  54. package/src/resources/responses/index.ts +23 -0
  55. package/src/resources/responses/responses.ts +1468 -0
  56. package/src/resources/responses.ts +1 -1259
  57. package/src/version.ts +1 -1
  58. package/version.d.mts +1 -1
  59. package/version.d.ts +1 -1
  60. package/version.js +1 -1
  61. package/version.mjs +1 -1
@@ -0,0 +1,1468 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../../core/resource';
4
+ import * as ResponsesAPI from './responses';
5
+ import * as Shared from '../shared';
6
+ import * as FilesAPI from './files';
7
+ import { FileContentParams, Files } from './files';
8
+ import { APIPromise } from '../../core/api-promise';
9
+ import { Stream } from '../../core/streaming';
10
+ import { RequestOptions } from '../../internal/request-options';
11
+ import { addOutputText } from '../../lib/add-output-text';
12
+ import { path } from '../../internal/utils/path';
13
+
14
+ export class Responses extends APIResource {
15
+ files: FilesAPI.Files = new FilesAPI.Files(this._client);
16
+
17
+ /**
18
+ * Generate a response for the provided input with optional web search and
19
+ * reasoning.
20
+ */
21
+ create(
22
+ body: ResponseCreateParamsNonStreaming,
23
+ options?: RequestOptions,
24
+ ): APIPromise<ResponseCreateResponse>;
25
+ create(
26
+ body: ResponseCreateParamsStreaming,
27
+ options?: RequestOptions,
28
+ ): APIPromise<Stream<ResponseStreamChunk>>;
29
+ create(
30
+ body: ResponseCreateParamsBase,
31
+ options?: RequestOptions,
32
+ ): APIPromise<Stream<ResponseStreamChunk> | ResponseCreateResponse>;
33
+ create(
34
+ body: ResponseCreateParams,
35
+ options?: RequestOptions,
36
+ ): APIPromise<ResponseCreateResponse> | APIPromise<Stream<ResponseStreamChunk>> {
37
+ const promise = this._client.post('/v1/responses', { body, ...options, stream: body.stream ?? false });
38
+
39
+ // For non-streaming responses, automatically add output_text property
40
+ if (!body.stream) {
41
+ return (promise as APIPromise<ResponseCreateResponse>)._thenUnwrap((rsp) => {
42
+ if ('object' in rsp && rsp.object === 'response') {
43
+ addOutputText(rsp as ResponseCreateResponse);
44
+ }
45
+ return rsp;
46
+ }) as APIPromise<ResponseCreateResponse>;
47
+ }
48
+
49
+ return promise as APIPromise<Stream<ResponseStreamChunk>>;
50
+ }
51
+
52
+ /**
53
+ * Retrieve a response by its ID. Use this to poll the status of background tasks.
54
+ */
55
+ retrieve(responseID: string, options?: RequestOptions): APIPromise<ResponseRetrieveResponse> {
56
+ return this._client.get(path`/v1/responses/${responseID}`, options);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Text annotation (e.g., URL citation)
62
+ */
63
+ export interface Annotation {
64
+ end_index?: number;
65
+
66
+ start_index?: number;
67
+
68
+ title?: string;
69
+
70
+ type?: string;
71
+
72
+ url?: string;
73
+ }
74
+
75
+ export interface ContentPart {
76
+ text: string;
77
+
78
+ /**
79
+ * Type of a content part
80
+ */
81
+ type: 'output_text';
82
+
83
+ annotations?: Array<Annotation>;
84
+ }
85
+
86
+ export interface ErrorInfo {
87
+ message: string;
88
+
89
+ code?: string;
90
+
91
+ type?: string;
92
+ }
93
+
94
+ export interface FunctionCallOutputItem {
95
+ id: string;
96
+
97
+ /**
98
+ * JSON string of arguments
99
+ */
100
+ arguments: string;
101
+
102
+ /**
103
+ * Correlates with function_call_output input
104
+ */
105
+ call_id: string;
106
+
107
+ name: string;
108
+
109
+ /**
110
+ * Status of a response or output item
111
+ */
112
+ status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
113
+
114
+ type: 'function_call';
115
+
116
+ /**
117
+ * Base64-encoded opaque signature for thinking models
118
+ */
119
+ thought_signature?: string;
120
+ }
121
+
122
+ export interface FunctionTool {
123
+ /**
124
+ * The name of the function
125
+ */
126
+ name: string;
127
+
128
+ type: 'function';
129
+
130
+ /**
131
+ * A description of what the function does
132
+ */
133
+ description?: string;
134
+
135
+ /**
136
+ * JSON Schema defining the function's parameters
137
+ */
138
+ parameters?: { [key: string]: unknown };
139
+
140
+ /**
141
+ * Whether to enable strict schema validation
142
+ */
143
+ strict?: boolean;
144
+ }
145
+
146
+ export type InputItem =
147
+ | InputItem.InputMessage
148
+ | InputItem.FunctionCallOutputInput
149
+ | InputItem.FunctionCallInput;
150
+
151
+ export namespace InputItem {
152
+ export interface InputMessage {
153
+ /**
154
+ * Message content - either a string or array of content parts
155
+ */
156
+ content: string | Array<InputMessage.ContentPartArray>;
157
+
158
+ role: 'user' | 'assistant' | 'system' | 'developer';
159
+
160
+ type: 'message';
161
+ }
162
+
163
+ export namespace InputMessage {
164
+ export interface ContentPartArray {
165
+ type: 'input_text' | 'input_image';
166
+
167
+ image_url?: string;
168
+
169
+ text?: string;
170
+ }
171
+ }
172
+
173
+ export interface FunctionCallOutputInput {
174
+ /**
175
+ * The call_id from function_call output
176
+ */
177
+ call_id: string;
178
+
179
+ /**
180
+ * Function result (JSON string)
181
+ */
182
+ output: string;
183
+
184
+ type: 'function_call_output';
185
+
186
+ /**
187
+ * Function name (required by some providers)
188
+ */
189
+ name?: string;
190
+
191
+ /**
192
+ * Base64-encoded signature from function_call
193
+ */
194
+ thought_signature?: string;
195
+ }
196
+
197
+ export interface FunctionCallInput {
198
+ /**
199
+ * Function arguments (JSON string)
200
+ */
201
+ arguments: string;
202
+
203
+ /**
204
+ * The call_id that correlates with function_call_output
205
+ */
206
+ call_id: string;
207
+
208
+ /**
209
+ * The function name
210
+ */
211
+ name: string;
212
+
213
+ type: 'function_call';
214
+
215
+ /**
216
+ * Base64-encoded signature for thinking models
217
+ */
218
+ thought_signature?: string;
219
+ }
220
+ }
221
+
222
+ /**
223
+ * One item in the response output: an assistant message, retrieved tool results,
224
+ * or a record of a tool call.
225
+ */
226
+ export type OutputItem =
227
+ | OutputItem.MessageOutputItem
228
+ | OutputItem.SearchResultsOutputItem
229
+ | OutputItem.FetchURLResultsOutputItem
230
+ | FunctionCallOutputItem
231
+ | OutputItem.McpListToolsOutputItem
232
+ | OutputItem.McpCallOutputItem;
233
+
234
+ export namespace OutputItem {
235
+ export interface MessageOutputItem {
236
+ id: string;
237
+
238
+ content: Array<ResponsesAPI.ContentPart>;
239
+
240
+ /**
241
+ * Role in a message
242
+ */
243
+ role: 'assistant';
244
+
245
+ /**
246
+ * Status of a response or output item
247
+ */
248
+ status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
249
+
250
+ type: 'message';
251
+ }
252
+
253
+ export interface SearchResultsOutputItem {
254
+ results: Array<Shared.SearchResult>;
255
+
256
+ type: 'search_results';
257
+
258
+ queries?: Array<string>;
259
+ }
260
+
261
+ export interface FetchURLResultsOutputItem {
262
+ contents: Array<FetchURLResultsOutputItem.Content>;
263
+
264
+ type: 'fetch_url_results';
265
+ }
266
+
267
+ export namespace FetchURLResultsOutputItem {
268
+ /**
269
+ * Content fetched from a URL
270
+ */
271
+ export interface Content {
272
+ /**
273
+ * The fetched content snippet
274
+ */
275
+ snippet: string;
276
+
277
+ /**
278
+ * The title of the page
279
+ */
280
+ title: string;
281
+
282
+ /**
283
+ * The URL from which content was fetched
284
+ */
285
+ url: string;
286
+ }
287
+ }
288
+
289
+ /**
290
+ * Tools discovered on one external MCP server at boot. Matches OpenAI's
291
+ * mcp_list_tools item.
292
+ */
293
+ export interface McpListToolsOutputItem {
294
+ id: string;
295
+
296
+ server_label: string;
297
+
298
+ tools: Array<McpListToolsOutputItem.Tool>;
299
+
300
+ type: 'mcp_list_tools';
301
+
302
+ error?: string;
303
+ }
304
+
305
+ export namespace McpListToolsOutputItem {
306
+ /**
307
+ * One tool discovered on a remote MCP server.
308
+ */
309
+ export interface Tool {
310
+ /**
311
+ * The server's JSON Schema for the tool, passed through unmodified.
312
+ */
313
+ input_schema: { [key: string]: unknown };
314
+
315
+ name: string;
316
+
317
+ description?: string;
318
+ }
319
+ }
320
+
321
+ /**
322
+ * One tool call executed against an external MCP server, modeled on OpenAI's
323
+ * mcp_call item.
324
+ */
325
+ export interface McpCallOutputItem {
326
+ id: string;
327
+
328
+ /**
329
+ * JSON-encoded arguments the model passed.
330
+ */
331
+ arguments: string;
332
+
333
+ name: string;
334
+
335
+ server_label: string;
336
+
337
+ type: 'mcp_call';
338
+
339
+ /**
340
+ * The failure string when the call failed (also returned to the model in-band);
341
+ * null on success, matching OpenAI's mcp_call.
342
+ */
343
+ error?: string | null;
344
+
345
+ /**
346
+ * Tool output text; empty when the call failed.
347
+ */
348
+ output?: string;
349
+ }
350
+ }
351
+
352
+ /**
353
+ * Metadata for a file shared from a response sandbox via the share_file tool.
354
+ */
355
+ export interface ResponseFile {
356
+ /**
357
+ * File identifier, scoped to the parent response.
358
+ */
359
+ id: string;
360
+
361
+ /**
362
+ * Size of the file in bytes.
363
+ */
364
+ bytes: number;
365
+
366
+ /**
367
+ * Unix timestamp (seconds) when the file was produced.
368
+ */
369
+ created_at: number;
370
+
371
+ /**
372
+ * Original filename set by the share_file tool call.
373
+ */
374
+ filename: string;
375
+
376
+ /**
377
+ * Object type. Always `file`.
378
+ */
379
+ object: 'file';
380
+ }
381
+
382
+ export interface ResponseFileList {
383
+ data: Array<ResponseFile>;
384
+
385
+ /**
386
+ * Object type. Always `list`.
387
+ */
388
+ object: 'list';
389
+ }
390
+
391
+ /**
392
+ * SSE stream event. Discriminate by the `type` field:
393
+ *
394
+ * - `response.created`: Initial response object
395
+ * - `response.in_progress`: Response processing started
396
+ * - `response.completed`: Final response with output
397
+ * - `response.failed`: Error occurred
398
+ * - `response.output_item.added`: New output item started
399
+ * - `response.output_item.done`: Output item completed
400
+ * - `response.output_text.delta`: Streaming text delta
401
+ * - `response.output_text.done`: Final text content
402
+ * - `response.reasoning.started`: Reasoning phase started
403
+ * - `response.reasoning.search_queries`: Search queries issued
404
+ * - `response.reasoning.search_results`: Search results received
405
+ * - `response.reasoning.fetch_url_queries`: URL fetch queries issued
406
+ * - `response.reasoning.fetch_url_results`: URL fetch results received
407
+ * - `response.reasoning.stopped`: Reasoning phase complete
408
+ */
409
+ export type ResponseStreamChunk =
410
+ | ResponseStreamChunk.ResponseCreatedEvent
411
+ | ResponseStreamChunk.ResponseInProgressEvent
412
+ | ResponseStreamChunk.ResponseCompletedEvent
413
+ | ResponseStreamChunk.ResponseFailedEvent
414
+ | ResponseStreamChunk.OutputItemAddedEvent
415
+ | ResponseStreamChunk.OutputItemDoneEvent
416
+ | ResponseStreamChunk.TextDeltaEvent
417
+ | ResponseStreamChunk.TextDoneEvent
418
+ | ResponseStreamChunk.ReasoningStartedEvent
419
+ | ResponseStreamChunk.SearchQueriesEvent
420
+ | ResponseStreamChunk.SearchResultsEvent
421
+ | ResponseStreamChunk.FetchURLQueriesEvent
422
+ | ResponseStreamChunk.FetchURLResultsEvent
423
+ | ResponseStreamChunk.ReasoningStoppedEvent;
424
+
425
+ export namespace ResponseStreamChunk {
426
+ /**
427
+ * Response created event (type: "response.created"). Contains the initial response
428
+ * object.
429
+ */
430
+ export interface ResponseCreatedEvent {
431
+ /**
432
+ * Monotonically increasing sequence number for event ordering
433
+ */
434
+ sequence_number: number;
435
+
436
+ /**
437
+ * SSE event type discriminator (always "response.created")
438
+ */
439
+ type: 'response.created';
440
+
441
+ /**
442
+ * Non-streaming response returned when stream is false
443
+ */
444
+ response?: ResponseCreatedEvent.Response;
445
+ }
446
+
447
+ export namespace ResponseCreatedEvent {
448
+ /**
449
+ * Non-streaming response returned when stream is false
450
+ */
451
+ export interface Response {
452
+ id: string;
453
+
454
+ created_at: number;
455
+
456
+ model: string;
457
+
458
+ /**
459
+ * Object type in API responses
460
+ */
461
+ object: 'response';
462
+
463
+ output: Array<ResponsesAPI.OutputItem>;
464
+
465
+ /**
466
+ * Status of a response or output item
467
+ */
468
+ status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
469
+
470
+ /**
471
+ * Whether the response was created in background mode.
472
+ */
473
+ background?: boolean;
474
+
475
+ error?: ResponsesAPI.ErrorInfo;
476
+
477
+ usage?: ResponsesAPI.ResponsesUsage;
478
+ }
479
+ }
480
+
481
+ /**
482
+ * Response in progress event (type: "response.in_progress"). Emitted when response
483
+ * processing has started.
484
+ */
485
+ export interface ResponseInProgressEvent {
486
+ /**
487
+ * Monotonically increasing sequence number for event ordering
488
+ */
489
+ sequence_number: number;
490
+
491
+ /**
492
+ * SSE event type discriminator (always "response.in_progress")
493
+ */
494
+ type: 'response.in_progress';
495
+
496
+ /**
497
+ * Non-streaming response returned when stream is false
498
+ */
499
+ response?: ResponseInProgressEvent.Response;
500
+ }
501
+
502
+ export namespace ResponseInProgressEvent {
503
+ /**
504
+ * Non-streaming response returned when stream is false
505
+ */
506
+ export interface Response {
507
+ id: string;
508
+
509
+ created_at: number;
510
+
511
+ model: string;
512
+
513
+ /**
514
+ * Object type in API responses
515
+ */
516
+ object: 'response';
517
+
518
+ output: Array<ResponsesAPI.OutputItem>;
519
+
520
+ /**
521
+ * Status of a response or output item
522
+ */
523
+ status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
524
+
525
+ /**
526
+ * Whether the response was created in background mode.
527
+ */
528
+ background?: boolean;
529
+
530
+ error?: ResponsesAPI.ErrorInfo;
531
+
532
+ usage?: ResponsesAPI.ResponsesUsage;
533
+ }
534
+ }
535
+
536
+ /**
537
+ * Response event Contains the full or partial response object.
538
+ */
539
+ export interface ResponseCompletedEvent {
540
+ /**
541
+ * Monotonically increasing sequence number for event ordering
542
+ */
543
+ sequence_number: number;
544
+
545
+ /**
546
+ * SSE event type discriminator (always "response.completed")
547
+ */
548
+ type: 'response.completed';
549
+
550
+ /**
551
+ * Non-streaming response returned when stream is false
552
+ */
553
+ response?: ResponseCompletedEvent.Response;
554
+ }
555
+
556
+ export namespace ResponseCompletedEvent {
557
+ /**
558
+ * Non-streaming response returned when stream is false
559
+ */
560
+ export interface Response {
561
+ id: string;
562
+
563
+ created_at: number;
564
+
565
+ model: string;
566
+
567
+ /**
568
+ * Object type in API responses
569
+ */
570
+ object: 'response';
571
+
572
+ output: Array<ResponsesAPI.OutputItem>;
573
+
574
+ /**
575
+ * Status of a response or output item
576
+ */
577
+ status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
578
+
579
+ /**
580
+ * Whether the response was created in background mode.
581
+ */
582
+ background?: boolean;
583
+
584
+ error?: ResponsesAPI.ErrorInfo;
585
+
586
+ usage?: ResponsesAPI.ResponsesUsage;
587
+ }
588
+ }
589
+
590
+ /**
591
+ * Response failed event (type: "response.failed"). Contains error details when
592
+ * streaming fails.
593
+ */
594
+ export interface ResponseFailedEvent {
595
+ error: ResponsesAPI.ErrorInfo;
596
+
597
+ /**
598
+ * Monotonically increasing sequence number for event ordering
599
+ */
600
+ sequence_number: number;
601
+
602
+ /**
603
+ * SSE event type discriminator (always "response.failed")
604
+ */
605
+ type: 'response.failed';
606
+ }
607
+
608
+ /**
609
+ * Output item added event (type: "response.output_item.added"). Emitted when a new
610
+ * output item (message or tool call) starts.
611
+ */
612
+ export interface OutputItemAddedEvent {
613
+ /**
614
+ * One item in the response output: an assistant message, retrieved tool results,
615
+ * or a record of a tool call.
616
+ */
617
+ item: ResponsesAPI.OutputItem;
618
+
619
+ output_index: number;
620
+
621
+ /**
622
+ * Monotonically increasing sequence number for event ordering
623
+ */
624
+ sequence_number: number;
625
+
626
+ /**
627
+ * SSE event type discriminator (always "response.output_item.added")
628
+ */
629
+ type: 'response.output_item.added';
630
+ }
631
+
632
+ /**
633
+ * Output item done event (type: "response.output_item.done"). Emitted when an
634
+ * output item (message or tool call) completes.
635
+ */
636
+ export interface OutputItemDoneEvent {
637
+ /**
638
+ * One item in the response output: an assistant message, retrieved tool results,
639
+ * or a record of a tool call.
640
+ */
641
+ item: ResponsesAPI.OutputItem;
642
+
643
+ output_index: number;
644
+
645
+ /**
646
+ * Monotonically increasing sequence number for event ordering
647
+ */
648
+ sequence_number: number;
649
+
650
+ /**
651
+ * SSE event type discriminator (always "response.output_item.done")
652
+ */
653
+ type: 'response.output_item.done';
654
+ }
655
+
656
+ /**
657
+ * Text delta event (type: "response.output_text.delta"). Contains incremental text
658
+ * content.
659
+ */
660
+ export interface TextDeltaEvent {
661
+ content_index: number;
662
+
663
+ delta: string;
664
+
665
+ item_id: string;
666
+
667
+ output_index: number;
668
+
669
+ /**
670
+ * Monotonically increasing sequence number for event ordering
671
+ */
672
+ sequence_number: number;
673
+
674
+ /**
675
+ * SSE event type discriminator (always "response.output_text.delta")
676
+ */
677
+ type: 'response.output_text.delta';
678
+ }
679
+
680
+ /**
681
+ * Text done event (type: "response.output_text.done"). Contains the final text
682
+ * content.
683
+ */
684
+ export interface TextDoneEvent {
685
+ content_index: number;
686
+
687
+ item_id: string;
688
+
689
+ output_index: number;
690
+
691
+ /**
692
+ * Monotonically increasing sequence number for event ordering
693
+ */
694
+ sequence_number: number;
695
+
696
+ text: string;
697
+
698
+ /**
699
+ * SSE event type discriminator (always "response.output_text.done")
700
+ */
701
+ type: 'response.output_text.done';
702
+ }
703
+
704
+ /**
705
+ * Reasoning started event (type: "response.reasoning.started"). Signals the model
706
+ * has started reasoning/searching.
707
+ */
708
+ export interface ReasoningStartedEvent {
709
+ /**
710
+ * Monotonically increasing sequence number for event ordering
711
+ */
712
+ sequence_number: number;
713
+
714
+ /**
715
+ * SSE event type discriminator (always "response.reasoning.started")
716
+ */
717
+ type: 'response.reasoning.started';
718
+
719
+ thought?: string;
720
+ }
721
+
722
+ /**
723
+ * Search queries event (type: "response.reasoning.search_queries"). Contains
724
+ * search queries being executed.
725
+ */
726
+ export interface SearchQueriesEvent {
727
+ queries: Array<string>;
728
+
729
+ /**
730
+ * Monotonically increasing sequence number for event ordering
731
+ */
732
+ sequence_number: number;
733
+
734
+ /**
735
+ * SSE event type discriminator (always "response.reasoning.search_queries")
736
+ */
737
+ type: 'response.reasoning.search_queries';
738
+
739
+ thought?: string;
740
+ }
741
+
742
+ /**
743
+ * Search results event (type: "response.reasoning.search_results"). Contains
744
+ * search results returned.
745
+ */
746
+ export interface SearchResultsEvent {
747
+ results: Array<Shared.SearchResult>;
748
+
749
+ /**
750
+ * Monotonically increasing sequence number for event ordering
751
+ */
752
+ sequence_number: number;
753
+
754
+ /**
755
+ * SSE event type discriminator (always "response.reasoning.search_results")
756
+ */
757
+ type: 'response.reasoning.search_results';
758
+
759
+ thought?: string;
760
+
761
+ usage?: ResponsesAPI.ResponsesUsage;
762
+ }
763
+
764
+ /**
765
+ * URL fetch queries event (type: "response.reasoning.fetch_url_queries"). Contains
766
+ * URLs being fetched.
767
+ */
768
+ export interface FetchURLQueriesEvent {
769
+ /**
770
+ * Monotonically increasing sequence number for event ordering
771
+ */
772
+ sequence_number: number;
773
+
774
+ /**
775
+ * SSE event type discriminator (always "response.reasoning.fetch_url_queries")
776
+ */
777
+ type: 'response.reasoning.fetch_url_queries';
778
+
779
+ urls: Array<string>;
780
+
781
+ thought?: string;
782
+ }
783
+
784
+ /**
785
+ * URL fetch results event (type: "response.reasoning.fetch_url_results"). Contains
786
+ * fetched URL contents.
787
+ */
788
+ export interface FetchURLResultsEvent {
789
+ contents: Array<FetchURLResultsEvent.Content>;
790
+
791
+ /**
792
+ * Monotonically increasing sequence number for event ordering
793
+ */
794
+ sequence_number: number;
795
+
796
+ /**
797
+ * SSE event type discriminator (always "response.reasoning.fetch_url_results")
798
+ */
799
+ type: 'response.reasoning.fetch_url_results';
800
+
801
+ thought?: string;
802
+ }
803
+
804
+ export namespace FetchURLResultsEvent {
805
+ /**
806
+ * Content fetched from a URL
807
+ */
808
+ export interface Content {
809
+ /**
810
+ * The fetched content snippet
811
+ */
812
+ snippet: string;
813
+
814
+ /**
815
+ * The title of the page
816
+ */
817
+ title: string;
818
+
819
+ /**
820
+ * The URL from which content was fetched
821
+ */
822
+ url: string;
823
+ }
824
+ }
825
+
826
+ /**
827
+ * Reasoning stopped event (type: "response.reasoning.stopped"). Signals the model
828
+ * has finished reasoning/searching.
829
+ */
830
+ export interface ReasoningStoppedEvent {
831
+ /**
832
+ * Monotonically increasing sequence number for event ordering
833
+ */
834
+ sequence_number: number;
835
+
836
+ /**
837
+ * SSE event type discriminator (always "response.reasoning.stopped")
838
+ */
839
+ type: 'response.reasoning.stopped';
840
+
841
+ thought?: string;
842
+ }
843
+ }
844
+
845
+ export interface ResponsesCreateParams {
846
+ /**
847
+ * Input content - either a string or array of input items
848
+ */
849
+ input: string | Array<InputItem>;
850
+
851
+ /**
852
+ * Run the response asynchronously. When true, the request is queued and the
853
+ * response object's `status` will be `queued` or `in_progress`. Poll GET
854
+ * /v1/responses/{response_id} to retrieve the final result.
855
+ */
856
+ background?: boolean | null;
857
+
858
+ /**
859
+ * System instructions for the model
860
+ */
861
+ instructions?: string;
862
+
863
+ /**
864
+ * ISO 639-1 language code for response language
865
+ */
866
+ language_preference?: string;
867
+
868
+ /**
869
+ * Maximum tokens to generate
870
+ */
871
+ max_output_tokens?: number;
872
+
873
+ /**
874
+ * Maximum number of research loop steps. If provided, overrides the preset's
875
+ * max_steps value. Must be >= 1 if specified. Maximum allowed is 10.
876
+ */
877
+ max_steps?: number;
878
+
879
+ /**
880
+ * Model ID in provider/model format (e.g., "xai/grok-4-1", "openai/gpt-4o"). If
881
+ * models is also provided, models takes precedence. Required if neither models nor
882
+ * preset is provided.
883
+ */
884
+ model?: string;
885
+
886
+ /**
887
+ * Model fallback chain. Each model is in provider/model format. Models are tried
888
+ * in order until one succeeds. Max 5 models allowed. If set, takes precedence over
889
+ * single model field. The response.model will reflect the model that actually
890
+ * succeeded.
891
+ */
892
+ models?: Array<string>;
893
+
894
+ /**
895
+ * Preset configuration name (e.g., "sonar-pro", "sonar-reasoning"). Pre-configured
896
+ * model with system prompt and search parameters. Required if model is not
897
+ * provided.
898
+ */
899
+ preset?: string;
900
+
901
+ reasoning?: ResponsesCreateParams.Reasoning;
902
+
903
+ /**
904
+ * Specifies the desired output format for the model response
905
+ */
906
+ response_format?: Shared.ResponseFormat;
907
+
908
+ /**
909
+ * If true, returns SSE stream instead of JSON
910
+ */
911
+ stream?: boolean;
912
+
913
+ /**
914
+ * Tools available to the model
915
+ */
916
+ tools?: Array<
917
+ | ResponsesCreateParams.WebSearchTool
918
+ | ResponsesCreateParams.FetchURLTool
919
+ | ResponsesCreateParams.PeopleSearchTool
920
+ | FunctionTool
921
+ | ResponsesCreateParams.FinanceSearchTool
922
+ | ResponsesCreateParams.SandboxTool
923
+ | ResponsesCreateParams.McpTool
924
+ >;
925
+ }
926
+
927
+ export namespace ResponsesCreateParams {
928
+ export interface Reasoning {
929
+ /**
930
+ * How much effort the model should spend on reasoning
931
+ */
932
+ effort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
933
+ }
934
+
935
+ export interface WebSearchTool {
936
+ type: 'web_search';
937
+
938
+ filters?: WebSearchTool.Filters;
939
+
940
+ max_tokens?: number;
941
+
942
+ max_tokens_per_page?: number;
943
+
944
+ /**
945
+ * Search context size (low, medium, high). Omit when supplying explicit max_tokens
946
+ * / max_tokens_per_page.
947
+ */
948
+ search_context_size?: 'low' | 'medium' | 'high';
949
+
950
+ /**
951
+ * User's geographic location for search personalization
952
+ */
953
+ user_location?: WebSearchTool.UserLocation;
954
+ }
955
+
956
+ export namespace WebSearchTool {
957
+ export interface Filters {
958
+ /**
959
+ * Input: MM/DD/YYYY, Output: YYYY-MM-DD
960
+ */
961
+ last_updated_after_filter?: string;
962
+
963
+ /**
964
+ * Input: MM/DD/YYYY, Output: YYYY-MM-DD
965
+ */
966
+ last_updated_before_filter?: string;
967
+
968
+ /**
969
+ * Input: MM/DD/YYYY, Output: YYYY-MM-DD
970
+ */
971
+ search_after_date_filter?: string;
972
+
973
+ /**
974
+ * Input: MM/DD/YYYY, Output: YYYY-MM-DD
975
+ */
976
+ search_before_date_filter?: string;
977
+
978
+ search_domain_filter?: Array<string>;
979
+
980
+ search_recency_filter?: 'hour' | 'day' | 'week' | 'month' | 'year';
981
+ }
982
+
983
+ /**
984
+ * User's geographic location for search personalization
985
+ */
986
+ export interface UserLocation {
987
+ city?: string;
988
+
989
+ /**
990
+ * ISO 3166-1 alpha-2 country code
991
+ */
992
+ country?: string;
993
+
994
+ latitude?: number;
995
+
996
+ longitude?: number;
997
+
998
+ region?: string;
999
+ }
1000
+ }
1001
+
1002
+ export interface FetchURLTool {
1003
+ type: 'fetch_url';
1004
+
1005
+ /**
1006
+ * Maximum number of URLs to fetch per tool call
1007
+ */
1008
+ max_urls?: number;
1009
+ }
1010
+
1011
+ export interface PeopleSearchTool {
1012
+ /**
1013
+ * Enables the `people_search` tool.
1014
+ */
1015
+ type: 'people_search';
1016
+ }
1017
+
1018
+ export interface FinanceSearchTool {
1019
+ /**
1020
+ * Enables the `finance_search` tool. The model can request structured financial
1021
+ * data (quotes, financials, segments, earnings transcripts, etc.) via
1022
+ * category-based fan-out to FMP, Finchat, and Quartr.
1023
+ */
1024
+ type: 'finance_search';
1025
+ }
1026
+
1027
+ export interface SandboxTool {
1028
+ /**
1029
+ * Enables the `sandbox` tool. The model can execute code in an isolated container
1030
+ * during the request and use the result in its final answer.
1031
+ */
1032
+ type: 'sandbox';
1033
+ }
1034
+
1035
+ /**
1036
+ * Connects a user-supplied remote MCP server. The worker discovers the server's
1037
+ * tools at boot and calls them like native tools. Matches OpenAI's mcp tool.
1038
+ * `require_approval`, `connector_id`, and `defer_loading` are not supported in v1
1039
+ * and are ignored if sent: every call auto-runs, and only bring-your-own
1040
+ * `server_url` is honored.
1041
+ */
1042
+ export interface McpTool {
1043
+ /**
1044
+ * Unique per request, ^[a-zA-Z0-9_-]{1,64}$. Namespaces the server's tools.
1045
+ */
1046
+ server_label: string;
1047
+
1048
+ /**
1049
+ * HTTPS URL of the remote MCP server.
1050
+ */
1051
+ server_url: string;
1052
+
1053
+ type: 'mcp';
1054
+
1055
+ /**
1056
+ * Optional allowlist of tool names. Empty exposes all discovered tools.
1057
+ */
1058
+ allowed_tools?: Array<string>;
1059
+
1060
+ /**
1061
+ * An OAuth access token that can be used with a remote MCP server, with a custom
1062
+ * MCP server URL. Never logged or echoed.
1063
+ */
1064
+ authorization?: string;
1065
+
1066
+ /**
1067
+ * Extra request headers. Never logged or echoed.
1068
+ */
1069
+ headers?: { [key: string]: string };
1070
+ }
1071
+ }
1072
+
1073
+ export interface ResponsesUsage {
1074
+ input_tokens: number;
1075
+
1076
+ output_tokens: number;
1077
+
1078
+ total_tokens: number;
1079
+
1080
+ cost?: ResponsesUsage.Cost;
1081
+
1082
+ input_tokens_details?: ResponsesUsage.InputTokensDetails;
1083
+
1084
+ tool_calls_details?: { [key: string]: ResponsesUsage.ToolCallsDetails };
1085
+ }
1086
+
1087
+ export namespace ResponsesUsage {
1088
+ export interface Cost {
1089
+ /**
1090
+ * Currency code for cost values
1091
+ */
1092
+ currency: 'USD';
1093
+
1094
+ input_cost: number;
1095
+
1096
+ output_cost: number;
1097
+
1098
+ total_cost: number;
1099
+
1100
+ cache_creation_cost?: number;
1101
+
1102
+ cache_read_cost?: number;
1103
+
1104
+ tool_calls_cost?: number;
1105
+ }
1106
+
1107
+ export interface InputTokensDetails {
1108
+ cache_creation_input_tokens?: number;
1109
+
1110
+ cache_read_input_tokens?: number;
1111
+ }
1112
+
1113
+ export interface ToolCallsDetails {
1114
+ /**
1115
+ * Number of times this tool was invoked
1116
+ */
1117
+ invocation?: number;
1118
+ }
1119
+ }
1120
+
1121
+ /**
1122
+ * Non-streaming response returned when stream is false
1123
+ */
1124
+ export interface ResponseCreateResponse {
1125
+ id: string;
1126
+
1127
+ created_at: number;
1128
+
1129
+ model: string;
1130
+
1131
+ /**
1132
+ * Object type in API responses
1133
+ */
1134
+ object: 'response';
1135
+
1136
+ output: Array<OutputItem>;
1137
+
1138
+ /**
1139
+ * Status of a response or output item
1140
+ */
1141
+ status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
1142
+
1143
+ /**
1144
+ * Whether the response was created in background mode.
1145
+ */
1146
+ background?: boolean;
1147
+
1148
+ error?: ErrorInfo;
1149
+
1150
+ usage?: ResponsesUsage;
1151
+
1152
+ /**
1153
+ * Convenience property that aggregates all `output_text` items from the `output` list.
1154
+ * If no `output_text` content blocks exist, then an empty string is returned.
1155
+ */
1156
+ output_text?: string;
1157
+ }
1158
+
1159
+ /**
1160
+ * Non-streaming response returned when stream is false
1161
+ */
1162
+ export interface ResponseRetrieveResponse {
1163
+ id: string;
1164
+
1165
+ created_at: number;
1166
+
1167
+ model: string;
1168
+
1169
+ /**
1170
+ * Object type in API responses
1171
+ */
1172
+ object: 'response';
1173
+
1174
+ output: Array<OutputItem>;
1175
+
1176
+ /**
1177
+ * Status of a response or output item
1178
+ */
1179
+ status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
1180
+
1181
+ /**
1182
+ * Whether the response was created in background mode.
1183
+ */
1184
+ background?: boolean;
1185
+
1186
+ error?: ErrorInfo;
1187
+
1188
+ usage?: ResponsesUsage;
1189
+
1190
+ /**
1191
+ * Convenience property that aggregates all `output_text` items from the `output` list.
1192
+ * If no `output_text` content blocks exist, then an empty string is returned.
1193
+ */
1194
+ output_text?: string;
1195
+ }
1196
+
1197
+ export type ResponseCreateParams = ResponseCreateParamsNonStreaming | ResponseCreateParamsStreaming;
1198
+
1199
+ export interface ResponseCreateParamsBase {
1200
+ /**
1201
+ * Input content - either a string or array of input items
1202
+ */
1203
+ input: string | Array<InputItem>;
1204
+
1205
+ /**
1206
+ * Run the response asynchronously. When true, the request is queued and the
1207
+ * response object's `status` will be `queued` or `in_progress`. Poll GET
1208
+ * /v1/responses/{response_id} to retrieve the final result.
1209
+ */
1210
+ background?: boolean | null;
1211
+
1212
+ /**
1213
+ * System instructions for the model
1214
+ */
1215
+ instructions?: string;
1216
+
1217
+ /**
1218
+ * ISO 639-1 language code for response language
1219
+ */
1220
+ language_preference?: string;
1221
+
1222
+ /**
1223
+ * Maximum tokens to generate
1224
+ */
1225
+ max_output_tokens?: number;
1226
+
1227
+ /**
1228
+ * Maximum number of research loop steps. If provided, overrides the preset's
1229
+ * max_steps value. Must be >= 1 if specified. Maximum allowed is 10.
1230
+ */
1231
+ max_steps?: number;
1232
+
1233
+ /**
1234
+ * Model ID in provider/model format (e.g., "xai/grok-4-1", "openai/gpt-4o"). If
1235
+ * models is also provided, models takes precedence. Required if neither models nor
1236
+ * preset is provided.
1237
+ */
1238
+ model?: string;
1239
+
1240
+ /**
1241
+ * Model fallback chain. Each model is in provider/model format. Models are tried
1242
+ * in order until one succeeds. Max 5 models allowed. If set, takes precedence over
1243
+ * single model field. The response.model will reflect the model that actually
1244
+ * succeeded.
1245
+ */
1246
+ models?: Array<string>;
1247
+
1248
+ /**
1249
+ * Preset configuration name (e.g., "sonar-pro", "sonar-reasoning"). Pre-configured
1250
+ * model with system prompt and search parameters. Required if model is not
1251
+ * provided.
1252
+ */
1253
+ preset?: string;
1254
+
1255
+ reasoning?: ResponseCreateParams.Reasoning;
1256
+
1257
+ /**
1258
+ * Specifies the desired output format for the model response
1259
+ */
1260
+ response_format?: Shared.ResponseFormat;
1261
+
1262
+ /**
1263
+ * If true, returns SSE stream instead of JSON
1264
+ */
1265
+ stream?: boolean;
1266
+
1267
+ /**
1268
+ * Tools available to the model
1269
+ */
1270
+ tools?: Array<
1271
+ | ResponseCreateParams.WebSearchTool
1272
+ | ResponseCreateParams.FetchURLTool
1273
+ | ResponseCreateParams.PeopleSearchTool
1274
+ | FunctionTool
1275
+ | ResponseCreateParams.FinanceSearchTool
1276
+ | ResponseCreateParams.SandboxTool
1277
+ | ResponseCreateParams.McpTool
1278
+ >;
1279
+ }
1280
+
1281
+ export namespace ResponseCreateParams {
1282
+ export interface Reasoning {
1283
+ /**
1284
+ * How much effort the model should spend on reasoning
1285
+ */
1286
+ effort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
1287
+ }
1288
+
1289
+ export interface WebSearchTool {
1290
+ type: 'web_search';
1291
+
1292
+ filters?: WebSearchTool.Filters;
1293
+
1294
+ max_tokens?: number;
1295
+
1296
+ max_tokens_per_page?: number;
1297
+
1298
+ /**
1299
+ * Search context size (low, medium, high). Omit when supplying explicit max_tokens
1300
+ * / max_tokens_per_page.
1301
+ */
1302
+ search_context_size?: 'low' | 'medium' | 'high';
1303
+
1304
+ /**
1305
+ * User's geographic location for search personalization
1306
+ */
1307
+ user_location?: WebSearchTool.UserLocation;
1308
+ }
1309
+
1310
+ export namespace WebSearchTool {
1311
+ export interface Filters {
1312
+ /**
1313
+ * Input: MM/DD/YYYY, Output: YYYY-MM-DD
1314
+ */
1315
+ last_updated_after_filter?: string;
1316
+
1317
+ /**
1318
+ * Input: MM/DD/YYYY, Output: YYYY-MM-DD
1319
+ */
1320
+ last_updated_before_filter?: string;
1321
+
1322
+ /**
1323
+ * Input: MM/DD/YYYY, Output: YYYY-MM-DD
1324
+ */
1325
+ search_after_date_filter?: string;
1326
+
1327
+ /**
1328
+ * Input: MM/DD/YYYY, Output: YYYY-MM-DD
1329
+ */
1330
+ search_before_date_filter?: string;
1331
+
1332
+ search_domain_filter?: Array<string>;
1333
+
1334
+ search_recency_filter?: 'hour' | 'day' | 'week' | 'month' | 'year';
1335
+ }
1336
+
1337
+ /**
1338
+ * User's geographic location for search personalization
1339
+ */
1340
+ export interface UserLocation {
1341
+ city?: string;
1342
+
1343
+ /**
1344
+ * ISO 3166-1 alpha-2 country code
1345
+ */
1346
+ country?: string;
1347
+
1348
+ latitude?: number;
1349
+
1350
+ longitude?: number;
1351
+
1352
+ region?: string;
1353
+ }
1354
+ }
1355
+
1356
+ export interface FetchURLTool {
1357
+ type: 'fetch_url';
1358
+
1359
+ /**
1360
+ * Maximum number of URLs to fetch per tool call
1361
+ */
1362
+ max_urls?: number;
1363
+ }
1364
+
1365
+ export interface PeopleSearchTool {
1366
+ /**
1367
+ * Enables the `people_search` tool.
1368
+ */
1369
+ type: 'people_search';
1370
+ }
1371
+
1372
+ export interface FinanceSearchTool {
1373
+ /**
1374
+ * Enables the `finance_search` tool. The model can request structured financial
1375
+ * data (quotes, financials, segments, earnings transcripts, etc.) via
1376
+ * category-based fan-out to FMP, Finchat, and Quartr.
1377
+ */
1378
+ type: 'finance_search';
1379
+ }
1380
+
1381
+ export interface SandboxTool {
1382
+ /**
1383
+ * Enables the `sandbox` tool. The model can execute code in an isolated container
1384
+ * during the request and use the result in its final answer.
1385
+ */
1386
+ type: 'sandbox';
1387
+ }
1388
+
1389
+ /**
1390
+ * Connects a user-supplied remote MCP server. The worker discovers the server's
1391
+ * tools at boot and calls them like native tools. Matches OpenAI's mcp tool.
1392
+ * `require_approval`, `connector_id`, and `defer_loading` are not supported in v1
1393
+ * and are ignored if sent: every call auto-runs, and only bring-your-own
1394
+ * `server_url` is honored.
1395
+ */
1396
+ export interface McpTool {
1397
+ /**
1398
+ * Unique per request, ^[a-zA-Z0-9_-]{1,64}$. Namespaces the server's tools.
1399
+ */
1400
+ server_label: string;
1401
+
1402
+ /**
1403
+ * HTTPS URL of the remote MCP server.
1404
+ */
1405
+ server_url: string;
1406
+
1407
+ type: 'mcp';
1408
+
1409
+ /**
1410
+ * Optional allowlist of tool names. Empty exposes all discovered tools.
1411
+ */
1412
+ allowed_tools?: Array<string>;
1413
+
1414
+ /**
1415
+ * An OAuth access token that can be used with a remote MCP server, with a custom
1416
+ * MCP server URL. Never logged or echoed.
1417
+ */
1418
+ authorization?: string;
1419
+
1420
+ /**
1421
+ * Extra request headers. Never logged or echoed.
1422
+ */
1423
+ headers?: { [key: string]: string };
1424
+ }
1425
+
1426
+ export type ResponseCreateParamsNonStreaming = ResponsesAPI.ResponseCreateParamsNonStreaming;
1427
+ export type ResponseCreateParamsStreaming = ResponsesAPI.ResponseCreateParamsStreaming;
1428
+ }
1429
+
1430
+ export interface ResponseCreateParamsNonStreaming extends ResponseCreateParamsBase {
1431
+ /**
1432
+ * If true, returns SSE stream instead of JSON
1433
+ */
1434
+ stream?: false;
1435
+ }
1436
+
1437
+ export interface ResponseCreateParamsStreaming extends ResponseCreateParamsBase {
1438
+ /**
1439
+ * If true, returns SSE stream instead of JSON
1440
+ */
1441
+ stream: true;
1442
+ }
1443
+
1444
+ Responses.Files = Files;
1445
+
1446
+ export declare namespace Responses {
1447
+ export {
1448
+ type Annotation as Annotation,
1449
+ type ContentPart as ContentPart,
1450
+ type ErrorInfo as ErrorInfo,
1451
+ type FunctionCallOutputItem as FunctionCallOutputItem,
1452
+ type FunctionTool as FunctionTool,
1453
+ type InputItem as InputItem,
1454
+ type OutputItem as OutputItem,
1455
+ type ResponseFile as ResponseFile,
1456
+ type ResponseFileList as ResponseFileList,
1457
+ type ResponseStreamChunk as ResponseStreamChunk,
1458
+ type ResponsesCreateParams as ResponsesCreateParams,
1459
+ type ResponsesUsage as ResponsesUsage,
1460
+ type ResponseCreateResponse as ResponseCreateResponse,
1461
+ type ResponseRetrieveResponse as ResponseRetrieveResponse,
1462
+ type ResponseCreateParams as ResponseCreateParams,
1463
+ type ResponseCreateParamsNonStreaming as ResponseCreateParamsNonStreaming,
1464
+ type ResponseCreateParamsStreaming as ResponseCreateParamsStreaming,
1465
+ };
1466
+
1467
+ export { Files as Files, type FileContentParams as FileContentParams };
1468
+ }