@perplexity-ai/perplexity_ai 0.2.1 → 0.3.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 (59) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/client.d.mts +4 -3
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +4 -3
  5. package/client.d.ts.map +1 -1
  6. package/package.json +1 -1
  7. package/resources/async/chat/chat.d.mts +2 -2
  8. package/resources/async/chat/chat.d.mts.map +1 -1
  9. package/resources/async/chat/chat.d.ts +2 -2
  10. package/resources/async/chat/chat.d.ts.map +1 -1
  11. package/resources/async/chat/completions.d.mts +161 -134
  12. package/resources/async/chat/completions.d.mts.map +1 -1
  13. package/resources/async/chat/completions.d.ts +161 -134
  14. package/resources/async/chat/completions.d.ts.map +1 -1
  15. package/resources/async/chat/completions.js +25 -7
  16. package/resources/async/chat/completions.js.map +1 -1
  17. package/resources/async/chat/completions.mjs +25 -7
  18. package/resources/async/chat/completions.mjs.map +1 -1
  19. package/resources/async/chat/index.d.mts +1 -1
  20. package/resources/async/chat/index.d.mts.map +1 -1
  21. package/resources/async/chat/index.d.ts +1 -1
  22. package/resources/async/chat/index.d.ts.map +1 -1
  23. package/resources/chat/completions.d.mts +116 -83
  24. package/resources/chat/completions.d.mts.map +1 -1
  25. package/resources/chat/completions.d.ts +116 -83
  26. package/resources/chat/completions.d.ts.map +1 -1
  27. package/resources/chat/completions.js +1 -2
  28. package/resources/chat/completions.js.map +1 -1
  29. package/resources/chat/completions.mjs +1 -2
  30. package/resources/chat/completions.mjs.map +1 -1
  31. package/resources/content.d.mts +1 -28
  32. package/resources/content.d.mts.map +1 -1
  33. package/resources/content.d.ts +1 -28
  34. package/resources/content.d.ts.map +1 -1
  35. package/resources/content.js +1 -1
  36. package/resources/content.mjs +1 -1
  37. package/resources/search.d.mts +1 -70
  38. package/resources/search.d.mts.map +1 -1
  39. package/resources/search.d.ts +1 -70
  40. package/resources/search.d.ts.map +1 -1
  41. package/resources/search.js +1 -1
  42. package/resources/search.mjs +1 -1
  43. package/resources/shared.d.mts +310 -25
  44. package/resources/shared.d.mts.map +1 -1
  45. package/resources/shared.d.ts +310 -25
  46. package/resources/shared.d.ts.map +1 -1
  47. package/src/client.ts +4 -3
  48. package/src/resources/async/chat/chat.ts +2 -2
  49. package/src/resources/async/chat/completions.ts +265 -142
  50. package/src/resources/async/chat/index.ts +1 -1
  51. package/src/resources/chat/completions.ts +183 -85
  52. package/src/resources/content.ts +1 -28
  53. package/src/resources/search.ts +1 -70
  54. package/src/resources/shared.ts +434 -25
  55. package/src/version.ts +1 -1
  56. package/version.d.mts +1 -1
  57. package/version.d.ts +1 -1
  58. package/version.js +1 -1
  59. package/version.mjs +1 -1
@@ -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,291 @@ 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
+ return_videos?: boolean | null;
265
+
266
+ safe_search?: boolean | null;
237
267
 
238
- /**
239
- * Only include content published after this date (YYYY-MM-DD)
240
- */
241
268
  search_after_date_filter?: string | null;
242
269
 
243
- /**
244
- * Only include content published before this date (YYYY-MM-DD)
245
- */
246
270
  search_before_date_filter?: string | null;
247
271
 
248
- /**
249
- * List of domains to limit search results to. Use '-' prefix to exclude domains
250
- */
251
272
  search_domain_filter?: Array<string> | null;
252
273
 
253
- /**
254
- * Type of search: 'web' for general, 'academic' for scholarly, 'sec' for SEC
255
- * filings
256
- */
274
+ search_internal_properties?: { [key: string]: unknown } | null;
275
+
257
276
  search_mode?: 'web' | 'academic' | 'sec' | null;
258
277
 
259
- /**
260
- * Filter results by how recently they were published
261
- */
262
278
  search_recency_filter?: 'hour' | 'day' | 'week' | 'month' | 'year' | null;
263
279
 
280
+ search_tenant?: string | null;
281
+
282
+ stop?: string | Array<string> | null;
283
+
284
+ stream?: boolean | null;
285
+
286
+ temperature?: number | null;
287
+
288
+ tool_choice?: 'none' | 'auto' | 'required' | null;
289
+
290
+ tools?: Array<Request.Tool> | null;
291
+
292
+ top_k?: number | null;
293
+
294
+ top_logprobs?: number | null;
295
+
296
+ top_p?: number | null;
297
+
298
+ updated_after_timestamp?: number | null;
299
+
300
+ updated_before_timestamp?: number | null;
301
+
264
302
  web_search_options?: Request.WebSearchOptions;
265
303
  }
266
304
 
267
305
  export namespace Request {
306
+ export interface DebugParams {
307
+ summarizer_model_override?: string | null;
308
+
309
+ summarizer_prompt_override?: string | null;
310
+ }
311
+
312
+ export interface ResponseFormatText {
313
+ type: 'text';
314
+ }
315
+
316
+ export interface ResponseFormatJsonSchema {
317
+ json_schema: ResponseFormatJsonSchema.JsonSchema;
318
+
319
+ type: 'json_schema';
320
+ }
321
+
322
+ export namespace ResponseFormatJsonSchema {
323
+ export interface JsonSchema {
324
+ schema: { [key: string]: unknown };
325
+
326
+ description?: string | null;
327
+
328
+ name?: string | null;
329
+
330
+ strict?: boolean | null;
331
+ }
332
+ }
333
+
334
+ export interface ResponseFormatRegex {
335
+ regex: ResponseFormatRegex.Regex;
336
+
337
+ type: 'regex';
338
+ }
339
+
340
+ export namespace ResponseFormatRegex {
341
+ export interface Regex {
342
+ regex: string;
343
+
344
+ description?: string | null;
345
+
346
+ name?: string | null;
347
+
348
+ strict?: boolean | null;
349
+ }
350
+ }
351
+
352
+ export interface Tool {
353
+ function: Tool.Function;
354
+
355
+ type: 'function';
356
+ }
357
+
358
+ export namespace Tool {
359
+ export interface Function {
360
+ description: string;
361
+
362
+ name: string;
363
+
364
+ parameters: Function.Parameters;
365
+
366
+ strict?: boolean | null;
367
+ }
368
+
369
+ export namespace Function {
370
+ export interface Parameters {
371
+ properties: { [key: string]: unknown };
372
+
373
+ type: string;
374
+
375
+ additional_properties?: boolean | null;
376
+
377
+ required?: Array<string> | null;
378
+ }
379
+ }
380
+ }
381
+
268
382
  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
- */
383
+ image_results_enhanced_relevance?: boolean;
384
+
278
385
  search_context_size?: 'low' | 'medium' | 'high';
279
386
 
280
- user_location?: WebSearchOptions.UserLocation;
387
+ search_type?: 'fast' | 'pro' | 'auto';
388
+
389
+ user_location?: WebSearchOptions.UserLocation | null;
281
390
  }
282
391
 
283
392
  export namespace WebSearchOptions {
284
393
  export interface UserLocation {
285
394
  city?: string | null;
286
395
 
287
- /**
288
- * Two-letter ISO country code
289
- */
290
396
  country?: string | null;
291
397
 
292
398
  latitude?: number | null;
293
399
 
294
400
  longitude?: number | null;
295
401
 
296
- /**
297
- * State/province name
298
- */
299
402
  region?: string | null;
300
403
  }
301
404
  }
302
405
  }
303
406
  }
304
407
 
305
- export interface CompletionListParams {
408
+ export interface CompletionGetParams {
409
+ /**
410
+ * Query param:
411
+ */
412
+ local_mode?: boolean;
413
+
414
+ /**
415
+ * Header param:
416
+ */
417
+ 'x-client-env'?: string;
418
+
419
+ /**
420
+ * Header param:
421
+ */
422
+ 'x-client-name'?: string;
423
+
424
+ /**
425
+ * Header param:
426
+ */
427
+ 'x-request-time'?: string;
428
+
306
429
  /**
307
- * Maximum number of requests to return
430
+ * Header param:
308
431
  */
309
- limit?: number;
432
+ 'x-usage-tier'?: string;
310
433
 
311
434
  /**
312
- * Token for fetching the next page of results
435
+ * Header param:
313
436
  */
314
- next_token?: string;
437
+ 'x-user-id'?: string;
315
438
  }
316
439
 
317
440
  export declare namespace Completions {
@@ -320,6 +443,6 @@ export declare namespace Completions {
320
443
  type CompletionListResponse as CompletionListResponse,
321
444
  type CompletionGetResponse as CompletionGetResponse,
322
445
  type CompletionCreateParams as CompletionCreateParams,
323
- type CompletionListParams as CompletionListParams,
446
+ type CompletionGetParams as CompletionGetParams,
324
447
  };
325
448
  }
@@ -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';