@saplingai/sapling-js 1.0.53 → 1.0.55

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.
@@ -23,11 +23,44 @@ export type AdvancedEditOptions = {
23
23
  export type ConstructorOptions = {
24
24
  timeout?: number,
25
25
  hostname?: string,
26
+ /** API path override. Leading and trailing slashes are optional. */
26
27
  pathname?: string,
27
- }
28
+ /**
29
+ * When true, every request carries the API's `return_usage: true` flag and
30
+ * every successful JSON-object response additionally reports the usage the
31
+ * request submitted for metering as a top-level `usage` field (see
32
+ * `ApiUsage`). Defaults to false.
33
+ */
34
+ returnUsage?: boolean,
35
+ }
36
+
37
+ /**
38
+ * Usage a request submitted for metering, reported when the client is
39
+ * constructed with `returnUsage: true`. `characters` is the count the request
40
+ * submitted for billing (one count per DISTINCT item of a batch request;
41
+ * 0 for unbilled requests). It is captured before the billing pipeline's
42
+ * dedup window applies, so it is an upper bound on the final charge.
43
+ */
44
+ export type ApiUsage = {
45
+ characters: number;
46
+ }
47
+
48
+ /**
49
+ * A top-level API response with the optional `usage` report attached
50
+ * (present only on successful responses when the client was constructed with
51
+ * `returnUsage: true`). Batch responses carry it on the wrapper object, not
52
+ * on the per-item results.
53
+ */
54
+ export type WithUsage<T> = T & { usage?: ApiUsage };
55
+
56
+ /** English varieties the API accepts for `variety`. `string & {}` keeps the
57
+ * literals as autocomplete hints while still accepting any string. */
58
+ export type EnglishVariety = 'us-variety' | 'gb-variety' | 'au-variety' | 'ca-variety'
59
+ | 's-variety' | 't-variety' | 'null-variety' | (string & {});
28
60
 
29
61
  export type EditOptions = {
30
- variety?: string,
62
+ /** English variety to enforce. The API rejects other values with a 400. */
63
+ variety?: EnglishVariety,
31
64
  autoApply?: boolean,
32
65
  lang?: string,
33
66
  medical?: boolean,
@@ -37,14 +70,112 @@ export type EditOptions = {
37
70
  includeErrorCategories?: boolean,
38
71
  }
39
72
 
73
+ /** One suggested edit. `start`/`end` are offsets into `sentence`; add
74
+ * `sentence_start` to get offsets into the submitted text. */
75
+ export type SpellcheckEdit = {
76
+ /** Opaque edit id; pass to acceptEdit()/rejectEdit(). */
77
+ id: string,
78
+ /** The unedited sentence containing the edit. */
79
+ sentence: string,
80
+ sentence_start: number,
81
+ start: number,
82
+ end: number,
83
+ replacement: string,
84
+ }
85
+
86
+ export type Edit = SpellcheckEdit & {
87
+ /** Error type (see the API's Error Categories page). Omitted when
88
+ * `includeErrorCategories` is false. */
89
+ error_type?: string,
90
+ general_error_type?: string,
91
+ /** Explanation for some edits; advanced edits carry their own (may be null). */
92
+ description?: string | null,
93
+ }
94
+
95
+ /** Why some sentences are missing model edits. */
96
+ export type DegradedReason = 'model_timeout' | 'model_unavailable' | 'model_error';
97
+
98
+ /**
99
+ * Present only on a partial result: a model stage could not process some
100
+ * sentences in time, so those sentences may be missing some or all of their
101
+ * edits. Counts only: the response does not say which sentences, so retry the
102
+ * whole request after a short backoff for a complete result. A total failure
103
+ * is an HTTP 503 with `Retry-After` instead.
104
+ */
105
+ export type Degraded = {
106
+ sentences_degraded: number,
107
+ sentences_total: number,
108
+ reason: DegradedReason,
109
+ }
110
+
111
+ /** A sentence the API skipped without checking. */
112
+ export type IgnoredSentence = {
113
+ sentence: string,
114
+ reason: 'SENTENCE_EXCEEDS_MAX_LENGTH' | 'UNRECOGNIZED_CHARACTER_SET' | 'INVALID_TOKENS_FOUND',
115
+ }
116
+
117
+ export type EditsResponse = {
118
+ /** Sorted by position in the text. */
119
+ edits: Edit[],
120
+ /** The detected language; only when `lang: 'auto'` was sent. */
121
+ lang?: string,
122
+ /** The text with every edit applied; only when `autoApply: true`. Advanced edits
123
+ * are never applied. */
124
+ applied_text?: string,
125
+ /** Set with `applied_text` when the text contains HTML tags, which auto-apply
126
+ * does not account for. */
127
+ warning?: string,
128
+ 'ignored-sentences'?: IgnoredSentence[],
129
+ degraded?: Degraded,
130
+ }
131
+
132
+ export type SpellcheckResponse = {
133
+ edits: SpellcheckEdit[],
134
+ /** The detected language; only when `lang: 'auto'` was sent. */
135
+ lang?: string,
136
+ /** Misspelled word -> ranked candidate corrections; only with `multipleEdits: true`
137
+ * (empty when the neural spellchecker served the request). */
138
+ candidates?: Record<string, string[]>,
139
+ /** Echo of the `userData` option, when sent. */
140
+ user_data?: unknown,
141
+ /** Only when `autoApply: true`. */
142
+ applied_text?: string,
143
+ warning?: string,
144
+ degraded?: Degraded,
145
+ }
146
+
40
147
  export type AIDetectOptions = {
41
148
  /** Include `sentence_scores` (server default true). */
42
149
  sent_scores?: boolean,
43
150
  /** Include `score_string`, an HTML heatmap of the scored text. */
44
151
  score_string?: boolean,
45
- /** Pin a detector model version (e.g. `'20251027'`); omitted = current default. */
152
+ /** Pin a detector model version (e.g. `'20260820'`, or `'ml20261104'` for the current multilingual
153
+ * model; the previous multilingual models `'ml20261009'`, `'ml20261031'`, `'ml20261102'` and `'ml20261103'` stay pinnable); omitted = current default, with text detected as `ar`/`de`/`es`/`fr`/`it`/`ja`/`ko`/`nl`/`pl`/`pt`/`ro`/`ru`/`sv`/`tr`/`zh`
154
+ * routed to the multilingual model. A pin always wins over that routing and over `lang`. */
46
155
  version?: string,
47
- }
156
+ /** Language of the text: `'en'`, `'ar'`, `'de'`, `'es'`, `'fr'`, `'it'`, `'ja'`, `'ko'`, `'nl'`, `'pl'`, `'pt'`, `'ro'`, `'ru'`, `'sv'`, `'tr'` or `'zh'`
157
+ * (case-insensitive; region subtags such as `'pt-BR'` are accepted). Picks that language's
158
+ * model instead of relying on detection, which helps with short texts; omit it (or pass
159
+ * `'auto'`) to detect.
160
+ * Other languages are rejected with a 400. Applies to every item of a batch. */
161
+ lang?: string,
162
+ /** Keep no copy of the text: the result is still scored and billed (repeats within the
163
+ * deduplication window are still not billed twice), but it is not written to the shared
164
+ * result cache and usage is logged without the text. Default false; always on for teams with
165
+ * data retention disabled. Applies to every item of a batch. */
166
+ zero_retention?: boolean,
167
+ /** Also save the result as a shareable report and return its link in `report`. A single
168
+ * text only (not a batch). The report is saved to your AI detector history, where you can
169
+ * revoke the link; anyone with the link can view the text and its scores until it is
170
+ * revoked or expires 90 days after creation. Requires your private API key (OAuth access
171
+ * tokens and public API keys get a 400, as does combining it with `zero_retention`). When
172
+ * no report can be made, `report` is null and `report_skip_reason` says why; the request
173
+ * is still scored and billed. */
174
+ create_report?: boolean,
175
+ }
176
+
177
+ /** aidetect() batch options: `create_report` is single-text only. */
178
+ export type AIDetectBatchOptions = Omit<AIDetectOptions, 'create_report'>;
48
179
 
49
180
  export type AIDetectSentenceScore = {
50
181
  sentence: string;
@@ -63,27 +194,109 @@ export type AIDetectLanguage = {
63
194
  confidence: number;
64
195
  }
65
196
 
197
+ /** A run of consecutive sentences scoring >= 0.5. */
198
+ export type AIDetectSegment = {
199
+ /** Offsets into the response `text` (`end` exclusive), in Unicode code points like
200
+ * `AIDetectSentenceScore`. */
201
+ start: number;
202
+ end: number;
203
+ /** Mean score of the run's sentences, weighted by their length. */
204
+ score: number;
205
+ }
206
+
207
+ /** `short_text`: under 500 characters. `list_format`: mostly bullet or numbered lines. */
208
+ export type AIDetectLowConfidenceReason = 'short_text' | 'list_format';
209
+
66
210
  export type AIDetectResponse = {
67
211
  /** 0 (likely human-written) to 1 (likely AI-generated). */
68
212
  score: number;
69
213
  /** Share of the text in sentences scoring >= 0.5 (flags partially
70
214
  * AI-written documents); null when nothing could be scored. */
71
215
  ai_fraction: number | null;
216
+ /** Plain-language summary of `score` and `ai_fraction`: `'ai'` when `ai_fraction` >= 0.8
217
+ * and `score` >= 0.5; otherwise `'mixed'` when `ai_fraction` >= 0.2 or `score` >= 0.5;
218
+ * otherwise `'human'` (with a null `ai_fraction`, `'ai'` or `'human'` by `score` alone).
219
+ * Omitted when the text could not be scored. */
220
+ verdict?: 'human' | 'mixed' | 'ai';
221
+ /** The AI-scored passages, in text order; empty when no sentence scores >= 0.5. Also sent
222
+ * with `sent_scores: false`; omitted when sentence offsets are unavailable. */
223
+ segments?: AIDetectSegment[];
224
+ /** True when the input is of a kind with a higher false-positive rate (see
225
+ * `low_confidence_reasons`), so hedge the result rather than show a bare score. */
226
+ low_confidence: boolean;
227
+ /** Empty when `low_confidence` is false. */
228
+ low_confidence_reasons: AIDetectLowConfidenceReason[];
72
229
  text: string;
73
230
  tokens: string[];
74
231
  token_probs: number[];
75
- /** The pinned `version` when one was requested, otherwise an opaque
76
- * identifier of the default model — log it, don't parse it. */
232
+ /** The pinned `version` when one was requested; `'ml20261104'` when unpinned text was
233
+ * detected as (or `lang` named) `ar`/`de`/`es`/`fr`/`it`/`ja`/`ko`/`nl`/`pl`/`pt`/`ro`/`ru`/`sv`/`tr`/`zh` and scored by the
234
+ * multilingual model; otherwise an opaque identifier of the default model — log it, don't
235
+ * parse it. */
77
236
  version: string;
78
237
  /** Present unless `sent_scores: false`. */
79
238
  sentence_scores?: AIDetectSentenceScore[];
80
239
  /** Present when `score_string: true`. */
81
240
  score_string?: string;
82
- /** Advisory detected language; omitted unless detection is high-confidence.
83
- * The detector is trained on English. */
241
+ /** Advisory detected language; omitted unless detection is high-confidence. Always the
242
+ * detected language, even when `lang` was sent, so a mismatch is visible.
243
+ * English plus `ar`, `de`, `es`, `fr`, `it`, `ja`, `ko`, `nl`, `pl`, `pt`, `ro`, `ru`, `sv`,
244
+ * `tr` and `zh` (routed to the multilingual model) are supported; other languages are scored by the English model and are less
245
+ * reliable. */
84
246
  language?: AIDetectLanguage;
85
247
  }
86
248
 
249
+ /** The public report link minted by `create_report: true`. */
250
+ export type AIDetectReport = {
251
+ /** AI detector history entry id (the report is listed in your dashboard history). */
252
+ id: string;
253
+ /** Public report link. */
254
+ url: string;
255
+ /** ISO 8601 timestamp. */
256
+ shared_at: string;
257
+ /** ISO 8601 timestamp: when the link stops resolving unless revoked or deleted sooner. */
258
+ expires_at: string;
259
+ }
260
+
261
+ /** Why `report` is null: `nonpersist` (team keeps no data), `disabled` (AI detector history
262
+ * off), `text_not_retained` (history keeps no text), `unconfirmed_email`, `quota` (history
263
+ * full), `unscorable`, `error`. */
264
+ export type AIDetectReportSkipReason = 'nonpersist' | 'disabled' | 'text_not_retained'
265
+ | 'unconfirmed_email' | 'quota' | 'unscorable' | 'error';
266
+
267
+ /** Added to single-text responses only when `create_report: true` was sent. */
268
+ export type AIDetectReportFields = {
269
+ /** null when no report was made (see `report_skip_reason`). */
270
+ report?: AIDetectReport | null;
271
+ /** Present only when `report` is null. */
272
+ report_skip_reason?: AIDetectReportSkipReason;
273
+ }
274
+
275
+ /** fileAidetect() always scores with sentence scores and score_string enabled. */
276
+ export type FileAIDetectResponse = AIDetectResponse
277
+ & Required<Pick<AIDetectResponse, 'sentence_scores' | 'score_string'>>
278
+ & AIDetectReportFields;
279
+
280
+ export type URLAIDetectSource = {
281
+ /** Final URL after redirects. */
282
+ url: string;
283
+ /** The page's og:title, <title> or first <h1> (a linked document's file name); empty
284
+ * when there is none. */
285
+ title: string;
286
+ /** The response's media type, e.g. `'text/html'` or `'application/pdf'`. */
287
+ content_type: string;
288
+ /** Characters scored (and billed). */
289
+ characters: number;
290
+ /** True when the page (2MB of HTML), document (15MB) or text (200,000 characters) was cut
291
+ * off, so only a prefix was scored. */
292
+ truncated: boolean;
293
+ }
294
+
295
+ /** urlAidetect(): the aidetect() response plus where the scored text came from. */
296
+ export type URLAIDetectResponse = AIDetectResponse & AIDetectReportFields & {
297
+ source: URLAIDetectSource;
298
+ }
299
+
87
300
  export type AIDetectBatchResponse = {
88
301
  results: AIDetectResponse[];
89
302
  }
@@ -129,6 +342,61 @@ export type DeleteStyleguideRulesetResponse = {
129
342
  deleted: string;
130
343
  }
131
344
 
345
+ export type ChunkOptions = {
346
+ step_size?: number;
347
+ }
348
+
349
+ export type ChunkResponse = {
350
+ chunks: string[];
351
+ }
352
+
353
+ export type JdMatchLevel = 'low' | 'moderate' | 'high';
354
+
355
+ export type JdMatchMatchedKeyword = {
356
+ term: string;
357
+ job_description_count: number;
358
+ resume_count: number;
359
+ }
360
+
361
+ export type JdMatchMissingKeyword = {
362
+ term: string;
363
+ job_description_count: number;
364
+ }
365
+
366
+ export type JdMatchCopiedSpan = {
367
+ /** Offsets into the submitted resume (`end` exclusive), in Unicode code points —
368
+ * slice with `Array.from(text)` if it may contain emoji. */
369
+ start: number;
370
+ end: number;
371
+ text: string;
372
+ words: number;
373
+ }
374
+
375
+ /** jdMatch(): a text overlap report. It says nothing about who wrote the resume. */
376
+ export type JdMatchResponse = {
377
+ /** 0–1. A heuristic over keyword coverage and copying, not a probability. */
378
+ score: number;
379
+ level: JdMatchLevel;
380
+ keyword_coverage: number;
381
+ matched_keywords: JdMatchMatchedKeyword[];
382
+ missing_keywords: JdMatchMissingKeyword[];
383
+ /** Share of the resume's words inside a copied span. */
384
+ copied_fraction: number;
385
+ /** Whether the resume shares any run of 6+ words verbatim with the posting. */
386
+ has_copied_span: boolean;
387
+ /** At most 50, in document order; `copied_spans_total` has the full count. */
388
+ copied_spans: JdMatchCopiedSpan[];
389
+ copied_spans_total: number;
390
+ resume_words: number;
391
+ job_description_words: number;
392
+ version: string;
393
+ }
394
+
395
+ /** pdfToText()/docxToText(): the document's plain text. */
396
+ export type FileToTextResponse = {
397
+ text: string;
398
+ }
399
+
132
400
  export type AccountBlockedReason =
133
401
  | 'key_expired'
134
402
  | 'subscription_expired'
@@ -141,6 +409,9 @@ export type AccountCreditSummary = {
141
409
  enabled: boolean;
142
410
  currency: string;
143
411
  alert_threshold_percent: number;
412
+ // Prepaid-only account: API access needs a positive credit balance. Sent
413
+ // whether or not `enabled` is true (optional for older on-prem servers).
414
+ credits_only?: boolean;
144
415
  // Present only when `enabled` is true.
145
416
  balance_credits?: number;
146
417
  purchased_credits?: number;
@@ -183,6 +454,85 @@ export type AccountStatusResponse = {
183
454
  };
184
455
  }
185
456
 
457
+ export type ReportingWindowOptions = {
458
+ /** Days before today the window starts (non-negative integer). */
459
+ start_days_back?: number,
460
+ /** Days before today the window ends (non-negative integer). Defaults to 0. */
461
+ end_days_back?: number,
462
+ }
463
+
464
+ export type ApiUsageKeySummary = {
465
+ /** Masked id, `****<last4>-<hash8>`; the raw key is never returned. */
466
+ api_key: string;
467
+ tag: string;
468
+ /** Characters in the window. */
469
+ characters: number;
470
+ /** Monthly character limit; -1 for none. */
471
+ monthly_limit: number | null;
472
+ /** Characters this calendar month. */
473
+ monthly_usage: number;
474
+ /** null when there is no limit. */
475
+ remaining_quota: number | null;
476
+ quota_exceeded: boolean;
477
+ }
478
+
479
+ export type ApiUsageResponse = {
480
+ /** Inclusive ISO dates of the resolved window. */
481
+ start_date: string;
482
+ end_date: string;
483
+ total_characters: number;
484
+ /** At list prices, per (endpoint, month). */
485
+ total_cost_usd: number;
486
+ currency: string;
487
+ /** Keyed by masked key id. */
488
+ by_api_key: Record<string, ApiUsageKeySummary>;
489
+ /** Keyed by endpoint name, e.g. `EDIT`. */
490
+ by_endpoint: Record<string, { characters: number; cost_usd: number }>;
491
+ /** Masked key id → `YYYY-MM-DD` → characters. */
492
+ daily_usage: Record<string, Record<string, number>>;
493
+ /** Masked key id → `YYYY-MM` → characters. */
494
+ monthly_usage: Record<string, Record<string, number>>;
495
+ /** ISO timestamp of the latest usage row in the window, or null. */
496
+ last_updated: string | null;
497
+ /** Omitted for team-scoped keys. Same object as accountStatus()'s `credits`. */
498
+ credit_balance_data?: AccountCreditSummary;
499
+ }
500
+
501
+ export type ApiEndpointUsageInterval = 'Daily' | 'Weekly' | 'Monthly';
502
+
503
+ export type ApiEndpointUsageOptions = ReportingWindowOptions & {
504
+ /** Defaults to 'Daily'. */
505
+ interval?: ApiEndpointUsageInterval,
506
+ }
507
+
508
+ export type ApiEndpointUsageResponse = {
509
+ /** Endpoint name → bucket start (days before today, as a string key) → characters. */
510
+ data: Record<string, Record<string, number>>;
511
+ last_updated: string | null;
512
+ }
513
+
514
+ export type ApiQuotaUsageResponse = {
515
+ /** Monthly character limit; -1 for none. */
516
+ quota: number;
517
+ /** Characters in the window. */
518
+ usage: number;
519
+ /** Suggestions accepted / ignored via acceptEdit()/rejectEdit() since the first of the month. */
520
+ accepts: number;
521
+ ignores: number;
522
+ /** Unix epoch seconds. */
523
+ last_updated: number;
524
+ }
525
+
526
+ export type ApiUserActivityResponse = {
527
+ edits_shown: number;
528
+ edits_accepted: number;
529
+ edits_ignored: number;
530
+ active_users: {
531
+ logged_in: number;
532
+ anonymous: number;
533
+ };
534
+ }
535
+
186
536
  export type SimplifyReadingLevel = 'plain' | 'elementary' | 'middle_school' | 'high_school';
187
537
 
188
538
  export type SimplifyOptions = {
@@ -215,6 +565,43 @@ export type LangdetectOptions = {
215
565
  segments?: boolean,
216
566
  }
217
567
 
568
+ export type LangdetectCandidate = {
569
+ lang: string;
570
+ conf: number;
571
+ name: string | null;
572
+ }
573
+
574
+ export type LangdetectResult = {
575
+ /** ISO 639-1 code of the most likely language. */
576
+ lang: string;
577
+ conf: number;
578
+ name: string | null;
579
+ /** The recommended trust bar: true only when the confidence is high and the text has enough
580
+ * letters. Short inputs like "OK" or "Hola" are never reliable. */
581
+ reliable: boolean;
582
+ /** Dominant writing system as an ISO 15924 code (`Latn`, `Cyrl`, `Arab`, `Hani`, `Jpan`,
583
+ * `Hang`, ...). `Zzzz` when the letters are in an unmapped script; null when the text has no
584
+ * letters. */
585
+ script: string | null;
586
+ /** The top_k most likely languages, best first. */
587
+ candidates: LangdetectCandidate[];
588
+ }
589
+
590
+ export type LangdetectSegment = LangdetectResult & {
591
+ start: number;
592
+ end: number;
593
+ text: string;
594
+ }
595
+
596
+ export type LangdetectResponse = LangdetectResult & {
597
+ /** Present only when the request sent segments: true. */
598
+ segments?: LangdetectSegment[];
599
+ }
600
+
601
+ export type LangdetectBatchResponse = {
602
+ results: LangdetectResponse[];
603
+ }
604
+
218
605
  export type ClassifyLabel = string | { name: string; description?: string };
219
606
 
220
607
  export type ClassifyOptions = {
@@ -371,6 +758,35 @@ export type NERBatchResponse = {
371
758
  results: NERResponse[];
372
759
  }
373
760
 
761
+ export type InclusiveCategory = 'gender' | 'race_ethnicity' | 'disability' | 'age' |
762
+ 'lgbtq' | 'religion' | 'socioeconomic' | 'appearance';
763
+
764
+ export type InclusiveSeverity = 'low' | 'medium' | 'high';
765
+
766
+ export type InclusiveOptions = {
767
+ categories?: InclusiveCategory[],
768
+ }
769
+
770
+ export type InclusiveIssue = {
771
+ category: InclusiveCategory;
772
+ severity: InclusiveSeverity;
773
+ text: string;
774
+ start: number | null;
775
+ end: number | null;
776
+ note: string;
777
+ suggestion: string;
778
+ }
779
+
780
+ export type InclusiveResponse = {
781
+ issues: InclusiveIssue[];
782
+ categories: InclusiveCategory[];
783
+ inclusive: boolean;
784
+ }
785
+
786
+ export type InclusiveBatchResponse = {
787
+ results: InclusiveResponse[];
788
+ }
789
+
374
790
  export type SafetyCategory = 'toxicity' | 'profanity' | 'harassment' | 'hate_speech' |
375
791
  'self_harm' | 'sexual' | 'violence';
376
792
 
@@ -404,7 +820,9 @@ export type SpellcheckOptions = {
404
820
  multipleEdits?: boolean,
405
821
  lang?: string,
406
822
  autoApply?: boolean,
407
- variety?: string,
823
+ /** English variety to enforce. The API rejects other values with a 400. */
824
+ variety?: EnglishVariety,
825
+ /** Arbitrary JSON echoed back as `user_data` on the response. */
408
826
  userData?: any,
409
827
  }
410
828
 
@@ -441,6 +859,36 @@ export type ExtractBatchResponse = {
441
859
  results: ExtractResponse[];
442
860
  }
443
861
 
862
+ /** A document for fileAidetect()/fileExtract()/fileSummarize(): a Blob/File, or the file's bytes (Buffer,
863
+ * Uint8Array, ArrayBuffer). The API picks the format by file extension (.pdf, .docx, .pptx,
864
+ * .odt, .txt, .md, .html, .htm; up to 30MB), so bytes need `options.filename`. */
865
+ export type UploadFile = Blob | ArrayBuffer | ArrayBufferView;
866
+
867
+ export type FileUploadOptions = {
868
+ /** Required unless `file` is a File (whose own name is used otherwise), e.g. 'report.pdf'. */
869
+ filename?: string,
870
+ }
871
+
872
+ export type FileExtractOptions = ExtractOptions & FileUploadOptions;
873
+
874
+ export type FileAIDetectOptions = FileUploadOptions & Pick<AIDetectOptions, 'zero_retention' | 'create_report'>;
875
+
876
+ export type FileExtractDocument = {
877
+ /** The extension the document was read as, e.g. 'pdf'. */
878
+ file_type: string,
879
+ /** Characters of text extracted from the file. */
880
+ characters: number,
881
+ /** Characters read for extraction (at most 10,000) and billed. */
882
+ characters_used: number,
883
+ /** True when the text was cut to its first 10,000 characters; fields stated only
884
+ * later in the document are reported missing. */
885
+ truncated: boolean,
886
+ }
887
+
888
+ export type FileExtractResponse = ExtractResponse & {
889
+ document: FileExtractDocument,
890
+ }
891
+
444
892
  export type TranslateOptions = {
445
893
  source_lang?: string,
446
894
  formality?: 'formal' | 'informal',
@@ -474,6 +922,24 @@ export type SummarizeBatchResponse = {
474
922
  results: SummarizeResponse[];
475
923
  }
476
924
 
925
+ export type FileSummarizeOptions = SummarizeOptions & FileUploadOptions;
926
+
927
+ export type FileSummarizeDocument = {
928
+ /** The extension the document was read as, e.g. 'pdf'. */
929
+ file_type: string,
930
+ /** Characters of text extracted from the file. */
931
+ characters: number,
932
+ /** Characters summarized (at most 20,000) and billed. */
933
+ characters_used: number,
934
+ /** True when the text was cut to its first 20,000 characters; the summary covers
935
+ * only that part of the document. */
936
+ truncated: boolean,
937
+ }
938
+
939
+ export type FileSummarizeResponse = SummarizeResponse & {
940
+ document: FileSummarizeDocument,
941
+ }
942
+
477
943
  export type RephraseMapping =
478
944
  'paraphrase' | 'passive_to_active' | 'active_to_passive' | 'informal_to_formal' |
479
945
  'formal_to_informal' | 'sentence_split' | 'reword' | 'generate_title' | 'generate_acronym' |
@@ -513,6 +979,31 @@ export type RephraseResponse = {
513
979
  results: RephraseResult[],
514
980
  }
515
981
 
982
+ export type CompleteResponse = {
983
+ /** The predicted continuation of `query`. */
984
+ output: string,
985
+ /** The part of the sent query the prediction continues: the API keeps only the text
986
+ * after the last run of three spaces. */
987
+ query: string,
988
+ /** Pass to acceptComplete() as `completeUUID`, with this `query` and `output`. */
989
+ hash: string,
990
+ }
991
+
992
+ export type AcceptCompleteResponse = {
993
+ result: 'success',
994
+ }
995
+
996
+ /** [probability, tone name, emoji] triples, e.g. [1.0, 'neutral', '😐']. */
997
+ export type ToneScores = Array<[number, string, string]>;
998
+
999
+ export type ToneResponse = {
1000
+ /** Up to 3 tones for the whole text, most likely first; the probabilities sum to 1. */
1001
+ overall: ToneScores,
1002
+ /** One entry per sentence, aligned with `sents`. */
1003
+ results: ToneScores[],
1004
+ sents: string[],
1005
+ }
1006
+
516
1007
  export type SentimentLabel = 'POSITIVE' | 'NEUTRAL' | 'NEGATIVE';
517
1008
 
518
1009
  /** [probability, label] pairs, most likely first. */
@@ -573,71 +1064,169 @@ export type AddDictionaryEntryOptions = {
573
1064
  case_sensitive?: boolean,
574
1065
  }
575
1066
 
1067
+ export type CustomMapping = {
1068
+ id: string,
1069
+ /** The text to match; `^` / `$` anchor to a sentence's start / end, `#` matches a number. */
1070
+ entry: string,
1071
+ /** The replacement suggested; a `#` substitutes the matched number back in. */
1072
+ mapping: string,
1073
+ /** Shown with the suggestion; empty string or null (older rules) when none was set. */
1074
+ description: string | null,
1075
+ case_sensitive: boolean,
1076
+ /** RFC 1123 timestamp, e.g. "Wed, 07 Oct 2020 21:15:47 GMT". */
1077
+ created_at: string,
1078
+ updated_at: string,
1079
+ }
1080
+
1081
+ export type CustomMappingsResponse = {
1082
+ /** Sorted by entry. */
1083
+ custom_mappings: CustomMapping[],
1084
+ }
1085
+
1086
+ export type AddCustomMappingOptions = {
1087
+ /** Shown to the end user with the suggestion; a mapping with a description cannot be ignored. */
1088
+ description?: string,
1089
+ /** Defaults to true. */
1090
+ case_sensitive?: boolean,
1091
+ }
1092
+
1093
+ export type CustomFilter = {
1094
+ id: string,
1095
+ /** The original text of the suppressed edits; empty string is a wildcard. */
1096
+ input: string,
1097
+ /** The replacement text of the suppressed edits; empty string is a wildcard. */
1098
+ output: string,
1099
+ case_sensitive: boolean,
1100
+ /** RFC 1123 timestamp, e.g. "Wed, 07 Oct 2020 21:15:47 GMT". */
1101
+ created_at: string,
1102
+ updated_at: string,
1103
+ }
1104
+
1105
+ export type CustomFiltersResponse = {
1106
+ /** Sorted by input. */
1107
+ custom_filters: CustomFilter[],
1108
+ }
1109
+
1110
+ export type AddCustomFilterOptions = {
1111
+ /** Defaults to true. */
1112
+ case_sensitive?: boolean,
1113
+ }
1114
+
576
1115
  export type UserDetails = {
577
1116
  userId?: string,
578
1117
  anonUser?: boolean,
579
1118
  }
580
1119
 
1120
+ export type VersionResponse = {
1121
+ /** Release version, for example `'2026.6'`. */
1122
+ version: string;
1123
+ /** Build identifier; `'unknown'` when the image carries no build number. */
1124
+ build: string;
1125
+ };
1126
+
1127
+ export type LivenessResponse = {
1128
+ msg: 'alive';
1129
+ };
1130
+
581
1131
  export declare class Client {
582
1132
  constructor(apiKey: string, options?: ConstructorOptions);
583
1133
 
584
- edits(text: string, sessionId?: string, options?: EditOptions, userDetails?: UserDetails): Promise<AxiosResponse>;
1134
+ edits(text: string, sessionId?: string, options?: EditOptions, userDetails?: UserDetails): Promise<AxiosResponse<WithUsage<EditsResponse>>>;
585
1135
  acceptEdit(editUUID: string, sessionId?: string, userId?: string): Promise<AxiosResponse>;
586
1136
  rejectEdit(editUUID: string, sessionId?: string, userId?: string): Promise<AxiosResponse>;
587
1137
 
588
- spellcheck(text: string, sessionId?: string, options?: SpellcheckOptions, userDetails?: UserDetails): Promise<AxiosResponse>;
589
-
590
- complete(query: string, sessionId?: string): Promise<AxiosResponse>;
591
- acceptComplete(completeUUID: string, query: string, completion: string, sessionId?: string): Promise<AxiosResponse>;
592
- tone(text: string): Promise<AxiosResponse>;
593
- rephrase(text: string, options?: RephraseOptions): Promise<AxiosResponse<RephraseResponse>>;
1138
+ spellcheck(text: string, sessionId?: string, options?: SpellcheckOptions, userDetails?: UserDetails): Promise<AxiosResponse<WithUsage<SpellcheckResponse>>>;
1139
+
1140
+ /** `data` is `[]` when no completion is available (the prediction failed or was too
1141
+ * short). Check `Array.isArray(data)` before reading fields. */
1142
+ complete(query: string, sessionId?: string): Promise<AxiosResponse<WithUsage<CompleteResponse> | never[]>>;
1143
+ /** Pass the `hash`, `query` and `output` that complete() returned. A changed `query` or
1144
+ * `completion` gets a 400 ("Arguments do not match hash."). */
1145
+ acceptComplete(completeUUID: string, query: string, completion: string, sessionId?: string): Promise<AxiosResponse<WithUsage<AcceptCompleteResponse>>>;
1146
+ /** `data` is `[]` when the API cannot split the text into sentences. Check
1147
+ * `Array.isArray(data)` before reading fields. */
1148
+ tone(text: string): Promise<AxiosResponse<WithUsage<ToneResponse> | never[]>>;
1149
+ rephrase(text: string, options?: RephraseOptions): Promise<AxiosResponse<WithUsage<RephraseResponse>>>;
594
1150
  /** A text with no sentences (e.g. markup or punctuation only) gets a 204 with an empty
595
1151
  * body, so `data` is `''` then; a text the API cannot split into sentences gets a 200
596
1152
  * with `[]`. Check `Array.isArray(data) || !data` before reading fields. */
597
- sentiment(text: string): Promise<AxiosResponse<SentimentResponse | '' | never[]>>;
598
- statistics(text: string, options?: StatisticsOptions): Promise<AxiosResponse<StatisticsResponse>>;
599
- similarTerms(query: string): Promise<AxiosResponse<SimilarTermsResponse>>;
600
- profanity(text: string): Promise<AxiosResponse<ProfanityResponse>>;
1153
+ sentiment(text: string): Promise<AxiosResponse<WithUsage<SentimentResponse> | '' | never[]>>;
1154
+ statistics(text: string, options?: StatisticsOptions): Promise<AxiosResponse<WithUsage<StatisticsResponse>>>;
1155
+ similarTerms(query: string): Promise<AxiosResponse<WithUsage<SimilarTermsResponse>>>;
1156
+ profanity(text: string): Promise<AxiosResponse<WithUsage<ProfanityResponse>>>;
601
1157
  dictionaryEntries(): Promise<AxiosResponse<DictionaryEntry[]>>;
602
- addDictionaryEntry(entry: string, options?: AddDictionaryEntryOptions): Promise<AxiosResponse<DictionaryEntry>>;
1158
+ addDictionaryEntry(entry: string, options?: AddDictionaryEntryOptions): Promise<AxiosResponse<WithUsage<DictionaryEntry>>>;
603
1159
  /** Answers 204 with an empty body. */
604
1160
  deleteDictionaryEntry(entryId: string): Promise<AxiosResponse<''>>;
605
- extract(text: string, fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<ExtractResponse>>;
606
- extract(texts: string[], fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<ExtractBatchResponse>>;
607
- extract(text: string | string[], fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<ExtractResponse | ExtractBatchResponse>>;
608
- translate(text: string, targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<TranslateResponse>>;
609
- translate(texts: string[], targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<TranslateBatchResponse>>;
610
- translate(text: string | string[], targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<TranslateResponse | TranslateBatchResponse>>;
611
- summarize(text: string, options?: SummarizeOptions): Promise<AxiosResponse<SummarizeResponse>>;
612
- summarize(texts: string[], options?: SummarizeOptions): Promise<AxiosResponse<SummarizeBatchResponse>>;
613
- summarize(text: string | string[], options?: SummarizeOptions): Promise<AxiosResponse<SummarizeResponse | SummarizeBatchResponse>>;
614
-
615
- aidetect(text: string, options?: AIDetectOptions): Promise<AxiosResponse<AIDetectResponse>>;
616
- aidetect(texts: string[], options?: AIDetectOptions): Promise<AxiosResponse<AIDetectBatchResponse>>;
617
- aidetect(text: string | string[], options?: AIDetectOptions): Promise<AxiosResponse<AIDetectResponse | AIDetectBatchResponse>>;
618
- styleguide(text: string, rules: StyleguideRule[] | string): Promise<AxiosResponse<StyleguideResponse>>;
619
- styleguide(texts: string[], rules: StyleguideRule[] | string): Promise<AxiosResponse<StyleguideBatchResponse>>;
620
- styleguide(text: string | string[], rules: StyleguideRule[] | string): Promise<AxiosResponse<StyleguideResponse | StyleguideBatchResponse>>;
621
- styleguideRulesets(): Promise<AxiosResponse<StyleguideRulesetsResponse>>;
622
- saveStyleguideRuleset(name: string, rules: StyleguideRule[]): Promise<AxiosResponse<SaveStyleguideRulesetResponse>>;
623
- deleteStyleguideRuleset(name: string): Promise<AxiosResponse<DeleteStyleguideRulesetResponse>>;
624
- simplify(text: string, options?: SimplifyOptions): Promise<AxiosResponse<SimplifyResponse>>;
625
- simplify(texts: string[], options?: SimplifyOptions): Promise<AxiosResponse<SimplifyBatchResponse>>;
626
- simplify(text: string | string[], options?: SimplifyOptions): Promise<AxiosResponse<SimplifyResponse | SimplifyBatchResponse>>;
627
- langdetect(text: string | string[], options?: LangdetectOptions): Promise<AxiosResponse>;
628
- quality(text: string, options?: QualityOptions): Promise<AxiosResponse<QualityResponse>>;
629
- quality(texts: string[], options?: QualityOptions): Promise<AxiosResponse<QualityBatchResponse>>;
630
- quality(text: string | string[], options?: QualityOptions): Promise<AxiosResponse<QualityResponse | QualityBatchResponse>>;
631
- pii(text: string, options?: PIIOptions): Promise<AxiosResponse<PIIResponse>>;
632
- ner(text: string, options?: NEROptions): Promise<AxiosResponse<NERResponse>>;
633
- ner(texts: string[], options?: NEROptions): Promise<AxiosResponse<NERBatchResponse>>;
634
- ner(text: string | string[], options?: NEROptions): Promise<AxiosResponse<NERResponse | NERBatchResponse>>;
635
- safety(text: string, options?: SafetyOptions): Promise<AxiosResponse<SafetyResponse>>;
636
- safety(texts: string[], options?: SafetyOptions): Promise<AxiosResponse<SafetyBatchResponse>>;
637
- safety(text: string | string[], options?: SafetyOptions): Promise<AxiosResponse<SafetyResponse | SafetyBatchResponse>>;
638
- classify(text: string, labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<ClassifyResponse>>;
639
- classify(texts: string[], labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<ClassifyBatchResponse>>;
640
- classify(text: string | string[], labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<ClassifyResponse | ClassifyBatchResponse>>;
641
- seo(text: string, options?: SeoOptions): Promise<AxiosResponse<SeoResponse>>;
1161
+ customMappings(): Promise<AxiosResponse<WithUsage<CustomMappingsResponse>>>;
1162
+ addCustomMapping(entry: string, mapping: string, options?: AddCustomMappingOptions): Promise<AxiosResponse<WithUsage<CustomMapping>>>;
1163
+ /** Answers 204 with an empty body. */
1164
+ deleteCustomMapping(mappingId: string): Promise<AxiosResponse<''>>;
1165
+ customFilters(): Promise<AxiosResponse<WithUsage<CustomFiltersResponse>>>;
1166
+ addCustomFilter(input: string, output: string, options?: AddCustomFilterOptions): Promise<AxiosResponse<WithUsage<CustomFilter>>>;
1167
+ /** Answers 204 with an empty body. */
1168
+ deleteCustomFilter(filterId: string): Promise<AxiosResponse<''>>;
1169
+ extract(text: string, fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<WithUsage<ExtractResponse>>>;
1170
+ extract(texts: string[], fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<WithUsage<ExtractBatchResponse>>>;
1171
+ extract(text: string | string[], fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<WithUsage<ExtractResponse | ExtractBatchResponse>>>;
1172
+ fileExtract(file: UploadFile, fields: ExtractField[], options?: FileExtractOptions): Promise<AxiosResponse<WithUsage<FileExtractResponse>>>;
1173
+ translate(text: string, targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<WithUsage<TranslateResponse>>>;
1174
+ translate(texts: string[], targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<WithUsage<TranslateBatchResponse>>>;
1175
+ translate(text: string | string[], targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<WithUsage<TranslateResponse | TranslateBatchResponse>>>;
1176
+ summarize(text: string, options?: SummarizeOptions): Promise<AxiosResponse<WithUsage<SummarizeResponse>>>;
1177
+ summarize(texts: string[], options?: SummarizeOptions): Promise<AxiosResponse<WithUsage<SummarizeBatchResponse>>>;
1178
+ summarize(text: string | string[], options?: SummarizeOptions): Promise<AxiosResponse<WithUsage<SummarizeResponse | SummarizeBatchResponse>>>;
1179
+ fileSummarize(file: UploadFile, options?: FileSummarizeOptions): Promise<AxiosResponse<WithUsage<FileSummarizeResponse>>>;
1180
+
1181
+ aidetect(text: string, options?: AIDetectOptions): Promise<AxiosResponse<WithUsage<AIDetectResponse & AIDetectReportFields>>>;
1182
+ aidetect(texts: string[], options?: AIDetectBatchOptions): Promise<AxiosResponse<WithUsage<AIDetectBatchResponse>>>;
1183
+ aidetect(text: string | string[], options?: AIDetectBatchOptions): Promise<AxiosResponse<WithUsage<AIDetectResponse | AIDetectBatchResponse>>>;
1184
+ fileAidetect(file: UploadFile, options?: FileAIDetectOptions): Promise<AxiosResponse<WithUsage<FileAIDetectResponse>>>;
1185
+ urlAidetect(url: string, options?: AIDetectOptions): Promise<AxiosResponse<WithUsage<URLAIDetectResponse>>>;
1186
+ styleguide(text: string, rules: StyleguideRule[] | string): Promise<AxiosResponse<WithUsage<StyleguideResponse>>>;
1187
+ styleguide(texts: string[], rules: StyleguideRule[] | string): Promise<AxiosResponse<WithUsage<StyleguideBatchResponse>>>;
1188
+ styleguide(text: string | string[], rules: StyleguideRule[] | string): Promise<AxiosResponse<WithUsage<StyleguideResponse | StyleguideBatchResponse>>>;
1189
+ styleguideRulesets(): Promise<AxiosResponse<WithUsage<StyleguideRulesetsResponse>>>;
1190
+ saveStyleguideRuleset(name: string, rules: StyleguideRule[]): Promise<AxiosResponse<WithUsage<SaveStyleguideRulesetResponse>>>;
1191
+ deleteStyleguideRuleset(name: string): Promise<AxiosResponse<WithUsage<DeleteStyleguideRulesetResponse>>>;
1192
+ simplify(text: string, options?: SimplifyOptions): Promise<AxiosResponse<WithUsage<SimplifyResponse>>>;
1193
+ simplify(texts: string[], options?: SimplifyOptions): Promise<AxiosResponse<WithUsage<SimplifyBatchResponse>>>;
1194
+ simplify(text: string | string[], options?: SimplifyOptions): Promise<AxiosResponse<WithUsage<SimplifyResponse | SimplifyBatchResponse>>>;
1195
+ langdetect(text: string, options?: LangdetectOptions): Promise<AxiosResponse<WithUsage<LangdetectResponse>>>;
1196
+ langdetect(texts: string[], options?: LangdetectOptions): Promise<AxiosResponse<WithUsage<LangdetectBatchResponse>>>;
1197
+ langdetect(text: string | string[], options?: LangdetectOptions): Promise<AxiosResponse<WithUsage<LangdetectResponse | LangdetectBatchResponse>>>;
1198
+ quality(text: string, options?: QualityOptions): Promise<AxiosResponse<WithUsage<QualityResponse>>>;
1199
+ quality(texts: string[], options?: QualityOptions): Promise<AxiosResponse<WithUsage<QualityBatchResponse>>>;
1200
+ quality(text: string | string[], options?: QualityOptions): Promise<AxiosResponse<WithUsage<QualityResponse | QualityBatchResponse>>>;
1201
+ pii(text: string, options?: PIIOptions): Promise<AxiosResponse<WithUsage<PIIResponse>>>;
1202
+ ner(text: string, options?: NEROptions): Promise<AxiosResponse<WithUsage<NERResponse>>>;
1203
+ ner(texts: string[], options?: NEROptions): Promise<AxiosResponse<WithUsage<NERBatchResponse>>>;
1204
+ ner(text: string | string[], options?: NEROptions): Promise<AxiosResponse<WithUsage<NERResponse | NERBatchResponse>>>;
1205
+ inclusive(text: string, options?: InclusiveOptions): Promise<AxiosResponse<WithUsage<InclusiveResponse>>>;
1206
+ inclusive(texts: string[], options?: InclusiveOptions): Promise<AxiosResponse<WithUsage<InclusiveBatchResponse>>>;
1207
+ inclusive(text: string | string[], options?: InclusiveOptions): Promise<AxiosResponse<WithUsage<InclusiveResponse | InclusiveBatchResponse>>>;
1208
+ safety(text: string, options?: SafetyOptions): Promise<AxiosResponse<WithUsage<SafetyResponse>>>;
1209
+ safety(texts: string[], options?: SafetyOptions): Promise<AxiosResponse<WithUsage<SafetyBatchResponse>>>;
1210
+ safety(text: string | string[], options?: SafetyOptions): Promise<AxiosResponse<WithUsage<SafetyResponse | SafetyBatchResponse>>>;
1211
+ classify(text: string, labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<WithUsage<ClassifyResponse>>>;
1212
+ classify(texts: string[], labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<WithUsage<ClassifyBatchResponse>>>;
1213
+ classify(text: string | string[], labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<WithUsage<ClassifyResponse | ClassifyBatchResponse>>>;
1214
+ seo(text: string, options?: SeoOptions): Promise<AxiosResponse<WithUsage<SeoResponse>>>;
1215
+ jdMatch(text: string, jobDescription: string): Promise<AxiosResponse<WithUsage<JdMatchResponse>>>;
1216
+ chunkText(text: string, maxLength: number, options?: ChunkOptions): Promise<AxiosResponse<WithUsage<ChunkResponse>>>;
1217
+ chunkHtml(html: string, maxLength: number, options?: ChunkOptions): Promise<AxiosResponse<WithUsage<ChunkResponse>>>;
1218
+ /** `file` must be named `*.pdf` (a File's own name, or options.filename). */
1219
+ pdfToText(file: UploadFile, options?: FileUploadOptions): Promise<AxiosResponse<WithUsage<FileToTextResponse>>>;
1220
+ /** `file` must be named `*.docx` (a File's own name, or options.filename). */
1221
+ docxToText(file: UploadFile, options?: FileUploadOptions): Promise<AxiosResponse<WithUsage<FileToTextResponse>>>;
1222
+ /** Not WithUsage<>: public and unbilled, and sends neither the API key nor return_usage. */
1223
+ version(): Promise<AxiosResponse<VersionResponse>>;
1224
+ /** Not WithUsage<>: public and unbilled, and sends neither the API key nor return_usage. */
1225
+ liveness(): Promise<AxiosResponse<LivenessResponse>>;
642
1226
  accountStatus(): Promise<AxiosResponse<AccountStatusResponse>>;
1227
+ apiUsage(options?: ReportingWindowOptions): Promise<AxiosResponse<WithUsage<ApiUsageResponse>>>;
1228
+ apiEndpointUsage(options?: ApiEndpointUsageOptions): Promise<AxiosResponse<WithUsage<ApiEndpointUsageResponse>>>;
1229
+ /** Not WithUsage<>: the response's own `usage` is an integer and return_usage is not sent. */
1230
+ apiQuotaUsage(options?: ReportingWindowOptions): Promise<AxiosResponse<ApiQuotaUsageResponse>>;
1231
+ apiUserActivity(options?: ReportingWindowOptions): Promise<AxiosResponse<WithUsage<ApiUserActivityResponse>>>;
643
1232
  }