@pdfvector/client 0.1.3 → 0.2.1

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/dist/contract.mjs CHANGED
@@ -364,6 +364,38 @@ const oc = new class ContractBuilder extends ContractProcedure {
364
364
  route: {},
365
365
  meta: {}
366
366
  });
367
+ // ../util/lib/academic-providers.ts
368
+ /** Academic search providers, in the order the API lists them. Single source for the contract and marketing copy. */
369
+ const academicProviders = [
370
+ "semantic-scholar",
371
+ "pubmed",
372
+ "arxiv",
373
+ "google-scholar",
374
+ "eric",
375
+ "europe-pmc",
376
+ "openalex",
377
+ "crossref"
378
+ ];
379
+ const numberWords = [
380
+ "zero",
381
+ "one",
382
+ "two",
383
+ "three",
384
+ "four",
385
+ "five",
386
+ "six",
387
+ "seven",
388
+ "eight",
389
+ "nine",
390
+ "ten",
391
+ "eleven",
392
+ "twelve"
393
+ ];
394
+ /** English word for small counts in marketing copy ("eight"); digits past twelve. */
395
+ function countWord(count) {
396
+ return numberWords[count] ?? String(count);
397
+ }
398
+ countWord(academicProviders.length);
367
399
  // ../util/lib/api-source.ts
368
400
  const apiSources = [
369
401
  "make",
@@ -376,27 +408,44 @@ const apiSources = [
376
408
  "unknown",
377
409
  "internal"
378
410
  ];
411
+ // ../util/lib/free-tier.ts
412
+ const MB$3 = 1048576;
413
+ const freeTierLimits = {
414
+ bankStatementParse: {
415
+ dailyLimit: 5,
416
+ maxFileSize: 5 * MB$3,
417
+ maxPages: 5
418
+ },
419
+ documentParse: {
420
+ dailyLimit: 20,
421
+ maxFileSize: 5 * MB$3,
422
+ maxPages: 50,
423
+ maxOcrPages: 5
424
+ },
425
+ generateSchema: { dailyLimit: 10 },
426
+ publicationPdfUrl: { dailyLimit: 20 }
427
+ };
379
428
  // ../util/lib/tier.ts
380
- const MB = 1048576;
429
+ const MB$2 = 1048576;
381
430
  const tierLimits = {
382
431
  nano: {
383
- maxFileSize: 40 * MB,
432
+ maxFileSize: 40 * MB$2,
384
433
  maxPages: 30
385
434
  },
386
435
  mini: {
387
- maxFileSize: 40 * MB,
436
+ maxFileSize: 40 * MB$2,
388
437
  maxPages: 30
389
438
  },
390
439
  pro: {
391
- maxFileSize: 40 * MB,
440
+ maxFileSize: 40 * MB$2,
392
441
  maxPages: 30
393
442
  },
394
443
  max: {
395
- maxFileSize: 500 * MB,
444
+ maxFileSize: 500 * MB$2,
396
445
  maxPages: 2e3
397
446
  },
398
447
  auto: {
399
- maxFileSize: 500 * MB,
448
+ maxFileSize: 500 * MB$2,
400
449
  maxPages: 2e3
401
450
  }
402
451
  };
@@ -1397,7 +1446,7 @@ print(data["data"])`,
1397
1446
  "offset": 0,
1398
1447
  "yearFrom": 2017,
1399
1448
  "yearTo": 2025,
1400
- "fields": ["title", "authors", "year", "doi", "citationCount"]
1449
+ "fields": ["title", "authors", "year", "doi", "totalCitations"]
1401
1450
  }'`,
1402
1451
  typescript: `import { createClient } from "@pdfvector/client";
1403
1452
 
@@ -1429,7 +1478,7 @@ response = requests.post(
1429
1478
  "offset": 0,
1430
1479
  "yearFrom": 2017,
1431
1480
  "yearTo": 2025,
1432
- "fields": ["title", "authors", "year", "doi", "citationCount"],
1481
+ "fields": ["title", "authors", "year", "doi", "totalCitations"],
1433
1482
  },
1434
1483
  )
1435
1484
  data = response.json()
@@ -1467,7 +1516,7 @@ print(f"Found {data['estimatedTotalResults']} results")`,
1467
1516
  -H "Content-Type: application/json" \\
1468
1517
  -d '{
1469
1518
  "ids": ["10.1038/s41586-021-03819-2", "2303.08774", "PMID:33116299"],
1470
- "fields": ["title", "authors", "year", "doi", "abstract", "citationCount"]
1519
+ "fields": ["title", "authors", "year", "doi", "abstract", "totalCitations"]
1471
1520
  }'`,
1472
1521
  typescript: `import { createClient } from "@pdfvector/client";
1473
1522
 
@@ -1488,7 +1537,7 @@ response = requests.post(
1488
1537
  headers={"Authorization": "Bearer YOUR_API_KEY"},
1489
1538
  json={
1490
1539
  "ids": ["10.1038/s41586-021-03819-2", "2303.08774", "PMID:33116299"],
1491
- "fields": ["title", "authors", "year", "doi", "abstract", "citationCount"],
1540
+ "fields": ["title", "authors", "year", "doi", "abstract", "totalCitations"],
1492
1541
  },
1493
1542
  )
1494
1543
  for paper in response.json()["results"]:
@@ -1552,7 +1601,7 @@ for paper in response.json()["results"]:
1552
1601
  -d '{
1553
1602
  "paragraph": "Large language models have demonstrated remarkable few-shot learning capabilities across a wide range of NLP tasks. The scaling of transformer architectures to billions of parameters has led to emergent abilities not observed in smaller models.",
1554
1603
  "providers": ["semantic-scholar", "openalex"],
1555
- "fields": ["title", "authors", "year", "doi", "citationCount"]
1604
+ "fields": ["title", "authors", "year", "doi", "totalCitations"]
1556
1605
  }'`,
1557
1606
  typescript: `import { createClient } from "@pdfvector/client";
1558
1607
 
@@ -1579,7 +1628,7 @@ response = requests.post(
1579
1628
  json={
1580
1629
  "paragraph": "Large language models have demonstrated remarkable few-shot learning capabilities across a wide range of NLP tasks. The scaling of transformer architectures to billions of parameters has led to emergent abilities not observed in smaller models.",
1581
1630
  "providers": ["semantic-scholar", "openalex"],
1582
- "fields": ["title", "authors", "year", "doi", "citationCount"],
1631
+ "fields": ["title", "authors", "year", "doi", "totalCitations"],
1583
1632
  },
1584
1633
  )
1585
1634
  data = response.json()
@@ -1887,16 +1936,7 @@ function getOpenApiCodeSamples(id) {
1887
1936
  const documentParseOpenApiCodeSamples = getOpenApiCodeSamples("document-parse");
1888
1937
  const academicParseOpenApiCodeSamples = getOpenApiCodeSamples("academic-parse");
1889
1938
  // ../util/lib/contract/instance/router/academic/provider.ts
1890
- const providerSchema = z.enum([
1891
- "semantic-scholar",
1892
- "pubmed",
1893
- "arxiv",
1894
- "google-scholar",
1895
- "eric",
1896
- "europe-pmc",
1897
- "openalex",
1898
- "crossref"
1899
- ], { message: "Invalid provider. Must be one of: semantic-scholar, pubmed, arxiv, google-scholar, eric, europe-pmc, openalex, crossref" });
1939
+ const providerSchema = z.enum(academicProviders, { message: `Invalid provider. Must be one of: ${academicProviders.join(", ")}` });
1900
1940
  const grantProviderSchema = z.enum([
1901
1941
  "grants-gov",
1902
1942
  "nih-reporter",
@@ -1930,7 +1970,7 @@ const fetchErrorSchema = z.object({
1930
1970
  error: z.string(),
1931
1971
  code: z.string().nullish()
1932
1972
  });
1933
- const requestExamples$21 = {
1973
+ const requestExamples$22 = {
1934
1974
  "Fetch by DOI": {
1935
1975
  summary: "Fetch a paper by DOI",
1936
1976
  value: { ids: ["10.1038/nature12373"] }
@@ -1980,7 +2020,7 @@ const fetch = oc.input(z.object({
1980
2020
  spec: (op) => {
1981
2021
  op.security = [{ bearerAuth: [] }];
1982
2022
  const reqBody = op.requestBody;
1983
- if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$21;
2023
+ if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$22;
1984
2024
  op["x-codeSamples"] = getOpenApiCodeSamples("academic-fetch");
1985
2025
  return op;
1986
2026
  }
@@ -2010,7 +2050,7 @@ const sentenceCitationSchema = z.object({
2010
2050
  sentence: z.string(),
2011
2051
  citations: z.array(scoredPublicationSchema)
2012
2052
  });
2013
- const requestExamples$20 = {
2053
+ const requestExamples$21 = {
2014
2054
  "Find citations for a paragraph": {
2015
2055
  summary: "Find citations for a research paragraph",
2016
2056
  value: { paragraph: "Deep learning has revolutionized computer vision and natural language processing. Transformer architectures have become the dominant approach for sequence modeling tasks. Recent large language models demonstrate emergent capabilities not seen in smaller models." }
@@ -2058,7 +2098,7 @@ const findCitations = oc.input(z.object({
2058
2098
  spec: (op) => {
2059
2099
  op.security = [{ bearerAuth: [] }];
2060
2100
  const reqBody = op.requestBody;
2061
- if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$20;
2101
+ if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$21;
2062
2102
  op["x-codeSamples"] = getOpenApiCodeSamples("academic-find-citations");
2063
2103
  return op;
2064
2104
  }
@@ -2083,7 +2123,7 @@ const publicationSchema$2 = z.object({
2083
2123
  provider: providerSchema.nullish(),
2084
2124
  providerData: z.record(z.string(), z.unknown()).nullish()
2085
2125
  });
2086
- const requestExamples$19 = {
2126
+ const requestExamples$20 = {
2087
2127
  "Get citations by DOI": {
2088
2128
  summary: "Get citations and references for a paper by DOI",
2089
2129
  value: {
@@ -2149,7 +2189,7 @@ const paperGraph = oc.input(z.object({
2149
2189
  spec: (op) => {
2150
2190
  op.security = [{ bearerAuth: [] }];
2151
2191
  const reqBody = op.requestBody;
2152
- if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$19;
2192
+ if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$20;
2153
2193
  op["x-codeSamples"] = getOpenApiCodeSamples("academic-paper-graph");
2154
2194
  return op;
2155
2195
  }
@@ -2228,10 +2268,17 @@ function tierDesc(tier, credits, unit, extra) {
2228
2268
  }
2229
2269
  const autoLimit = tierLimits["auto"];
2230
2270
  if (!autoLimit) throw new Error("Missing auto tier limits");
2271
+ const autoLimitStr = `Up to ${autoLimit.maxPages} pages, ${fmtSize(autoLimit.maxFileSize)}.`;
2272
+ const proLimit = tierLimits["pro"];
2273
+ if (!proLimit) throw new Error("Missing pro tier limits");
2274
+ /** File limits for operation descriptions, from `tierLimits` (Auto/Max vs the 30-page tiers). */
2275
+ const fileLimitsDescription = `Files up to ${autoLimit.maxPages.toLocaleString("en-US")} pages and ${fmtSize(autoLimit.maxFileSize)} with the auto and max models; nano, mini and pro accept up to ${proLimit.maxPages} pages and ${fmtSize(proLimit.maxFileSize)}.`;
2276
+ /** Error field for callers that retry with another model (operation descriptions). */
2277
+ const suggestedModelDescription = "When the chosen model cannot handle the document (a scanned PDF on nano, an image on nano or mini, a file over the page or size limit, an unusable answer), the error response's `data.suggestedModel` names the model to retry with: the next tier up, `auto` for files over the tier's page or size limit that fit auto's, or the lowest tier that supports the file type.";
2231
2278
  /** Model tier descriptions for document parse endpoints. */
2232
2279
  const documentParseModelDescription = `Model tier for parsing.
2233
2280
 
2234
- - auto (default): Intelligent fallback — credits based on the tier selected automatically. ${`Up to ${autoLimit.maxPages} pages, ${fmtSize(autoLimit.maxFileSize)}.`}\n${tierDesc("nano", documentParseCosts.nano, "credit/page", "Simple plain text documents.")}\n${tierDesc("mini", documentParseCosts.mini, "credits/page", "Documents with tables and structured content.")}\n${tierDesc("pro", documentParseCosts.pro, "credits/page", "Tables, handwritten text, figures, math, Arabic, image support.")}\n${tierDesc("max", documentParseCosts.max, "credits/page", "Full Pro capabilities + enhanced multilingual.")}` + formatNote;
2281
+ - auto (default): Intelligent fallback — credits based on the tier selected automatically. ${autoLimitStr}\n${tierDesc("nano", documentParseCosts.nano, "credit/page", "Simple plain text documents.")}\n${tierDesc("mini", documentParseCosts.mini, "credits/page", "Documents with tables and structured content.")}\n${tierDesc("pro", documentParseCosts.pro, "credits/page", "Tables, handwritten text, figures, math, Arabic, image support.")}\n${tierDesc("max", documentParseCosts.max, "credits/page", "Full Pro capabilities + enhanced multilingual.")}` + formatNote;
2235
2282
  /** Model tier descriptions for document extract endpoints. */
2236
2283
  const documentExtractModelDescription = `Model tier for extracting structured data.
2237
2284
 
@@ -2297,7 +2344,7 @@ const parseOutputSchema$4 = z.object({
2297
2344
  html: z.string().optional().describe("Full HTML representation of the paper content. Only available when using the 'max' model."),
2298
2345
  pages: z.array(pageMarkdownSchema).optional().describe("Page-separated markdown content. Returned only when includePages is true.")
2299
2346
  });
2300
- const requestExamples$18 = {
2347
+ const requestExamples$19 = {
2301
2348
  "Parse ArXiv paper by ID": {
2302
2349
  summary: "Parse ArXiv paper by ID",
2303
2350
  value: {
@@ -2330,12 +2377,12 @@ const requestExamples$18 = {
2330
2377
  };
2331
2378
  const parse$4 = oc.input(parseInputSchema$4).output(parseOutputSchema$4).route({
2332
2379
  summary: "Parse an academic paper to markdown",
2333
- description: "Resolve an academic paper URL or identifier to a public PDF URL, parse the PDF, and return markdown using the same model tiers as document.parse. Returns NOT_FOUND when the paper cannot be found or no public PDF is available.",
2380
+ description: "Resolve an academic paper URL or identifier to a public PDF URL, parse the PDF, and return markdown using the same model tiers as document.parse. When the first copy cannot be downloaded (for example a publisher that blocks automated downloads), other open-access copies are tried: arXiv, PubMed Central, and repository copies listed by OpenAlex; pdfURL in the response is the copy that was parsed. Returns NOT_FOUND when the paper cannot be found or no public PDF is available.",
2334
2381
  tags: ["Academic"],
2335
2382
  spec: (op) => {
2336
2383
  op.security = [{ bearerAuth: [] }];
2337
2384
  const reqBody = op.requestBody;
2338
- if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$18;
2385
+ if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$19;
2339
2386
  op["x-codeSamples"] = academicParseOpenApiCodeSamples;
2340
2387
  return op;
2341
2388
  }
@@ -2366,7 +2413,7 @@ const providerErrorSchema$1 = z.object({
2366
2413
  code: z.string().nullish(),
2367
2414
  details: z.record(z.string(), z.unknown()).nullish()
2368
2415
  });
2369
- const requestExamples$17 = {
2416
+ const requestExamples$18 = {
2370
2417
  "Search with default provider": {
2371
2418
  summary: "Search with Semantic Scholar",
2372
2419
  value: { query: "deep learning for natural language processing" }
@@ -2423,16 +2470,16 @@ const search = oc.input(z.object({
2423
2470
  })).output(z.object({
2424
2471
  estimatedTotalResults: z.number(),
2425
2472
  results: z.array(publicationSchema$1),
2426
- errors: z.array(providerErrorSchema$1).nullish().describe("Providers that failed for this request (for example rate limited or unavailable). When present, `results` only contain papers from the providers that succeeded, so treat the response as partial. Credits are the same either way."),
2473
+ errors: z.array(providerErrorSchema$1).nullish().describe("Providers that failed for this request (for example rate limited or unavailable). When present, `results` only contain papers from the providers that succeeded, so treat the response as partial; it is billed like any successful search. If every requested provider fails and they include `europe-pmc` but not `pubmed`, the search falls back to `pubmed` with the time left: `results` then come from PubMed (each result's `provider` says so) and each failed provider's entry here has `details.fallbackProvider` `pubmed`; it is billed like any successful search. If every provider fails (including that fallback, whose entry then has `details.fallback` `true`), the request fails with HTTP 503 (`SERVICE_UNAVAILABLE`, `data.code` `ALL_PROVIDERS_FAILED`, per-provider `data.errors`) and is not charged."),
2427
2474
  requestId: z.number().int()
2428
2475
  })).route({
2429
2476
  summary: "Search academic papers",
2430
- description: `Search for academic publications across multiple databases with relevance ranking. Costs ${academicCreditCosts.academicSearch} credits per request.`,
2477
+ description: `Search for academic publications across multiple databases with relevance ranking. Costs ${academicCreditCosts.academicSearch} credits per request, also when no papers match. If every provider fails, it returns HTTP 503 and charges nothing.`,
2431
2478
  tags: ["Academic"],
2432
2479
  spec: (op) => {
2433
2480
  op.security = [{ bearerAuth: [] }];
2434
2481
  const reqBody = op.requestBody;
2435
- if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$17;
2482
+ if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$18;
2436
2483
  op["x-codeSamples"] = getOpenApiCodeSamples("academic-search");
2437
2484
  return op;
2438
2485
  }
@@ -2466,7 +2513,7 @@ const providerErrorSchema = z.object({
2466
2513
  code: z.string().nullish(),
2467
2514
  details: z.record(z.string(), z.unknown()).nullish()
2468
2515
  });
2469
- const requestExamples$16 = {
2516
+ const requestExamples$17 = {
2470
2517
  "Search all providers": {
2471
2518
  summary: "Search grants across all funding databases",
2472
2519
  value: { query: "machine learning healthcare" }
@@ -2544,7 +2591,7 @@ const searchGrants = oc.input(z.object({
2544
2591
  spec: (op) => {
2545
2592
  op.security = [{ bearerAuth: [] }];
2546
2593
  const reqBody = op.requestBody;
2547
- if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$16;
2594
+ if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$17;
2548
2595
  op["x-codeSamples"] = getOpenApiCodeSamples("academic-search-grants");
2549
2596
  return op;
2550
2597
  }
@@ -2577,7 +2624,7 @@ const similarPaperSchema = z.object({
2577
2624
  citingIds: z.array(z.string()).nullish().describe("OpenAlex IDs of papers in result set that cite this paper (only if includeEdges=true)"),
2578
2625
  citedByIds: z.array(z.string()).nullish().describe("OpenAlex IDs of papers in result set cited by this paper (only if includeEdges=true)")
2579
2626
  });
2580
- const requestExamples$15 = {
2627
+ const requestExamples$16 = {
2581
2628
  "Find similar papers by DOI": {
2582
2629
  summary: "Find papers similar to a given paper",
2583
2630
  value: {
@@ -2635,7 +2682,7 @@ const similarPapers = oc.input(z.object({
2635
2682
  spec: (op) => {
2636
2683
  op.security = [{ bearerAuth: [] }];
2637
2684
  const reqBody = op.requestBody;
2638
- if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$15;
2685
+ if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$16;
2639
2686
  op["x-codeSamples"] = getOpenApiCodeSamples("academic-similar-papers");
2640
2687
  return op;
2641
2688
  }
@@ -2995,8 +3042,8 @@ var admin_exports = /* @__PURE__ */ __exportAll({
2995
3042
  setVersion: () => setVersion
2996
3043
  });
2997
3044
  // ../util/lib/contract/instance/router/authenticate/validate-credential.ts
2998
- const inputSchema$3 = z.object({}).optional();
2999
- const outputSchema$4 = z.object({
3045
+ const inputSchema$4 = z.object({}).optional();
3046
+ const outputSchema$5 = z.object({
3000
3047
  status: z.string().describe("Server status indicator"),
3001
3048
  version: z.string().describe("Server version"),
3002
3049
  timestamp: z.string().describe("Current server timestamp in ISO 8601 format")
@@ -3009,7 +3056,7 @@ const validateCredential = oc.route({
3009
3056
  op.security = [{ bearerAuth: [] }];
3010
3057
  return op;
3011
3058
  }
3012
- }).input(inputSchema$3).output(outputSchema$4);
3059
+ }).input(inputSchema$4).output(outputSchema$5);
3013
3060
  // ../util/lib/contract/instance/router/authenticate/index.ts
3014
3061
  var authenticate_exports = /* @__PURE__ */ __exportAll({ validateCredential: () => validateCredential });
3015
3062
  // ../util/lib/contract/instance/router/bankStatement/get-default-spec.ts
@@ -3053,7 +3100,7 @@ const askOutputSchema$3 = z.object({
3053
3100
  requestId: z.number().int().describe("Unique request identifier for this API call"),
3054
3101
  documentId: z.string().optional().describe("Document ID if provided via x-pdfvector-document-id header or request body")
3055
3102
  });
3056
- const requestExamples$14 = { "Ask from URL": {
3103
+ const requestExamples$15 = { "Ask from URL": {
3057
3104
  summary: "Ask from URL",
3058
3105
  value: {
3059
3106
  url: "https://example.com/bank-statement.pdf",
@@ -3065,7 +3112,7 @@ const ask$3 = oc.route({
3065
3112
  description: `Parse a bank statement and answer a question about its content using AI. Supports ${supportedFileTypesLong}. Provide the document via file upload, a public URL, or a base64-encoded string.`,
3066
3113
  tags: ["Bank Statement"],
3067
3114
  spec: (op) => {
3068
- const spec = getDefaultSpec$3(op, requestExamples$14);
3115
+ const spec = getDefaultSpec$3(op, requestExamples$15);
3069
3116
  spec["x-codeSamples"] = getOpenApiCodeSamples("bank-statement-ask");
3070
3117
  return spec;
3071
3118
  }
@@ -3107,7 +3154,7 @@ const extractOutputSchema$3 = z.object({
3107
3154
  requestId: z.number().int().describe("Unique request identifier for this API call"),
3108
3155
  documentId: z.string().optional().describe("Document ID if provided via x-pdfvector-document-id header or request body")
3109
3156
  });
3110
- const requestExamples$13 = { "Extract from URL": {
3157
+ const requestExamples$14 = { "Extract from URL": {
3111
3158
  summary: "Extract from URL",
3112
3159
  value: {
3113
3160
  url: "https://example.com/bank-statement.pdf",
@@ -3138,7 +3185,7 @@ const extract$3 = oc.route({
3138
3185
  description: `Parse a bank statement and extract structured data matching a provided JSON Schema using AI. Supports ${supportedFileTypesLong}. Provide the document via file upload, a public URL, or a base64-encoded string.`,
3139
3186
  tags: ["Bank Statement"],
3140
3187
  spec: (op) => {
3141
- const spec = getDefaultSpec$3(op, requestExamples$13);
3188
+ const spec = getDefaultSpec$3(op, requestExamples$14);
3142
3189
  spec["x-codeSamples"] = getOpenApiCodeSamples("bank-statement-extract");
3143
3190
  return spec;
3144
3191
  }
@@ -3169,7 +3216,7 @@ const parseOutputSchema$3 = z.object({
3169
3216
  html: z.string().optional().describe("Full HTML representation of the document content. Only available when using the 'max' model. Preserves rich formatting, tables, selection marks, and visual layout that cannot be fully represented in markdown."),
3170
3217
  documentId: z.string().optional().describe("Document ID if provided via x-pdfvector-document-id header or request body")
3171
3218
  });
3172
- const requestExamples$12 = {
3219
+ const requestExamples$13 = {
3173
3220
  "Parse from URL": {
3174
3221
  summary: "Parse from URL",
3175
3222
  value: { url: "https://example.com/bank-statement.pdf" }
@@ -3188,7 +3235,7 @@ const parse$3 = oc.route({
3188
3235
  description: `Extract text and structured data from a bank statement. Supports ${supportedFileTypesLong}. Provide the document via file upload, a public URL, or a base64-encoded string.`,
3189
3236
  tags: ["Bank Statement"],
3190
3237
  spec: (op) => {
3191
- const spec = getDefaultSpec$3(op, requestExamples$12);
3238
+ const spec = getDefaultSpec$3(op, requestExamples$13);
3192
3239
  spec["x-codeSamples"] = getOpenApiCodeSamples("bank-statement-parse");
3193
3240
  return spec;
3194
3241
  }
@@ -3245,7 +3292,7 @@ const askOutputSchema$2 = z.object({
3245
3292
  credits: 48,
3246
3293
  requestId: 1
3247
3294
  }] });
3248
- const requestExamples$11 = {
3295
+ const requestExamples$12 = {
3249
3296
  "Ask from URL": {
3250
3297
  summary: "Ask from URL",
3251
3298
  value: {
@@ -3286,10 +3333,10 @@ const requestExamples$11 = {
3286
3333
  };
3287
3334
  const ask$2 = oc.route({
3288
3335
  summary: "Ask a question about a document",
3289
- description: `Parse a document and answer a question about its content using AI. Supports ${supportedFileTypesLong}. Files up to 1000 pages and up to 500MB in size. Provide the document via file upload, a public URL, or a base64-encoded string.`,
3336
+ description: `Parse a document and answer a question about its content using AI. Supports ${supportedFileTypesLong}. ${fileLimitsDescription} ${suggestedModelDescription} Provide the document via file upload, a public URL, or a base64-encoded string.`,
3290
3337
  tags: ["Document"],
3291
3338
  spec: (op) => {
3292
- const spec = getDefaultSpec$2(op, requestExamples$11);
3339
+ const spec = getDefaultSpec$2(op, requestExamples$12);
3293
3340
  spec["x-codeSamples"] = getOpenApiCodeSamples("document-ask");
3294
3341
  return spec;
3295
3342
  }
@@ -3326,7 +3373,7 @@ const extractOutputSchema$2 = z.object({
3326
3373
  credits: 48,
3327
3374
  requestId: 1
3328
3375
  }] });
3329
- const requestExamples$10 = {
3376
+ const requestExamples$11 = {
3330
3377
  "Extract from URL": {
3331
3378
  summary: "Extract from URL",
3332
3379
  value: {
@@ -3380,10 +3427,10 @@ const requestExamples$10 = {
3380
3427
  };
3381
3428
  const extract$2 = oc.route({
3382
3429
  summary: "Extract structured data from a document",
3383
- description: `Parse a document and extract structured data matching a provided JSON Schema using AI. Supports ${supportedFileTypesLong}. Files up to 1000 pages and up to 500MB in size. Provide the document via file upload, a public URL, or a base64-encoded string.`,
3430
+ description: `Parse a document and extract structured data matching a provided JSON Schema using AI. Supports ${supportedFileTypesLong}. ${fileLimitsDescription} ${suggestedModelDescription} Provide the document via file upload, a public URL, or a base64-encoded string.`,
3384
3431
  tags: ["Document"],
3385
3432
  spec: (op) => {
3386
- const spec = getDefaultSpec$2(op, requestExamples$10);
3433
+ const spec = getDefaultSpec$2(op, requestExamples$11);
3387
3434
  spec["x-codeSamples"] = getOpenApiCodeSamples("document-extract");
3388
3435
  return spec;
3389
3436
  }
@@ -3436,7 +3483,7 @@ const parseOutputSchema$2 = z.object({
3436
3483
  documentId: z.string().optional().describe("Document ID if provided via x-pdfvector-document-id header or request body"),
3437
3484
  pages: z.array(pageMarkdownSchema).optional().describe("Page-separated markdown content. Returned only when includePages is true.")
3438
3485
  });
3439
- const requestExamples$9 = {
3486
+ const requestExamples$10 = {
3440
3487
  "Parse from URL": {
3441
3488
  summary: "Parse from URL",
3442
3489
  value: { url: "https://drive.google.com/file/d/13T04Yk20OwBNIDyvJJ3XlUg9WfOsmbjm/view?usp=share_link" }
@@ -3480,10 +3527,10 @@ const requestExamples$9 = {
3480
3527
  };
3481
3528
  const parse$2 = oc.route({
3482
3529
  summary: "Parse a document",
3483
- description: `Extract text and page count from a document. Supports ${supportedFileTypesLong}. Provide the document via file upload, a public URL, or a base64-encoded string.`,
3530
+ description: `Extract text and page count from a document. Supports ${supportedFileTypesLong}. Provide the document via file upload, a public URL, or a base64-encoded string. ${suggestedModelDescription}`,
3484
3531
  tags: ["Document"],
3485
3532
  spec: (op) => {
3486
- const spec = getDefaultSpec$2(op, requestExamples$9);
3533
+ const spec = getDefaultSpec$2(op, requestExamples$10);
3487
3534
  spec["x-codeSamples"] = documentParseOpenApiCodeSamples;
3488
3535
  return spec;
3489
3536
  }
@@ -3495,19 +3542,21 @@ var document_exports = /* @__PURE__ */ __exportAll({
3495
3542
  parse: () => parse$2
3496
3543
  });
3497
3544
  // ../util/lib/contract/instance/router/free/bank-statement-parse.ts
3498
- const inputSchema$2 = z.object({
3545
+ const MB$1 = 1048576;
3546
+ const limits$1 = freeTierLimits.bankStatementParse;
3547
+ const inputSchema$3 = z.object({
3499
3548
  url: fetchableUrlSchema.optional().describe("URL of the bank statement file to fetch and parse"),
3500
3549
  file: z.file().mime([...supportedFileMimes], supportedFileMimeErrorMessage).optional().describe(`Bank statement file upload via multipart form-data (${supportedFileFormatsDescription})`),
3501
3550
  base64: z.string().optional().describe("Base64-encoded bank statement file content")
3502
3551
  });
3503
- const outputSchema$3 = z.object({
3552
+ const outputSchema$4 = z.object({
3504
3553
  markdown: z.string().describe("Extracted text content from the bank statement"),
3505
3554
  pageCount: z.number().int().describe("Total number of pages in the document"),
3506
3555
  model: z.enum(["pro", "max"]).describe("Model tier used to parse the bank statement"),
3507
3556
  requestId: z.number().int().describe("Unique request identifier for this API call"),
3508
3557
  html: z.string().optional().describe("Full HTML representation of the document content")
3509
3558
  });
3510
- const requestExamples$8 = {
3559
+ const requestExamples$9 = {
3511
3560
  "Parse from URL": {
3512
3561
  summary: "Parse from URL",
3513
3562
  value: { url: "https://raw.githubusercontent.com/aws-samples/textract-bank-statement-processor/main/Statement20230428.pdf" }
@@ -3521,7 +3570,7 @@ const requestExamples$8 = {
3521
3570
  value: { file: "(binary)" }
3522
3571
  }
3523
3572
  };
3524
- const responseExample$3 = {
3573
+ const responseExample$4 = {
3525
3574
  markdown: "## Bank Statement\n\n### Account Information\n\n| Field | Value |\n|-------|-------|\n| Bank Name | Example Bank |\n| Account Number | ****1234 |\n| Statement Start Date | 2023-03-01 |\n| Statement End Date | 2023-03-31 |\n| Beginning Balance | $5,432.10 |\n| Ending Balance | $4,891.55 |\n\n### Transactions\n\n| Date | Description | Deposit Amount | Withdrawal Amount |\n| --- | --- | --- | --- |\n| 2023-03-05 | Direct Deposit - Payroll | $3,200.00 | |\n| 2023-03-08 | Online Transfer Out | | $500.00 |\n| 2023-03-15 | Grocery Store | | $142.35 |",
3526
3575
  pageCount: 2,
3527
3576
  model: "max",
@@ -3530,7 +3579,60 @@ const responseExample$3 = {
3530
3579
  };
3531
3580
  const bankStatementParse = oc.route({
3532
3581
  summary: "Free: Parse a bank statement",
3533
- description: `Extract text and structured data from a bank statement. Supports ${supportedFileTypesLong}. Free tier: max 5 pages, max 5 MB. Rate limited to 5 requests per IP per day.`,
3582
+ description: `Extract text and structured data from a bank statement. Supports ${supportedFileTypesLong}. Free tier: max ${limits$1.maxPages} pages, max ${limits$1.maxFileSize / MB$1} MB. Rate limited to ${limits$1.dailyLimit} requests per IP per day. Requires a Cloudflare Turnstile token from www.pdfvector.com in the x-pdfvector-turnstile-token header (MCP calls are exempt).`,
3583
+ tags: ["Free"],
3584
+ spec: (op) => {
3585
+ op.security = [];
3586
+ const reqBody = op.requestBody;
3587
+ if (reqBody?.content) for (const mediaType of Object.values(reqBody.content)) mediaType["examples"] = requestExamples$9;
3588
+ const okResponse = op.responses?.["200"];
3589
+ if (okResponse?.content) for (const mediaType of Object.values(okResponse.content)) mediaType["example"] = responseExample$4;
3590
+ return op;
3591
+ }
3592
+ }).input(inputSchema$3).output(outputSchema$4);
3593
+ // ../util/lib/contract/instance/router/free/document-parse.ts
3594
+ const MB = 1048576;
3595
+ const limits = freeTierLimits.documentParse;
3596
+ const inputSchema$2 = z.object({
3597
+ url: fetchableUrlSchema.optional().describe("URL of the document to fetch and parse"),
3598
+ file: z.file().mime([...supportedFileMimes], supportedFileMimeErrorMessage).optional().describe(`Document file upload via multipart form-data (${supportedFileFormatsDescription})`),
3599
+ base64: z.string().optional().describe("Base64-encoded document content")
3600
+ });
3601
+ const outputSchema$3 = z.object({
3602
+ markdown: z.string().describe("Markdown content of the document"),
3603
+ pageCount: z.number().int().describe("Total number of pages in the document"),
3604
+ model: z.enum([
3605
+ "nano",
3606
+ "mini",
3607
+ "pro",
3608
+ "max"
3609
+ ]).describe("Model tier the auto model selected for the document"),
3610
+ requestId: z.number().int().describe("Unique request identifier for this API call"),
3611
+ html: z.string().optional().describe("Full HTML representation of the document content")
3612
+ });
3613
+ const requestExamples$8 = {
3614
+ "Parse from URL": {
3615
+ summary: "Parse from URL",
3616
+ value: { url: "https://pdfobject.com/pdf/sample.pdf" }
3617
+ },
3618
+ "Parse from base64": {
3619
+ summary: "Parse from base64",
3620
+ value: { base64: "JVBERi0xLjAKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqIDIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDE+PmVuZG9iaiAzIDAgb2JqPDwvVHlwZS9QYWdlL01lZGlhQm94WzAgMCAzIDNdL1BhcmVudCAyIDAgUj4+ZW5kb2JqCnhyZWYKMCA0CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKdHJhaWxlcjw8L1NpemUgNC9Sb290IDEgMCBSPj4Kc3RhcnR4cmVmCjE5MAolJUVPRg==" }
3621
+ },
3622
+ "Parse from file upload": {
3623
+ summary: "Parse from file upload",
3624
+ value: { file: "(binary)" }
3625
+ }
3626
+ };
3627
+ const responseExample$3 = {
3628
+ markdown: "# Sample PDF\n\n## This is a simple PDF file. Fun fun fun.\n\nLorem ipsum dolor sit amet...",
3629
+ pageCount: 1,
3630
+ model: "mini",
3631
+ requestId: 42
3632
+ };
3633
+ const documentParse = oc.route({
3634
+ summary: "Free: Convert a document to markdown",
3635
+ description: `Convert a document to markdown. Supports ${supportedFileTypesLong}. Files the local engines read (Office, OpenDocument, RTF, EPUB, HTML, text and PDFs with a text layer) are converted without OCR; scanned PDFs and images use OCR. Free tier: max ${limits.maxPages} pages (${limits.maxOcrPages} for scans and images), max ${limits.maxFileSize / MB} MB. Rate limited to ${limits.dailyLimit} requests per IP per day. Requires a Cloudflare Turnstile token from www.pdfvector.com in the x-pdfvector-turnstile-token header (MCP calls are exempt).`,
3534
3636
  tags: ["Free"],
3535
3637
  spec: (op) => {
3536
3638
  op.security = [];
@@ -3623,7 +3725,7 @@ const responseExample$2 = {
3623
3725
  };
3624
3726
  const generateSchema = oc.route({
3625
3727
  summary: "Free: Generate a JSON Schema",
3626
- description: "Generate a JSON Schema from a natural language instruction. Use the resulting schema with the /extract endpoints to pull structured data from documents. Rate limited to 10 requests per IP per day.",
3728
+ description: `Generate a JSON Schema from a natural language instruction. Use the resulting schema with the /extract endpoints to pull structured data from documents. Rate limited to ${freeTierLimits.generateSchema.dailyLimit} requests per IP per day. Requires a Cloudflare Turnstile token from www.pdfvector.com in the x-pdfvector-turnstile-token header (MCP calls are exempt).`,
3627
3729
  tags: ["Free"],
3628
3730
  spec: (op) => {
3629
3731
  op.security = [];
@@ -3677,7 +3779,7 @@ const responseExample$1 = {
3677
3779
  };
3678
3780
  const publicationPdfUrl = oc.route({
3679
3781
  summary: "Free: Get publication PDF URL",
3680
- description: "Look up publications by DOI, PubMed ID, ArXiv ID, or other identifiers and return their PDF URLs if available. Accepts up to 20 IDs per request. Rate limited to 20 requests per IP per day.",
3782
+ description: `Look up publications by DOI, PubMed ID, ArXiv ID, or other identifiers and return their PDF URLs if available. Accepts up to 20 IDs per request. Rate limited to ${freeTierLimits.publicationPdfUrl.dailyLimit} requests per IP per day. Requires a Cloudflare Turnstile token from www.pdfvector.com in the x-pdfvector-turnstile-token header (MCP calls are exempt).`,
3681
3783
  tags: ["Free"],
3682
3784
  spec: (op) => {
3683
3785
  op.security = [];
@@ -3696,6 +3798,7 @@ const limitSchema = z.object({
3696
3798
  });
3697
3799
  const outputSchema = z.object({
3698
3800
  bankStatementParse: limitSchema.describe("Bank statement parse limits"),
3801
+ documentParse: limitSchema.describe("Document parse limits"),
3699
3802
  generateSchema: limitSchema.describe("JSON schema generator limits"),
3700
3803
  publicationPdfUrl: limitSchema.describe("Publication PDF URL lookup limits")
3701
3804
  });
@@ -3705,6 +3808,11 @@ const responseExample = {
3705
3808
  used: 2,
3706
3809
  remaining: 3
3707
3810
  },
3811
+ documentParse: {
3812
+ limit: 5,
3813
+ used: 1,
3814
+ remaining: 4
3815
+ },
3708
3816
  generateSchema: {
3709
3817
  limit: 10,
3710
3818
  used: 0,
@@ -3731,6 +3839,7 @@ const rateLimitStatus = oc.route({
3731
3839
  // ../util/lib/contract/instance/router/free/index.ts
3732
3840
  var free_exports = /* @__PURE__ */ __exportAll({
3733
3841
  bankStatementParse: () => bankStatementParse,
3842
+ documentParse: () => documentParse,
3734
3843
  generateSchema: () => generateSchema,
3735
3844
  publicationPdfUrl: () => publicationPdfUrl,
3736
3845
  rateLimitStatus: () => rateLimitStatus
@@ -3993,34 +4102,59 @@ const extractOutputSchema = z.object({
3993
4102
  requestId: z.number().int().describe("Unique request identifier for this API call"),
3994
4103
  documentId: z.string().optional().describe("Document ID if provided via x-pdfvector-document-id header or request body")
3995
4104
  });
3996
- const requestExamples$1 = { "Extract from URL": {
3997
- summary: "Extract from URL",
3998
- value: {
3999
- url: "https://example.com/invoice.pdf",
4000
- prompt: "Extract the vendor name, total amount, and line items",
4001
- schema: JSON.stringify({
4002
- type: "object",
4003
- properties: {
4004
- vendorName: { type: "string" },
4005
- totalAmount: { type: "number" },
4006
- lineItems: {
4105
+ const requestExamples$1 = {
4106
+ "Extract from URL": {
4107
+ summary: "Extract from URL",
4108
+ value: {
4109
+ url: "https://example.com/invoice.pdf",
4110
+ prompt: "Extract the vendor name, total amount, and line items",
4111
+ schema: JSON.stringify({
4112
+ type: "object",
4113
+ properties: {
4114
+ vendorName: { type: "string" },
4115
+ totalAmount: { type: "number" },
4116
+ lineItems: {
4117
+ type: "array",
4118
+ items: {
4119
+ type: "object",
4120
+ properties: {
4121
+ description: { type: "string" },
4122
+ amount: { type: "number" }
4123
+ }
4124
+ }
4125
+ }
4126
+ },
4127
+ required: ["vendorName", "totalAmount"]
4128
+ })
4129
+ }
4130
+ },
4131
+ "Many invoices in one PDF": {
4132
+ summary: "Many invoices in one PDF",
4133
+ value: {
4134
+ url: "https://example.com/batched-invoices.pdf",
4135
+ prompt: "Extract every invoice in the file as a separate item, one per invoice number",
4136
+ schema: JSON.stringify({
4137
+ type: "object",
4138
+ properties: { invoices: {
4007
4139
  type: "array",
4008
4140
  items: {
4009
4141
  type: "object",
4010
4142
  properties: {
4011
- description: { type: "string" },
4012
- amount: { type: "number" }
4013
- }
4143
+ invoiceNumber: { type: "string" },
4144
+ vendorName: { type: "string" },
4145
+ totalAmount: { type: "number" }
4146
+ },
4147
+ required: ["invoiceNumber", "totalAmount"]
4014
4148
  }
4015
- }
4016
- },
4017
- required: ["vendorName", "totalAmount"]
4018
- })
4149
+ } },
4150
+ required: ["invoices"]
4151
+ })
4152
+ }
4019
4153
  }
4020
- } };
4154
+ };
4021
4155
  const extract = oc.route({
4022
4156
  summary: "Extract structured data from an invoice",
4023
- description: `Parse an invoice and extract structured data matching a provided JSON Schema using AI. Supports ${supportedFileTypesLong}. Provide the document via file upload, a public URL, or a base64-encoded string.`,
4157
+ description: `Parse an invoice and extract structured data matching a provided JSON Schema using AI. Supports ${supportedFileTypesLong}. Provide the document via file upload, a public URL, or a base64-encoded string. For a file that holds several invoices, make the schema an object with an array property of invoice objects (see the "Many invoices in one PDF" example) to get one item per invoice.`,
4024
4158
  tags: ["Invoice"],
4025
4159
  spec: (op) => {
4026
4160
  const spec = getDefaultSpec(op, requestExamples$1);