@pdfvector/client 0.0.10 → 0.0.12
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/CHANGELOG.md +20 -0
- package/README.md +661 -7
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @pdfvector/client
|
|
2
2
|
|
|
3
|
+
## 0.0.12
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#159](https://github.com/phuctm97/pdfvector/pull/159) [`931317b`](https://github.com/phuctm97/pdfvector/commit/931317bd4732e56147d11f48cf6a203aa9983db2) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Add admin user detail sheet and plan/credits columns
|
|
9
|
+
|
|
10
|
+
- Updated dependencies [[`931317b`](https://github.com/phuctm97/pdfvector/commit/931317bd4732e56147d11f48cf6a203aa9983db2)]:
|
|
11
|
+
- @pdfvector/instance-client@0.0.32
|
|
12
|
+
|
|
13
|
+
## 0.0.11
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
- [#153](https://github.com/phuctm97/pdfvector/pull/153) [`8c3db48`](https://github.com/phuctm97/pdfvector/commit/8c3db48955105ebd6902bd557013de1de655f4fe) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Fix workspace dependency resolution in release workflows to publish correct contract version
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`8c3db48`](https://github.com/phuctm97/pdfvector/commit/8c3db48955105ebd6902bd557013de1de655f4fe)]:
|
|
21
|
+
- @pdfvector/instance-client@0.0.31
|
|
22
|
+
|
|
3
23
|
## 0.0.10
|
|
4
24
|
### Patch Changes
|
|
5
25
|
|
package/README.md
CHANGED
|
@@ -1,21 +1,675 @@
|
|
|
1
|
-
#
|
|
1
|
+
# PDF Vector TypeScript/JavaScript SDK
|
|
2
2
|
|
|
3
|
-
The official TypeScript/JavaScript SDK for the
|
|
3
|
+
The official TypeScript/JavaScript SDK for the [PDF Vector](https://www.pdfvector.com) API: Parse PDF, Word, Image, and Excel documents to clean, structured markdown format, ask questions about documents using AI, extract structured data from documents with JSON Schema, search across multiple academic databases with a unified API, fetch specific publications by DOI, PubMed ID, ArXiv ID, and more, find relevant academic citations for paragraphs of text, explore paper citation graphs, find similar papers, and search for research grants across US, EU, and UK funding databases.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Install
|
|
5
|
+
## Installation
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
8
|
npm install @pdfvector/client
|
|
9
|
+
# or
|
|
10
|
+
yarn add @pdfvector/client
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @pdfvector/client
|
|
13
|
+
# or
|
|
14
|
+
bun add @pdfvector/client
|
|
11
15
|
```
|
|
12
16
|
|
|
13
|
-
##
|
|
17
|
+
## Quick Start
|
|
14
18
|
|
|
15
19
|
```typescript
|
|
16
20
|
import { createClient } from "@pdfvector/client";
|
|
17
21
|
|
|
18
22
|
const client = createClient({
|
|
19
|
-
|
|
23
|
+
apiKey: "your-api-key",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Parse a document
|
|
27
|
+
const parseResult = await client.document.parse({
|
|
28
|
+
url: "https://example.com/document.pdf",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log(parseResult.markdown);
|
|
32
|
+
console.log(`Pages: ${parseResult.pageCount}, Model: ${parseResult.model}`);
|
|
33
|
+
|
|
34
|
+
// Ask questions about documents
|
|
35
|
+
const askResult = await client.document.ask({
|
|
36
|
+
url: "https://example.com/research-paper.pdf",
|
|
37
|
+
question: "What are the key findings and conclusions?",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
console.log(askResult.markdown);
|
|
41
|
+
|
|
42
|
+
// Extract structured data using JSON Schema
|
|
43
|
+
const extractResult = await client.document.extract({
|
|
44
|
+
url: "https://example.com/research-paper.pdf",
|
|
45
|
+
prompt: "Extract the research information",
|
|
46
|
+
schema: {
|
|
47
|
+
type: "object",
|
|
48
|
+
properties: {
|
|
49
|
+
title: { type: "string" },
|
|
50
|
+
authors: { type: "array", items: { type: "string" } },
|
|
51
|
+
abstract: { type: "string" },
|
|
52
|
+
findings: { type: "array", items: { type: "string" } },
|
|
53
|
+
},
|
|
54
|
+
required: ["title", "abstract"],
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
console.log(extractResult.data);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Authentication
|
|
62
|
+
|
|
63
|
+
Get your API key from the [PDF Vector dashboard](https://app.pdfvector.com/instances/2?tab=settings).
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const client = createClient({
|
|
67
|
+
apiKey: "your-api-key",
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Verify your credentials:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
const status = await client.authenticate.validateCredential();
|
|
75
|
+
console.log(status.version); // Server version
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Custom Domain
|
|
79
|
+
|
|
80
|
+
By default, the SDK connects to `global.pdfvector.com`. For custom or self-hosted instances:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const client = createClient({
|
|
84
|
+
domain: "your-instance.pdfvector.com",
|
|
85
|
+
apiKey: "your-api-key",
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// For local development
|
|
89
|
+
const localClient = createClient({
|
|
90
|
+
domain: "localhost:34000",
|
|
91
|
+
apiKey: "your-api-key",
|
|
20
92
|
});
|
|
21
93
|
```
|
|
94
|
+
|
|
95
|
+
## Document Processing
|
|
96
|
+
|
|
97
|
+
All document endpoints accept three input methods: `url`, `file` (File/Blob), or `base64`.
|
|
98
|
+
|
|
99
|
+
**Supported file types:** PDF, Word (.docx), Excel (.xlsx), CSV, and Image (.png, .jpg).
|
|
100
|
+
|
|
101
|
+
### Parse
|
|
102
|
+
|
|
103
|
+
Extract text content from documents:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const result = await client.document.parse(
|
|
107
|
+
{
|
|
108
|
+
url: "https://example.com/document.pdf",
|
|
109
|
+
model: "auto", // "auto" | "nano" | "mini" | "pro" | "max"
|
|
110
|
+
},
|
|
111
|
+
{ context: { documentId: "my-doc-123" } }, // optional, for usage tracking
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
console.log(result.markdown); // Extracted text
|
|
115
|
+
console.log(result.pageCount); // Number of pages
|
|
116
|
+
console.log(result.model); // Model tier used
|
|
117
|
+
console.log(result.html); // Full HTML (only with 'max' model)
|
|
118
|
+
console.log(result.documentId); // "my-doc-123"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Parse from file data
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { readFile } from "fs/promises";
|
|
125
|
+
|
|
126
|
+
const result = await client.document.parse(
|
|
127
|
+
{
|
|
128
|
+
file: new File([await readFile("document.pdf")], "document.pdf", {
|
|
129
|
+
type: "application/pdf",
|
|
130
|
+
}),
|
|
131
|
+
model: "auto",
|
|
132
|
+
},
|
|
133
|
+
{ context: { documentId: "uploaded-doc" } },
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
console.log(result.markdown);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Ask
|
|
140
|
+
|
|
141
|
+
Answer questions about a document:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
const result = await client.document.ask(
|
|
145
|
+
{
|
|
146
|
+
url: "https://example.com/research-paper.pdf",
|
|
147
|
+
question: "What are the main findings of this study?",
|
|
148
|
+
model: "auto",
|
|
149
|
+
},
|
|
150
|
+
{ context: { documentId: "research-paper-1" } },
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
console.log(result.markdown);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Extract
|
|
157
|
+
|
|
158
|
+
Extract structured data using a JSON Schema:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
const result = await client.document.extract(
|
|
162
|
+
{
|
|
163
|
+
url: "https://example.com/research-paper.pdf",
|
|
164
|
+
prompt: "Extract the title, authors, and publication year",
|
|
165
|
+
schema: {
|
|
166
|
+
type: "object",
|
|
167
|
+
properties: {
|
|
168
|
+
title: { type: "string" },
|
|
169
|
+
authors: { type: "array", items: { type: "string" } },
|
|
170
|
+
year: { type: "number" },
|
|
171
|
+
},
|
|
172
|
+
required: ["title", "authors", "year"],
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
{ context: { documentId: "research-paper-1" } },
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
console.log(result.data); // { title: "...", authors: [...], year: 2024 }
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Invoice Processing
|
|
182
|
+
|
|
183
|
+
Specialized methods for processing invoices. Parse supports `pro` and `max` models only. Ask and extract support all model tiers.
|
|
184
|
+
|
|
185
|
+
### Parse Invoice
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
const result = await client.invoice.parse(
|
|
189
|
+
{ url: "https://example.com/invoice.pdf" },
|
|
190
|
+
{ context: { documentId: "invoice-001" } },
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
console.log(result.markdown);
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Ask Questions About Invoices
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
const result = await client.invoice.ask(
|
|
200
|
+
{
|
|
201
|
+
url: "https://example.com/invoice.pdf",
|
|
202
|
+
question: "What is the total amount and due date for this invoice?",
|
|
203
|
+
},
|
|
204
|
+
{ context: { documentId: "invoice-001" } },
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
console.log(result.markdown);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Extract Structured Invoice Data
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
const result = await client.invoice.extract(
|
|
214
|
+
{
|
|
215
|
+
url: "https://example.com/invoice.pdf",
|
|
216
|
+
prompt: "Extract all invoice details including vendor, items, and totals",
|
|
217
|
+
schema: {
|
|
218
|
+
type: "object",
|
|
219
|
+
properties: {
|
|
220
|
+
invoiceNumber: { type: "string" },
|
|
221
|
+
date: { type: "string" },
|
|
222
|
+
totalAmount: { type: "number" },
|
|
223
|
+
items: {
|
|
224
|
+
type: "array",
|
|
225
|
+
items: {
|
|
226
|
+
type: "object",
|
|
227
|
+
properties: {
|
|
228
|
+
description: { type: "string" },
|
|
229
|
+
quantity: { type: "number" },
|
|
230
|
+
price: { type: "number" },
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
required: ["invoiceNumber", "date", "totalAmount", "items"],
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
{ context: { documentId: "invoice-001" } },
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
console.log(result.data);
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Identity Document Processing
|
|
245
|
+
|
|
246
|
+
Specialized methods for processing ID documents (passports, driver's licenses, ID cards). Parse supports `pro` and `max` models only. Ask and extract support all model tiers.
|
|
247
|
+
|
|
248
|
+
### Parse ID Document
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
const result = await client.identity.parse(
|
|
252
|
+
{ url: "https://example.com/passport.pdf" },
|
|
253
|
+
{ context: { documentId: "passport-jane" } },
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
console.log(result.markdown);
|
|
257
|
+
console.log(result.documentType); // e.g., "passport"
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Ask Questions About ID Documents
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
const result = await client.identity.ask(
|
|
264
|
+
{
|
|
265
|
+
url: "https://example.com/passport.pdf",
|
|
266
|
+
question: "What is the full name and date of birth on this document?",
|
|
267
|
+
},
|
|
268
|
+
{ context: { documentId: "passport-jane" } },
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
console.log(result.markdown);
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Extract Structured ID Document Data
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
const result = await client.identity.extract(
|
|
278
|
+
{
|
|
279
|
+
url: "https://example.com/passport.pdf",
|
|
280
|
+
prompt: "Extract passport details from this document",
|
|
281
|
+
schema: {
|
|
282
|
+
type: "object",
|
|
283
|
+
properties: {
|
|
284
|
+
fullName: { type: "string" },
|
|
285
|
+
dateOfBirth: { type: "string" },
|
|
286
|
+
documentNumber: { type: "string" },
|
|
287
|
+
nationality: { type: "string" },
|
|
288
|
+
expirationDate: { type: "string" },
|
|
289
|
+
},
|
|
290
|
+
required: ["fullName", "documentNumber"],
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
{ context: { documentId: "passport-jane" } },
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
console.log(result.data);
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## Bank Statement Processing
|
|
300
|
+
|
|
301
|
+
Specialized methods for processing bank statements. Parse supports `pro` and `max` models only. Ask and extract support all model tiers.
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
const result = await client.bankStatement.parse(
|
|
305
|
+
{ url: "https://example.com/statement.pdf" },
|
|
306
|
+
{ context: { documentId: "statement-2024-03" } },
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
console.log(result.markdown);
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
Also supports `bankStatement.ask()` and `bankStatement.extract()` with the same patterns as above.
|
|
313
|
+
|
|
314
|
+
## Academic Research
|
|
315
|
+
|
|
316
|
+
### Search Academic Publications
|
|
317
|
+
|
|
318
|
+
Search across multiple academic databases with a unified API. Costs 2 credits per request.
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
const result = await client.academic.search({
|
|
322
|
+
query: "quantum computing",
|
|
323
|
+
providers: ["semantic-scholar", "arxiv", "pubmed"],
|
|
324
|
+
limit: 20,
|
|
325
|
+
yearFrom: 2021,
|
|
326
|
+
yearTo: 2024,
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
result.results.forEach((publication) => {
|
|
330
|
+
console.log(`Title: ${publication.title}`);
|
|
331
|
+
console.log(`Authors: ${publication.authors?.map((a) => a.name).join(", ")}`);
|
|
332
|
+
console.log(`Year: ${publication.year}`);
|
|
333
|
+
console.log("---");
|
|
334
|
+
});
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
**Supported Providers:**
|
|
338
|
+
|
|
339
|
+
- `"semantic-scholar"` (default) - [Semantic Scholar](https://www.semanticscholar.org/)
|
|
340
|
+
- `"pubmed"` - [PubMed](https://pubmed.ncbi.nlm.nih.gov/)
|
|
341
|
+
- `"arxiv"` - [ArXiv](https://arxiv.org/)
|
|
342
|
+
- `"google-scholar"` - [Google Scholar](https://scholar.google.com/)
|
|
343
|
+
- `"eric"` - [ERIC](https://eric.ed.gov/)
|
|
344
|
+
- `"europe-pmc"` - [Europe PMC](https://europepmc.org/)
|
|
345
|
+
- `"openalex"` - [OpenAlex](https://openalex.org/)
|
|
346
|
+
- `"crossref"` - [Crossref](https://www.crossref.org/)
|
|
347
|
+
|
|
348
|
+
**Search Parameters:**
|
|
349
|
+
|
|
350
|
+
- `query` (required): 1-400 characters
|
|
351
|
+
- `providers`: Array of provider names (default: `["semantic-scholar"]`)
|
|
352
|
+
- `offset`: Pagination offset (default: 0)
|
|
353
|
+
- `limit`: Results per provider, 1-100 (default: 20)
|
|
354
|
+
- `yearFrom` / `yearTo`: Filter by publication year (1900-2100)
|
|
355
|
+
- `fields`: Specific fields to return (`"doi"`, `"title"`, `"url"`, `"providerURL"`, `"authors"`, `"date"`, `"year"`, `"totalCitations"`, `"totalReferences"`, `"abstract"`, `"pdfURL"`, `"provider"`, `"providerData"`)
|
|
356
|
+
|
|
357
|
+
### Fetch Academic Publications by ID
|
|
358
|
+
|
|
359
|
+
Fetch specific papers by their identifiers with automatic provider detection. Costs 2 credits per request.
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
const result = await client.academic.fetch({
|
|
363
|
+
ids: [
|
|
364
|
+
"10.1038/nature12373", // DOI
|
|
365
|
+
"12345678", // PubMed ID
|
|
366
|
+
"2301.00001", // ArXiv ID
|
|
367
|
+
],
|
|
368
|
+
fields: ["title", "authors", "year", "abstract", "doi"],
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
result.results.forEach((pub) => {
|
|
372
|
+
console.log(`Title: ${pub.title}`);
|
|
373
|
+
console.log(`Provider: ${pub.detectedProvider}`);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
result.errors?.forEach((error) => {
|
|
377
|
+
console.log(`Failed to fetch ${error.id}: ${error.error}`);
|
|
378
|
+
});
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
**Supported ID types:** DOI, PubMed ID, ArXiv ID, Semantic Scholar ID, ERIC ID, Europe PMC ID, OpenAlex ID.
|
|
382
|
+
|
|
383
|
+
### Find Citations for a Paragraph
|
|
384
|
+
|
|
385
|
+
Find relevant academic citations for each sentence in a paragraph using semantic similarity. Costs 2 credits per sentence analyzed.
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
const result = await client.academic.findCitations({
|
|
389
|
+
paragraph:
|
|
390
|
+
"Transformers have revolutionized natural language processing. Attention mechanisms allow models to focus on relevant parts of the input.",
|
|
391
|
+
providers: ["semantic-scholar", "arxiv", "pubmed"],
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
console.log(
|
|
395
|
+
`Found ${result.totalCitations} citations across ${result.sentenceCount} sentences`,
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
for (const item of result.results) {
|
|
399
|
+
console.log(`\nSentence: ${item.sentence}`);
|
|
400
|
+
for (const citation of item.citations) {
|
|
401
|
+
console.log(` [Score: ${citation.score}/10] ${citation.title}`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### Paper Citation Graph
|
|
407
|
+
|
|
408
|
+
Retrieve a paper's citing papers and referenced papers with pagination support. Costs 2+ credits per request (scales with result count).
|
|
409
|
+
|
|
410
|
+
```typescript
|
|
411
|
+
const result = await client.academic.paperGraph({
|
|
412
|
+
id: "10.1038/nature12373", // DOI, ArXiv ID, Semantic Scholar ID, OpenAlex ID, or URL
|
|
413
|
+
citationsLimit: 20,
|
|
414
|
+
referencesLimit: 20,
|
|
415
|
+
citationsOffset: 0,
|
|
416
|
+
referencesOffset: 0,
|
|
417
|
+
fields: ["title", "authors", "year", "doi"],
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
console.log(`Paper: ${result.paper.title}`);
|
|
421
|
+
console.log(`Total Citations: ${result.totalCitations}`);
|
|
422
|
+
console.log(`Total References: ${result.totalReferences}`);
|
|
423
|
+
|
|
424
|
+
for (const citation of result.citations) {
|
|
425
|
+
console.log(` Cited by: ${citation.title} (${citation.year})`);
|
|
426
|
+
}
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
**Parameters:**
|
|
430
|
+
|
|
431
|
+
- `id` (required): Paper identifier (DOI, ArXiv ID, Semantic Scholar ID, OpenAlex ID, or URL)
|
|
432
|
+
- `citationsLimit`: Max citing papers to return, 0-1000 (default: 100)
|
|
433
|
+
- `referencesLimit`: Max referenced papers to return, 0-1000 (default: 100)
|
|
434
|
+
- `citationsOffset` / `referencesOffset`: Pagination offsets (default: 0)
|
|
435
|
+
- `fields`: Specific fields to return
|
|
436
|
+
|
|
437
|
+
### Find Similar Papers
|
|
438
|
+
|
|
439
|
+
Find papers similar to a seed paper using citation network analysis. Costs 3 credits per request.
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
const result = await client.academic.similarPapers({
|
|
443
|
+
id: "10.1038/nature12373",
|
|
444
|
+
limit: 10,
|
|
445
|
+
includeEdges: true, // include citation graph edges for visualization
|
|
446
|
+
fields: ["title", "year", "doi"],
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
console.log(`Seed: ${result.seed.title}`);
|
|
450
|
+
|
|
451
|
+
for (const item of result.results) {
|
|
452
|
+
console.log(` [Similarity: ${item.similarity.toFixed(2)}] ${item.publication.title}`);
|
|
453
|
+
if (item.citingIds) {
|
|
454
|
+
console.log(` Citing: ${item.citingIds.length} papers in result set`);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
**Parameters:**
|
|
460
|
+
|
|
461
|
+
- `id` (required): Seed paper identifier
|
|
462
|
+
- `limit`: Max similar papers, 1-100 (default: 30)
|
|
463
|
+
- `includeEdges`: Include `citingIds`/`citedByIds` for graph construction (default: false)
|
|
464
|
+
- `fields`: Specific fields to return
|
|
465
|
+
|
|
466
|
+
### Search Grants
|
|
467
|
+
|
|
468
|
+
Search for research grants and funding opportunities across multiple databases with a unified API. Costs 2 credits per request.
|
|
469
|
+
|
|
470
|
+
```typescript
|
|
471
|
+
const result = await client.academic.searchGrants({
|
|
472
|
+
query: "machine learning healthcare",
|
|
473
|
+
providers: ["grants-gov", "nih-reporter", "cordis", "ukri"],
|
|
474
|
+
limit: 10,
|
|
475
|
+
fundingMin: 100000,
|
|
476
|
+
fundingMax: 1000000,
|
|
477
|
+
deadlineFrom: "2026-01-01",
|
|
478
|
+
deadlineTo: "2026-12-31",
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
console.log(`Found ${result.estimatedTotalResults} grants`);
|
|
482
|
+
|
|
483
|
+
for (const grant of result.results) {
|
|
484
|
+
console.log(`Title: ${grant.title}`);
|
|
485
|
+
console.log(`Agency: ${grant.agency} (${grant.region})`);
|
|
486
|
+
console.log(`Funding: ${grant.currency} ${grant.fundingAmountMin}-${grant.fundingAmountMax}`);
|
|
487
|
+
console.log(`Deadline: ${grant.deadlineDate ?? grant.closeDate ?? "N/A"}`);
|
|
488
|
+
console.log(`URL: ${grant.url}`);
|
|
489
|
+
console.log("---");
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// Partial provider failures are reported in errors array
|
|
493
|
+
result.errors?.forEach((error) => {
|
|
494
|
+
console.log(`Provider ${error.provider} failed: ${error.message}`);
|
|
495
|
+
});
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
**Supported Grant Providers:**
|
|
499
|
+
|
|
500
|
+
- `"grants-gov"` - [Grants.gov](https://www.grants.gov/) (US federal grants — NIH, NSF, DOE, DOD, etc.)
|
|
501
|
+
- `"nih-reporter"` - [NIH RePORTER](https://reporter.nih.gov/) (NIH-funded research projects)
|
|
502
|
+
- `"cordis"` - [CORDIS](https://cordis.europa.eu/) (EU-funded projects — Horizon Europe, ERC, etc.)
|
|
503
|
+
- `"ukri"` - [UKRI](https://www.ukri.org/) (UK-funded projects — EPSRC, BBSRC, MRC, etc.)
|
|
504
|
+
|
|
505
|
+
**Search Parameters:**
|
|
506
|
+
|
|
507
|
+
- `query` (required): 1-400 characters
|
|
508
|
+
- `providers`: Array of grant provider names (default: all 4 providers)
|
|
509
|
+
- `offset`: Pagination offset (default: 0)
|
|
510
|
+
- `limit`: Results per provider, 1-50 (default: 10)
|
|
511
|
+
- `fundingMin` / `fundingMax`: Filter by funding amount
|
|
512
|
+
- `deadlineFrom` / `deadlineTo`: Filter by deadline date (ISO format, e.g. `"2026-01-01"`)
|
|
513
|
+
- `fields`: Specific fields to return (`"sourceId"`, `"title"`, `"url"`, `"agency"`, `"program"`, `"description"`, `"eligibility"`, `"fundingAmountMin"`, `"fundingAmountMax"`, `"currency"`, `"deadlineDate"`, `"openDate"`, `"closeDate"`, `"grantType"`, `"region"`, `"keywords"`, `"piName"`, `"organizationName"`, `"provider"`, `"providerData"`)
|
|
514
|
+
|
|
515
|
+
## Document ID Tracking
|
|
516
|
+
|
|
517
|
+
Pass a `documentId` per request to track API usage. The ID is sent as a header and returned in responses for document, identity, invoice, and bank statement endpoints. Academic endpoints do not use `documentId`.
|
|
518
|
+
|
|
519
|
+
```typescript
|
|
520
|
+
const result = await client.document.parse(
|
|
521
|
+
{ url: "https://example.com/document.pdf" },
|
|
522
|
+
{ context: { documentId: "invoice-456" } },
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
console.log(result.documentId); // "invoice-456"
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
Each request can have its own `documentId`:
|
|
529
|
+
|
|
530
|
+
```typescript
|
|
531
|
+
const [resultA, resultB] = await Promise.all([
|
|
532
|
+
client.document.parse(
|
|
533
|
+
{ url: "https://example.com/doc-a.pdf" },
|
|
534
|
+
{ context: { documentId: "doc-a" } },
|
|
535
|
+
),
|
|
536
|
+
client.document.parse(
|
|
537
|
+
{ url: "https://example.com/doc-b.pdf" },
|
|
538
|
+
{ context: { documentId: "doc-b" } },
|
|
539
|
+
),
|
|
540
|
+
]);
|
|
541
|
+
|
|
542
|
+
console.log(resultA.documentId); // "doc-a"
|
|
543
|
+
console.log(resultB.documentId); // "doc-b"
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
## Model Tiers
|
|
547
|
+
|
|
548
|
+
| Tier | Best for | Max pages | Max size | Supported formats |
|
|
549
|
+
|------|----------|-----------|----------|-------------------|
|
|
550
|
+
| `nano` | Simple text documents | 30 | 10MB | PDF, Word, Excel, CSV |
|
|
551
|
+
| `mini` | Tables, structured content | 30 | 10MB | PDF, Word, Excel, CSV |
|
|
552
|
+
| `pro` | Complex docs, images, handwriting | 30 | 40MB | PDF, Word, Excel, CSV, Image |
|
|
553
|
+
| `max` | Large docs, full capabilities, HTML output | 1000 | 500MB | PDF, Word, Excel, CSV, Image |
|
|
554
|
+
| `auto` | Automatic selection with fallback (default) | 1000 | 500MB | PDF, Word, Excel, CSV, Image |
|
|
555
|
+
|
|
556
|
+
**Note:** Identity, invoice, and bank statement `parse` only support `pro`, `max`, and `auto` models. Their `ask` and `extract` support all model tiers.
|
|
557
|
+
|
|
558
|
+
## Credit Costs
|
|
559
|
+
|
|
560
|
+
| API | nano | mini | pro | max | Unit |
|
|
561
|
+
|-----|------|------|-----|-----|------|
|
|
562
|
+
| Document Parse | 1 | 2 | 4 | 8 | /page |
|
|
563
|
+
| Document Ask | 2 | 4 | 8 | 16 | /page |
|
|
564
|
+
| Document Extract | 2 | 4 | 8 | 16 | /page |
|
|
565
|
+
| Identity Parse | — | — | 6 | 10 | /page |
|
|
566
|
+
| Identity Ask | 6 | 10 | 14 | 18 | /page |
|
|
567
|
+
| Identity Extract | 6 | 10 | 14 | 18 | /page |
|
|
568
|
+
| Invoice Parse | — | — | 6 | 10 | /page |
|
|
569
|
+
| Invoice Ask | 6 | 10 | 14 | 18 | /page |
|
|
570
|
+
| Invoice Extract | 6 | 10 | 14 | 18 | /page |
|
|
571
|
+
| Bank Statement Parse | — | — | 6 | 10 | /page |
|
|
572
|
+
| Bank Statement Ask | 6 | 10 | 14 | 18 | /page |
|
|
573
|
+
| Bank Statement Extract | 6 | 10 | 14 | 18 | /page |
|
|
574
|
+
| Academic Search | 2 | 2 | 2 | 2 | /request |
|
|
575
|
+
| Academic Fetch | 2 | 2 | 2 | 2 | /request |
|
|
576
|
+
| Academic Find Citations | 2 | 2 | 2 | 2 | /sentence |
|
|
577
|
+
| Academic Paper Graph | 2+ | 2+ | 2+ | 2+ | /request |
|
|
578
|
+
| Academic Similar Papers | 3 | 3 | 3 | 3 | /request |
|
|
579
|
+
| Grant Search | 2 | 2 | 2 | 2 | /request |
|
|
580
|
+
|
|
581
|
+
## Error Handling
|
|
582
|
+
|
|
583
|
+
All API errors are thrown as `PDFVectorError` instances with structured error information:
|
|
584
|
+
|
|
585
|
+
```typescript
|
|
586
|
+
import { createClient, PDFVectorError } from "@pdfvector/client";
|
|
587
|
+
|
|
588
|
+
const client = createClient({
|
|
589
|
+
apiKey: "your-api-key",
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
try {
|
|
593
|
+
const result = await client.document.parse({
|
|
594
|
+
url: "https://example.com/document.pdf",
|
|
595
|
+
});
|
|
596
|
+
console.log(result.markdown);
|
|
597
|
+
} catch (error) {
|
|
598
|
+
if (error instanceof PDFVectorError) {
|
|
599
|
+
console.error(`API Error [${error.code}]: ${error.message}`);
|
|
600
|
+
console.error(`HTTP Status: ${error.status}`);
|
|
601
|
+
console.error(`Error Data:`, error.data);
|
|
602
|
+
} else {
|
|
603
|
+
console.error("Unexpected Error:", error);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
You can also use the static type guard:
|
|
609
|
+
|
|
610
|
+
```typescript
|
|
611
|
+
try {
|
|
612
|
+
await client.document.parse({ url: "..." });
|
|
613
|
+
} catch (error) {
|
|
614
|
+
if (PDFVectorError.is(error)) {
|
|
615
|
+
switch (error.code) {
|
|
616
|
+
case "UNAUTHORIZED":
|
|
617
|
+
console.error("Invalid API key");
|
|
618
|
+
break;
|
|
619
|
+
case "BAD_REQUEST":
|
|
620
|
+
console.error("Validation error:", error.message);
|
|
621
|
+
break;
|
|
622
|
+
case "INTERNAL_SERVER_ERROR":
|
|
623
|
+
console.error("Server error:", error.message);
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
### Error Codes
|
|
631
|
+
|
|
632
|
+
| Code | Status | Description |
|
|
633
|
+
|------|--------|-------------|
|
|
634
|
+
| `BAD_REQUEST` | 400 | Input validation failed (e.g., missing fields, invalid URL, question too short) |
|
|
635
|
+
| `UNAUTHORIZED` | 401 | Missing or invalid API key |
|
|
636
|
+
| `UNPROCESSABLE_CONTENT` | 422 | Document could not be processed by the requested model tier |
|
|
637
|
+
| `TOO_MANY_REQUESTS` | 429 | Rate limit exceeded |
|
|
638
|
+
| `INTERNAL_SERVER_ERROR` | 500 | Server-side failure |
|
|
639
|
+
|
|
640
|
+
## TypeScript Support
|
|
641
|
+
|
|
642
|
+
The SDK is written in TypeScript and includes full type definitions:
|
|
643
|
+
|
|
644
|
+
```typescript
|
|
645
|
+
import {
|
|
646
|
+
createClient,
|
|
647
|
+
PDFVectorError,
|
|
648
|
+
} from "@pdfvector/client";
|
|
649
|
+
|
|
650
|
+
import type {
|
|
651
|
+
Client,
|
|
652
|
+
ClientContext,
|
|
653
|
+
CreateClientOptions,
|
|
654
|
+
ContractInputs,
|
|
655
|
+
ContractOutputs,
|
|
656
|
+
PDFVectorModel,
|
|
657
|
+
} from "@pdfvector/client";
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
## Runtime Support
|
|
661
|
+
|
|
662
|
+
- **Node.js**: 20+
|
|
663
|
+
- **Bun**: 1.0+
|
|
664
|
+
- **ESM only** (CommonJS is not supported)
|
|
665
|
+
- Uses standard `fetch` API
|
|
666
|
+
|
|
667
|
+
## Support
|
|
668
|
+
|
|
669
|
+
- **API Reference**: [global.pdfvector.com/api/reference](https://global.pdfvector.com/api/reference)
|
|
670
|
+
- **Dashboard**: [app.pdfvector.com](https://app.pdfvector.com)
|
|
671
|
+
- **Billing**: [app.pdfvector.com/workspace/billing](https://app.pdfvector.com/workspace/billing)
|
|
672
|
+
|
|
673
|
+
## License
|
|
674
|
+
|
|
675
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdfvector/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Official TypeScript/JavaScript SDK for
|
|
5
|
+
"description": "Official TypeScript/JavaScript SDK for PDF Vector API",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"main": ".tsc/lib/index.js",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@pdfvector/instance-client": "^0.0.
|
|
26
|
+
"@pdfvector/instance-client": "^0.0.32"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
".tsc",
|