@perplexity-ai/perplexity_ai 0.2.1 → 0.4.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 (74) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/client.d.mts +4 -6
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +4 -6
  5. package/client.d.ts.map +1 -1
  6. package/client.js +0 -3
  7. package/client.js.map +1 -1
  8. package/client.mjs +0 -3
  9. package/client.mjs.map +1 -1
  10. package/package.json +1 -1
  11. package/resources/async/chat/chat.d.mts +2 -2
  12. package/resources/async/chat/chat.d.mts.map +1 -1
  13. package/resources/async/chat/chat.d.ts +2 -2
  14. package/resources/async/chat/chat.d.ts.map +1 -1
  15. package/resources/async/chat/completions.d.mts +160 -134
  16. package/resources/async/chat/completions.d.mts.map +1 -1
  17. package/resources/async/chat/completions.d.ts +160 -134
  18. package/resources/async/chat/completions.d.ts.map +1 -1
  19. package/resources/async/chat/completions.js +25 -7
  20. package/resources/async/chat/completions.js.map +1 -1
  21. package/resources/async/chat/completions.mjs +25 -7
  22. package/resources/async/chat/completions.mjs.map +1 -1
  23. package/resources/async/chat/index.d.mts +1 -1
  24. package/resources/async/chat/index.d.mts.map +1 -1
  25. package/resources/async/chat/index.d.ts +1 -1
  26. package/resources/async/chat/index.d.ts.map +1 -1
  27. package/resources/chat/completions.d.mts +115 -83
  28. package/resources/chat/completions.d.mts.map +1 -1
  29. package/resources/chat/completions.d.ts +115 -83
  30. package/resources/chat/completions.d.ts.map +1 -1
  31. package/resources/chat/completions.js +1 -2
  32. package/resources/chat/completions.js.map +1 -1
  33. package/resources/chat/completions.mjs +1 -2
  34. package/resources/chat/completions.mjs.map +1 -1
  35. package/resources/index.d.mts +0 -1
  36. package/resources/index.d.mts.map +1 -1
  37. package/resources/index.d.ts +0 -1
  38. package/resources/index.d.ts.map +1 -1
  39. package/resources/index.js +1 -3
  40. package/resources/index.js.map +1 -1
  41. package/resources/index.mjs +0 -1
  42. package/resources/index.mjs.map +1 -1
  43. package/resources/search.d.mts +1 -70
  44. package/resources/search.d.mts.map +1 -1
  45. package/resources/search.d.ts +1 -70
  46. package/resources/search.d.ts.map +1 -1
  47. package/resources/search.js +1 -1
  48. package/resources/search.mjs +1 -1
  49. package/resources/shared.d.mts +310 -25
  50. package/resources/shared.d.mts.map +1 -1
  51. package/resources/shared.d.ts +310 -25
  52. package/resources/shared.d.ts.map +1 -1
  53. package/src/client.ts +4 -12
  54. package/src/resources/async/chat/chat.ts +2 -2
  55. package/src/resources/async/chat/completions.ts +263 -142
  56. package/src/resources/async/chat/index.ts +1 -1
  57. package/src/resources/chat/completions.ts +181 -85
  58. package/src/resources/index.ts +0 -1
  59. package/src/resources/search.ts +1 -70
  60. package/src/resources/shared.ts +434 -25
  61. package/src/version.ts +1 -1
  62. package/version.d.mts +1 -1
  63. package/version.d.ts +1 -1
  64. package/version.js +1 -1
  65. package/version.mjs +1 -1
  66. package/resources/content.d.mts +0 -55
  67. package/resources/content.d.mts.map +0 -1
  68. package/resources/content.d.ts +0 -55
  69. package/resources/content.d.ts.map +0 -1
  70. package/resources/content.js +0 -15
  71. package/resources/content.js.map +0 -1
  72. package/resources/content.mjs +0 -11
  73. package/resources/content.mjs.map +0 -1
  74. package/src/resources/content.ts +0 -70
@@ -3,48 +3,71 @@
3
3
  import { APIResource } from '../../../core/resource';
4
4
  import * as Shared from '../../shared';
5
5
  import { APIPromise } from '../../../core/api-promise';
6
+ import { buildHeaders } from '../../../internal/headers';
6
7
  import { RequestOptions } from '../../../internal/request-options';
7
8
  import { path } from '../../../internal/utils/path';
8
9
 
9
10
  export class Completions extends APIResource {
10
11
  /**
11
- * Creates an asynchronous chat completion job
12
+ * FastAPI wrapper around async chat completions
13
+ *
14
+ * This endpoint creates an asynchronous chat completion job and returns a job ID
15
+ * that can be used to poll for results.
12
16
  */
13
17
  create(body: CompletionCreateParams, options?: RequestOptions): APIPromise<CompletionCreateResponse> {
14
18
  return this._client.post('/async/chat/completions', { body, ...options });
15
19
  }
16
20
 
17
21
  /**
18
- * Lists all asynchronous chat completion requests for the authenticated user
22
+ * list all async chat completion requests for a given user.
19
23
  */
20
- list(
21
- query: CompletionListParams | null | undefined = {},
22
- options?: RequestOptions,
23
- ): APIPromise<CompletionListResponse> {
24
- return this._client.get('/async/chat/completions', { query, ...options });
24
+ list(options?: RequestOptions): APIPromise<CompletionListResponse> {
25
+ return this._client.get('/async/chat/completions', options);
25
26
  }
26
27
 
27
28
  /**
28
- * Retrieves the status and result of a specific asynchronous chat completion job
29
+ * get the response for a given async chat completion request.
29
30
  */
30
- get(requestID: string, options?: RequestOptions): APIPromise<CompletionGetResponse> {
31
- return this._client.get(path`/async/chat/completions/${requestID}`, options);
31
+ get(
32
+ apiRequest: string,
33
+ params: CompletionGetParams | null | undefined = {},
34
+ options?: RequestOptions,
35
+ ): APIPromise<CompletionGetResponse> {
36
+ const {
37
+ 'x-client-env': xClientEnv,
38
+ 'x-client-name': xClientName,
39
+ 'x-request-time': xRequestTime,
40
+ 'x-usage-tier': xUsageTier,
41
+ 'x-user-id': xUserID,
42
+ ...query
43
+ } = params ?? {};
44
+ return this._client.get(path`/async/chat/completions/${apiRequest}`, {
45
+ query,
46
+ ...options,
47
+ headers: buildHeaders([
48
+ {
49
+ ...(xClientEnv != null ? { 'x-client-env': xClientEnv } : undefined),
50
+ ...(xClientName != null ? { 'x-client-name': xClientName } : undefined),
51
+ ...(xRequestTime != null ? { 'x-request-time': xRequestTime } : undefined),
52
+ ...(xUsageTier != null ? { 'x-usage-tier': xUsageTier } : undefined),
53
+ ...(xUserID != null ? { 'x-user-id': xUserID } : undefined),
54
+ },
55
+ options?.headers,
56
+ ]),
57
+ });
32
58
  }
33
59
  }
34
60
 
35
61
  export interface CompletionCreateResponse {
36
- /**
37
- * Unique identifier for the async job
38
- */
39
62
  id: string;
40
63
 
41
- /**
42
- * Unix timestamp of creation
43
- */
44
64
  created_at: number;
45
65
 
46
66
  model: string;
47
67
 
68
+ /**
69
+ * Status enum for async processing.
70
+ */
48
71
  status: 'CREATED' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILED';
49
72
 
50
73
  completed_at?: number | null;
@@ -53,53 +76,38 @@ export interface CompletionCreateResponse {
53
76
 
54
77
  failed_at?: number | null;
55
78
 
56
- /**
57
- * The completion response when status is COMPLETED
58
- */
59
79
  response?: CompletionCreateResponse.Response | null;
60
80
 
61
81
  started_at?: number | null;
62
82
  }
63
83
 
64
84
  export namespace CompletionCreateResponse {
65
- /**
66
- * The completion response when status is COMPLETED
67
- */
68
85
  export interface Response {
69
- /**
70
- * Unique identifier for the chat completion
71
- */
72
86
  id: string;
73
87
 
74
- choices: Array<Shared.ChatChoice>;
88
+ choices: Array<Shared.Choice>;
75
89
 
76
- /**
77
- * Unix timestamp of creation
78
- */
79
90
  created: number;
80
91
 
81
- /**
82
- * The model used
83
- */
84
92
  model: string;
85
93
 
86
- object: string;
87
-
88
94
  usage: Shared.UsageInfo;
89
95
 
90
- /**
91
- * Search results used in generating the response
92
- */
93
- search_results?: Array<Shared.SearchResult> | null;
96
+ citations?: Array<string> | null;
97
+
98
+ object?: string;
99
+
100
+ search_results?: Array<Shared.APIPublicSearchResult> | null;
101
+
102
+ status?: 'PENDING' | 'COMPLETED' | null;
103
+
104
+ type?: 'message' | 'info' | 'end_of_stream' | null;
94
105
  }
95
106
  }
96
107
 
97
108
  export interface CompletionListResponse {
98
109
  requests: Array<CompletionListResponse.Request>;
99
110
 
100
- /**
101
- * Token for pagination
102
- */
103
111
  next_token?: string | null;
104
112
  }
105
113
 
@@ -111,6 +119,9 @@ export namespace CompletionListResponse {
111
119
 
112
120
  model: string;
113
121
 
122
+ /**
123
+ * Status enum for async processing.
124
+ */
114
125
  status: 'CREATED' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILED';
115
126
 
116
127
  completed_at?: number | null;
@@ -122,18 +133,15 @@ export namespace CompletionListResponse {
122
133
  }
123
134
 
124
135
  export interface CompletionGetResponse {
125
- /**
126
- * Unique identifier for the async job
127
- */
128
136
  id: string;
129
137
 
130
- /**
131
- * Unix timestamp of creation
132
- */
133
138
  created_at: number;
134
139
 
135
140
  model: string;
136
141
 
142
+ /**
143
+ * Status enum for async processing.
144
+ */
137
145
  status: 'CREATED' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILED';
138
146
 
139
147
  completed_at?: number | null;
@@ -142,176 +150,289 @@ export interface CompletionGetResponse {
142
150
 
143
151
  failed_at?: number | null;
144
152
 
145
- /**
146
- * The completion response when status is COMPLETED
147
- */
148
153
  response?: CompletionGetResponse.Response | null;
149
154
 
150
155
  started_at?: number | null;
151
156
  }
152
157
 
153
158
  export namespace CompletionGetResponse {
154
- /**
155
- * The completion response when status is COMPLETED
156
- */
157
159
  export interface Response {
158
- /**
159
- * Unique identifier for the chat completion
160
- */
161
160
  id: string;
162
161
 
163
- choices: Array<Shared.ChatChoice>;
162
+ choices: Array<Shared.Choice>;
164
163
 
165
- /**
166
- * Unix timestamp of creation
167
- */
168
164
  created: number;
169
165
 
170
- /**
171
- * The model used
172
- */
173
166
  model: string;
174
167
 
175
- object: string;
176
-
177
168
  usage: Shared.UsageInfo;
178
169
 
179
- /**
180
- * Search results used in generating the response
181
- */
182
- search_results?: Array<Shared.SearchResult> | null;
170
+ citations?: Array<string> | null;
171
+
172
+ object?: string;
173
+
174
+ search_results?: Array<Shared.APIPublicSearchResult> | null;
175
+
176
+ status?: 'PENDING' | 'COMPLETED' | null;
177
+
178
+ type?: 'message' | 'info' | 'end_of_stream' | null;
183
179
  }
184
180
  }
185
181
 
186
182
  export interface CompletionCreateParams {
187
183
  request: CompletionCreateParams.Request;
184
+
185
+ idempotency_key?: string | null;
188
186
  }
189
187
 
190
188
  export namespace CompletionCreateParams {
191
189
  export interface Request {
192
- /**
193
- * A list of messages comprising the conversation so far
194
- */
195
- messages: Array<Shared.ChatMessage>;
190
+ messages: Array<Shared.ChatMessageInput>;
196
191
 
197
- /**
198
- * The name of the model that will complete your prompt
199
- */
200
- model: 'sonar' | 'sonar-pro' | 'sonar-deep-research' | 'sonar-reasoning' | 'sonar-reasoning-pro';
192
+ model: string;
201
193
 
202
- /**
203
- * Disables web search completely - model uses only training data
204
- */
205
- disable_search?: boolean;
194
+ _debug_pro_search?: boolean;
206
195
 
207
- /**
208
- * Enables classifier that decides if web search is needed
209
- */
210
- enable_search_classifier?: boolean;
196
+ _inputs?: Array<number> | null;
197
+
198
+ _is_browser_agent?: boolean | null;
199
+
200
+ _prompt_token_length?: number | null;
201
+
202
+ best_of?: number | null;
203
+
204
+ country?: string | null;
205
+
206
+ cum_logprobs?: boolean | null;
207
+
208
+ debug_params?: Request.DebugParams | null;
209
+
210
+ disable_search?: boolean | null;
211
+
212
+ diverse_first_token?: boolean | null;
213
+
214
+ enable_search_classifier?: boolean | null;
215
+
216
+ file_workspace_id?: string | null;
217
+
218
+ frequency_penalty?: number | null;
219
+
220
+ has_image_url?: boolean;
221
+
222
+ image_domain_filter?: Array<string> | null;
223
+
224
+ image_format_filter?: Array<string> | null;
211
225
 
212
- /**
213
- * Only include content last updated after this date (YYYY-MM-DD)
214
- */
215
226
  last_updated_after_filter?: string | null;
216
227
 
217
- /**
218
- * Only include content last updated before this date (YYYY-MM-DD)
219
- */
220
228
  last_updated_before_filter?: string | null;
221
229
 
222
- /**
223
- * Controls computational effort for sonar-deep-research model. Higher effort =
224
- * more thorough but more tokens
225
- */
226
- reasoning_effort?: 'low' | 'medium' | 'high' | null;
230
+ latitude?: number | null;
227
231
 
228
- /**
229
- * Whether to include images in search results
230
- */
231
- return_images?: boolean;
232
+ logprobs?: boolean | null;
232
233
 
233
- /**
234
- * Whether to return related questions
235
- */
236
- return_related_questions?: boolean;
234
+ longitude?: number | null;
235
+
236
+ max_tokens?: number | null;
237
+
238
+ n?: number | null;
239
+
240
+ num_images?: number;
241
+
242
+ num_search_results?: number;
243
+
244
+ parallel_tool_calls?: boolean | null;
245
+
246
+ presence_penalty?: number | null;
247
+
248
+ ranking_model?: string | null;
249
+
250
+ reasoning_effort?: 'minimal' | 'low' | 'medium' | 'high' | null;
251
+
252
+ response_format?:
253
+ | Request.ResponseFormatText
254
+ | Request.ResponseFormatJsonSchema
255
+ | Request.ResponseFormatRegex
256
+ | null;
257
+
258
+ response_metadata?: { [key: string]: unknown } | null;
259
+
260
+ return_images?: boolean | null;
261
+
262
+ return_related_questions?: boolean | null;
263
+
264
+ safe_search?: boolean | null;
237
265
 
238
- /**
239
- * Only include content published after this date (YYYY-MM-DD)
240
- */
241
266
  search_after_date_filter?: string | null;
242
267
 
243
- /**
244
- * Only include content published before this date (YYYY-MM-DD)
245
- */
246
268
  search_before_date_filter?: string | null;
247
269
 
248
- /**
249
- * List of domains to limit search results to. Use '-' prefix to exclude domains
250
- */
251
270
  search_domain_filter?: Array<string> | null;
252
271
 
253
- /**
254
- * Type of search: 'web' for general, 'academic' for scholarly, 'sec' for SEC
255
- * filings
256
- */
272
+ search_internal_properties?: { [key: string]: unknown } | null;
273
+
257
274
  search_mode?: 'web' | 'academic' | 'sec' | null;
258
275
 
259
- /**
260
- * Filter results by how recently they were published
261
- */
262
276
  search_recency_filter?: 'hour' | 'day' | 'week' | 'month' | 'year' | null;
263
277
 
278
+ search_tenant?: string | null;
279
+
280
+ stop?: string | Array<string> | null;
281
+
282
+ stream?: boolean | null;
283
+
284
+ temperature?: number | null;
285
+
286
+ tool_choice?: 'none' | 'auto' | 'required' | null;
287
+
288
+ tools?: Array<Request.Tool> | null;
289
+
290
+ top_k?: number | null;
291
+
292
+ top_logprobs?: number | null;
293
+
294
+ top_p?: number | null;
295
+
296
+ updated_after_timestamp?: number | null;
297
+
298
+ updated_before_timestamp?: number | null;
299
+
264
300
  web_search_options?: Request.WebSearchOptions;
265
301
  }
266
302
 
267
303
  export namespace Request {
304
+ export interface DebugParams {
305
+ summarizer_model_override?: string | null;
306
+
307
+ summarizer_prompt_override?: string | null;
308
+ }
309
+
310
+ export interface ResponseFormatText {
311
+ type: 'text';
312
+ }
313
+
314
+ export interface ResponseFormatJsonSchema {
315
+ json_schema: ResponseFormatJsonSchema.JsonSchema;
316
+
317
+ type: 'json_schema';
318
+ }
319
+
320
+ export namespace ResponseFormatJsonSchema {
321
+ export interface JsonSchema {
322
+ schema: { [key: string]: unknown };
323
+
324
+ description?: string | null;
325
+
326
+ name?: string | null;
327
+
328
+ strict?: boolean | null;
329
+ }
330
+ }
331
+
332
+ export interface ResponseFormatRegex {
333
+ regex: ResponseFormatRegex.Regex;
334
+
335
+ type: 'regex';
336
+ }
337
+
338
+ export namespace ResponseFormatRegex {
339
+ export interface Regex {
340
+ regex: string;
341
+
342
+ description?: string | null;
343
+
344
+ name?: string | null;
345
+
346
+ strict?: boolean | null;
347
+ }
348
+ }
349
+
350
+ export interface Tool {
351
+ function: Tool.Function;
352
+
353
+ type: 'function';
354
+ }
355
+
356
+ export namespace Tool {
357
+ export interface Function {
358
+ description: string;
359
+
360
+ name: string;
361
+
362
+ parameters: Function.Parameters;
363
+
364
+ strict?: boolean | null;
365
+ }
366
+
367
+ export namespace Function {
368
+ export interface Parameters {
369
+ properties: { [key: string]: unknown };
370
+
371
+ type: string;
372
+
373
+ additional_properties?: boolean | null;
374
+
375
+ required?: Array<string> | null;
376
+ }
377
+ }
378
+ }
379
+
268
380
  export interface WebSearchOptions {
269
- /**
270
- * Improves relevance of image search results
271
- */
272
- image_search_relevance_enhanced?: boolean;
273
-
274
- /**
275
- * Amount of search context retrieved: low (cost-saving), medium (balanced), high
276
- * (comprehensive)
277
- */
381
+ image_results_enhanced_relevance?: boolean;
382
+
278
383
  search_context_size?: 'low' | 'medium' | 'high';
279
384
 
280
- user_location?: WebSearchOptions.UserLocation;
385
+ search_type?: 'fast' | 'pro' | 'auto';
386
+
387
+ user_location?: WebSearchOptions.UserLocation | null;
281
388
  }
282
389
 
283
390
  export namespace WebSearchOptions {
284
391
  export interface UserLocation {
285
392
  city?: string | null;
286
393
 
287
- /**
288
- * Two-letter ISO country code
289
- */
290
394
  country?: string | null;
291
395
 
292
396
  latitude?: number | null;
293
397
 
294
398
  longitude?: number | null;
295
399
 
296
- /**
297
- * State/province name
298
- */
299
400
  region?: string | null;
300
401
  }
301
402
  }
302
403
  }
303
404
  }
304
405
 
305
- export interface CompletionListParams {
406
+ export interface CompletionGetParams {
407
+ /**
408
+ * Query param:
409
+ */
410
+ local_mode?: boolean;
411
+
412
+ /**
413
+ * Header param:
414
+ */
415
+ 'x-client-env'?: string;
416
+
417
+ /**
418
+ * Header param:
419
+ */
420
+ 'x-client-name'?: string;
421
+
422
+ /**
423
+ * Header param:
424
+ */
425
+ 'x-request-time'?: string;
426
+
306
427
  /**
307
- * Maximum number of requests to return
428
+ * Header param:
308
429
  */
309
- limit?: number;
430
+ 'x-usage-tier'?: string;
310
431
 
311
432
  /**
312
- * Token for fetching the next page of results
433
+ * Header param:
313
434
  */
314
- next_token?: string;
435
+ 'x-user-id'?: string;
315
436
  }
316
437
 
317
438
  export declare namespace Completions {
@@ -320,6 +441,6 @@ export declare namespace Completions {
320
441
  type CompletionListResponse as CompletionListResponse,
321
442
  type CompletionGetResponse as CompletionGetResponse,
322
443
  type CompletionCreateParams as CompletionCreateParams,
323
- type CompletionListParams as CompletionListParams,
444
+ type CompletionGetParams as CompletionGetParams,
324
445
  };
325
446
  }
@@ -7,5 +7,5 @@ export {
7
7
  type CompletionListResponse,
8
8
  type CompletionGetResponse,
9
9
  type CompletionCreateParams,
10
- type CompletionListParams,
10
+ type CompletionGetParams,
11
11
  } from './completions';