tldrapi 0.1.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.
- package/LICENSE +21 -0
- package/README.md +147 -0
- package/dist/client.d.ts +45 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +650 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +95 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +255 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 UnityCubed / TLDRapi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# tldrapi — Node.js / TypeScript SDK for TLDRapi
|
|
2
|
+
|
|
3
|
+
Official Node.js + TypeScript client for the [TLDRapi summarization API](https://tldrapi.com). Summarize text at five quality tiers, 20+ built-in voice styles, custom voices for paid tiers. Typed results, typed errors, retries, zero third-party HTTP dependencies (uses the Node 18+ built-in `fetch`).
|
|
4
|
+
|
|
5
|
+
**TLDRapi is distributed through the RapidAPI marketplace at launch.** Subscribe to the TLDRapi listing on RapidAPI to get your `X-RapidAPI-Key`, then pass it to the client as `rapidapiKey`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install tldrapi
|
|
11
|
+
# or
|
|
12
|
+
pnpm add tldrapi
|
|
13
|
+
# or
|
|
14
|
+
yarn add tldrapi
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Node.js 18+.
|
|
18
|
+
|
|
19
|
+
## Get your app's RapidAPI key
|
|
20
|
+
|
|
21
|
+
1. Sign in at [rapidapi.com](https://rapidapi.com)
|
|
22
|
+
2. Subscribe to the [TLDRapi Summarizer](https://rapidapi.com/thunderAPIs256/api/tldrapi-summarizer) listing (start with **BASIC** — free)
|
|
23
|
+
3. Go to **Console** (top nav) → **Applications** → **Add App** (or open an existing one)
|
|
24
|
+
4. In the App → **Authorizations** tab → click the copy icon next to your Authorization Key
|
|
25
|
+
|
|
26
|
+
That's the app's `X-RapidAPI-Key`. Pass it to the SDK constructor.
|
|
27
|
+
|
|
28
|
+
*Legacy path (deprecated): upper-right (?) → Legacy Developer Dashboard → Add New App → Authorization tab. The new Console path above is simpler.*
|
|
29
|
+
|
|
30
|
+
The Authorization Key field is the same value in both places — RapidAPI just labels it differently depending on which interface you use:
|
|
31
|
+
|
|
32
|
+
**New Console:**
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
**Legacy Developer Dashboard:**
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Quickstart
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { TLDRapi } from 'tldrapi';
|
|
46
|
+
|
|
47
|
+
const client = new TLDRapi({ rapidapiKey: 'YOUR_RAPIDAPI_KEY' });
|
|
48
|
+
|
|
49
|
+
const result = await client.summarize(
|
|
50
|
+
'Some long text here...',
|
|
51
|
+
{ tier: 'standard' }, // 'quick' | 'standard' | 'deep' | 'premium' | 'ultra'
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
console.log(result.summary);
|
|
55
|
+
console.log(`used ${result.usage.outputTokens} output tokens on ${result.usage.modelUsed}`);
|
|
56
|
+
console.log(`request id (for support): ${result.requestId}`);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Or plain JavaScript:
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
const { TLDRapi } = require('tldrapi');
|
|
63
|
+
const client = new TLDRapi({ rapidapiKey: 'YOUR_RAPIDAPI_KEY' });
|
|
64
|
+
const result = await client.summarize('Long text...');
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Handling errors
|
|
68
|
+
|
|
69
|
+
Every failure extends `TLDRapiError`. Catch the base for a safety net, or catch specific subclasses to branch on failure mode.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import {
|
|
73
|
+
TLDRapi, TLDRapiError,
|
|
74
|
+
InsufficientCreditsError, RateLimitError,
|
|
75
|
+
LanguageNotSupportedError,
|
|
76
|
+
} from 'tldrapi';
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const result = await client.summarize(text, { tier: 'deep' });
|
|
80
|
+
} catch (e) {
|
|
81
|
+
if (e instanceof InsufficientCreditsError) {
|
|
82
|
+
const topupUrl = (e.responseBody.options as any)?.top_up?.url;
|
|
83
|
+
// show user the topup options
|
|
84
|
+
} else if (e instanceof RateLimitError) {
|
|
85
|
+
await new Promise(r => setTimeout(r, (e.retryAfterSeconds || 60) * 1000));
|
|
86
|
+
// retry
|
|
87
|
+
} else if (e instanceof LanguageNotSupportedError) {
|
|
88
|
+
// English only at launch
|
|
89
|
+
} else if (e instanceof TLDRapiError) {
|
|
90
|
+
console.error(`TLDRapi error ${e.statusCode} (req ${e.requestId}): ${e.message}`);
|
|
91
|
+
} else {
|
|
92
|
+
throw e;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Quality tiers
|
|
98
|
+
|
|
99
|
+
| Tier | Credits/call | Max input tokens | Best for |
|
|
100
|
+
|-----------|-------------:|-----------------:|-----------------------------------|
|
|
101
|
+
| `quick` | 1 | 4,000 | Short texts, low-latency previews |
|
|
102
|
+
| `standard`| 5 | 16,000 | Default — modest documents |
|
|
103
|
+
| `deep` | 30 | 32,000 | Longer content, deeper reasoning |
|
|
104
|
+
| `premium` | 110 | 64,000 | Substantial documents, high fidelity |
|
|
105
|
+
| `ultra` | 400 | 100,000 | Long-form / research-grade |
|
|
106
|
+
|
|
107
|
+
Credit costs are dynamic — check current with `client.rates()`.
|
|
108
|
+
|
|
109
|
+
## Session pinning
|
|
110
|
+
|
|
111
|
+
To keep the same model / session state across calls:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
const r1 = await client.summarize('First document');
|
|
115
|
+
const r2 = await client.summarize('Second document', { sessionId: r1.sessionId });
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Overage
|
|
119
|
+
|
|
120
|
+
Pay 2× rate instead of getting a 402 when your balance runs low:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
const result = await client.summarize(text, { allowOverage: true });
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Configuration
|
|
127
|
+
|
|
128
|
+
| Option | Default | Notes |
|
|
129
|
+
|---------------|------------------------------------|---------------------------------------------|
|
|
130
|
+
| `rapidapiKey` | (required) | Your `X-RapidAPI-Key` from RapidAPI dashboard |
|
|
131
|
+
| `rapidapiHost`| `tldrapi-summarizer.p.rapidapi.com` | Override for staging listings only |
|
|
132
|
+
| `baseUrl` | `https://tldrapi-summarizer.p.rapidapi.com` | Change to point at a staging / mirror |
|
|
133
|
+
| `timeoutMs` | 60_000 | Per-request; deep tier can take 30s |
|
|
134
|
+
| `retries` | 3 | Retries on 5xx + network errors only |
|
|
135
|
+
| `fetchImpl` | `globalThis.fetch` | Pass `node-fetch` or `undici` for Node <18 |
|
|
136
|
+
|
|
137
|
+
## Support
|
|
138
|
+
|
|
139
|
+
- Issues: <https://github.com/unitycubedapps/tldrapi-node/issues>
|
|
140
|
+
- Docs: <https://unitycubed.dev/tldrapi/docs>
|
|
141
|
+
- Legal: <https://unitycubed.dev/tldrapi/legal>
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
Released under the MIT License — see [LICENSE](LICENSE).
|
|
146
|
+
|
|
147
|
+
Copyright (c) 2026 Ehren Biglari / Unity Cubed.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TLDRapi HTTP client for Node 18+.
|
|
3
|
+
*
|
|
4
|
+
* Design:
|
|
5
|
+
* - Uses the platform's built-in `fetch` (Node 18+). No third-party
|
|
6
|
+
* HTTP dependency in the shipped package.
|
|
7
|
+
* - Retries 5xx and network errors with exponential backoff + jitter,
|
|
8
|
+
* default 3 attempts. 4xx and 429 are NEVER retried (429 auto-retry
|
|
9
|
+
* would burn credits + worsen the throttle; caller should respect
|
|
10
|
+
* the Retry-After exposed on RateLimitError).
|
|
11
|
+
* - Per-request timeout via AbortController.
|
|
12
|
+
* - Typed exceptions map 1:1 to server response shapes; see errors.ts.
|
|
13
|
+
*/
|
|
14
|
+
import { ConvertFileOptions, ConvertPdfOptions, ConvertResult, ConvertTextOptions, CustomPromptDetail, CustomPromptList, CustomPromptListOptions, CustomPromptResult, CustomPromptSubmitOptions, FileInput, PdfConvertResult, Rates, RatesHistory, SummarizeOptions, SummarizeResult, TLDRapiClientOptions, UsageRange, UsageStats } from './types';
|
|
15
|
+
export declare const DEFAULT_RAPIDAPI_HOST = "tldrapi-summarizer.p.rapidapi.com";
|
|
16
|
+
export declare class TLDRapi {
|
|
17
|
+
private readonly rapidapiKey;
|
|
18
|
+
private readonly rapidapiHost;
|
|
19
|
+
private readonly baseUrl;
|
|
20
|
+
private readonly timeoutMs;
|
|
21
|
+
private readonly retries;
|
|
22
|
+
private readonly fetchImpl;
|
|
23
|
+
constructor(opts: TLDRapiClientOptions);
|
|
24
|
+
summarize(inputText: string, options?: SummarizeOptions): Promise<SummarizeResult>;
|
|
25
|
+
rates(): Promise<Rates>;
|
|
26
|
+
usage(): Promise<UsageStats>;
|
|
27
|
+
convertJsonToText(text: string, opts?: ConvertTextOptions): Promise<ConvertResult>;
|
|
28
|
+
convertHtmlToText(text: string, opts?: ConvertTextOptions): Promise<ConvertResult>;
|
|
29
|
+
convertMdToText(text: string, opts?: ConvertTextOptions): Promise<ConvertResult>;
|
|
30
|
+
private convertText;
|
|
31
|
+
convertDocToText(file: FileInput, opts?: ConvertFileOptions): Promise<ConvertResult>;
|
|
32
|
+
convertDocToLatex(file: FileInput, opts?: ConvertFileOptions): Promise<ConvertResult>;
|
|
33
|
+
/** Deprecated alias for `convertDocToText`. Kept for backward compat. */
|
|
34
|
+
convertDocxToText(file: FileInput, opts?: ConvertFileOptions): Promise<ConvertResult>;
|
|
35
|
+
private convertFile;
|
|
36
|
+
convertPdfToLatex(file: FileInput, opts?: ConvertPdfOptions): Promise<PdfConvertResult>;
|
|
37
|
+
pdfStatus(jobId: string): Promise<PdfConvertResult>;
|
|
38
|
+
ratesHistory(): Promise<RatesHistory>;
|
|
39
|
+
usageRange(from: string, to: string): Promise<UsageRange>;
|
|
40
|
+
customPromptSubmit(voiceName: string, instruction: string, opts?: CustomPromptSubmitOptions): Promise<CustomPromptResult>;
|
|
41
|
+
customPromptsList(opts?: CustomPromptListOptions): Promise<CustomPromptList>;
|
|
42
|
+
customPromptGet(promptId: string): Promise<CustomPromptDetail>;
|
|
43
|
+
private request;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAWH,OAAO,EACH,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAElB,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,yBAAyB,EAEzB,SAAS,EACT,gBAAgB,EAEhB,KAAK,EACL,YAAY,EAEZ,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EAGpB,UAAU,EAEV,UAAU,EAEb,MAAM,SAAS,CAAC;AASjB,eAAO,MAAM,qBAAqB,sCAAsC,CAAC;AAoGzE,qBAAa,OAAO;IAChB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;gBAE7B,IAAI,EAAE,oBAAoB;IAmBhC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;IAwCtF,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC;IA2BvB,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC;IAiC5B,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