@pdfvector/instance-client 0.1.0 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @pdfvector/instance-client
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#515](https://github.com/phuctm97/pdfvector/pull/515) [`6f8ae23`](https://github.com/phuctm97/pdfvector/commit/6f8ae23349c1a386fb5c3fc4985b6a8f95f98616) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Correct the README: this package is ESM only and exports the contract from its main entry; point most users to @pdfvector/client.
8
+
3
9
  ## 0.1.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -14,6 +14,10 @@ pnpm add @pdfvector/instance-client
14
14
  bun add @pdfvector/instance-client
15
15
  ```
16
16
 
17
+ > **Most users should install [`@pdfvector/client`](https://www.npmjs.com/package/@pdfvector/client)** (same API, plus a CommonJS build, smaller bundles and no environment access). `@pdfvector/instance-client` is the lower-level ESM-only package `@pdfvector/client` is built from.
18
+
19
+ This package is ESM only (`import`; Node.js 20.19+/22.12+ can also `require()` it) and ships type definitions. It works in Node.js, Bun, Cloudflare Workers, and browsers; Deno needs `--allow-env`.
20
+
17
21
  ## Quick Start
18
22
 
19
23
  ```typescript
@@ -60,6 +64,7 @@ const extractResult = await client.document.extract({
60
64
  console.log(extractResult.data);
61
65
  ```
62
66
 
67
+
63
68
  ## Authentication
64
69
 
65
70
  Get your API key from the [PDF Vector dashboard](https://app.pdfvector.com/instances/2?tab=settings).
@@ -720,7 +725,7 @@ try {
720
725
  } else if (error instanceof UnauthorizedError) {
721
726
  console.error("Invalid API key; check your dashboard");
722
727
  } else if (error instanceof PaymentRequiredError) {
723
- console.error(`${error.message} (${error.suggestion})`);
728
+ console.error(error.message, error.payUrl ?? error.billingUrl ?? "");
724
729
  } else if (error instanceof TooManyRequestsError) {
725
730
  console.error(`Rate limit ${error.limit} exceeded; resets at ${error.resetAt}`);
726
731
  } else if (error instanceof EmptyDocumentError) {
@@ -731,6 +736,44 @@ try {
731
736
  }
732
737
  ```
733
738
 
739
+ ### Out of credits and billing holds (402)
740
+
741
+ `PaymentRequiredError` covers two cases. `reasonCode` holds the stable machine code from the API (`CREDITS_EXHAUSTED`, or a `BILLING_*` code such as `BILLING_UNPAID_INVOICE`, `BILLING_PAYMENT_METHOD_REQUIRED`, `BILLING_DISPUTE`, `BILLING_LINKED_UNPAID_BALANCE`, `BILLING_ACCOUNT_HOLD`). Show `message` to the user as-is.
742
+
743
+ ```typescript
744
+ import { PaymentRequiredError } from "@pdfvector/instance-client";
745
+
746
+ try {
747
+ await client.document.parse({ url: "https://example.com/document.pdf" });
748
+ } catch (error) {
749
+ if (error instanceof PaymentRequiredError) {
750
+ if (error.isBillingHold) {
751
+ // Unpaid invoice, missing payment method, dispute, or account hold.
752
+ console.error(error.message);
753
+ console.error(error.payUrl ?? error.billingUrl); // where to pay or fix billing
754
+ console.error(error.amountDue, error.currency); // minor units, e.g. 1900 "usd"
755
+ } else {
756
+ // error.isCreditsExhausted: the monthly credits are used up.
757
+ console.error(`${error.remainingCredits}/${error.totalCredits} credits left, reset on ${error.resetsAt}`);
758
+ }
759
+ }
760
+ }
761
+ ```
762
+
763
+ | Field | Type | Description |
764
+ |-------|------|-------------|
765
+ | `isCreditsExhausted` | `boolean` | The monthly credits are used up |
766
+ | `isBillingHold` | `boolean` | Requests are blocked by a billing problem (`reasonCode` starts with `BILLING_`) |
767
+ | `totalCredits` | `number \| undefined` | Monthly credits of the plan |
768
+ | `remainingCredits` | `number \| undefined` | Credits left in the current period |
769
+ | `resetsAt` | `string \| undefined` | ISO date when the credits reset |
770
+ | `billingReason` | `string \| undefined` | Billing hold reason from the API |
771
+ | `invoiceCount` | `number \| undefined` | Number of unpaid invoices |
772
+ | `amountDue` | `number \| undefined` | Outstanding amount in minor currency units (cents) |
773
+ | `currency` | `string \| undefined` | Currency of `amountDue`, such as `usd` |
774
+ | `billingUrl` | `string \| undefined` | Billing page to update the payment method or see invoices |
775
+ | `payUrl` | `string \| undefined` | Direct link to pay the outstanding invoice (absent for disputes and account holds) |
776
+
734
777
  ### Error Class Hierarchy
735
778
 
736
779
  ```
@@ -747,7 +790,7 @@ PDFVectorError
747
790
  │ ├── InvalidSchemaError — reason
748
791
  │ └── NoInputProvidedError
749
792
  ├── UnauthorizedError (401)
750
- ├── PaymentRequiredError (402) — totalCredits, remainingCredits, resetsAt
793
+ ├── PaymentRequiredError (402) — totalCredits, remainingCredits, resetsAt, payUrl, billingUrl, …
751
794
  ├── NotFoundError (404)
752
795
  │ ├── AcademicPaperNotFoundError — input, paperErrorCode
753
796
  │ └── NoPublicPDFError — input, paperTitle, doi, providerURL
@@ -790,7 +833,7 @@ Use `error.toAgentError()` or `JSON.stringify(error)` when you need a serializab
790
833
  |------|--------|-------------|
791
834
  | `BAD_REQUEST` | 400 | Input validation failed, including invalid URLs, unsupported formats, file size limits, page limits, invalid base64, and invalid JSON Schema |
792
835
  | `UNAUTHORIZED` | 401 | Missing, invalid or deleted API key |
793
- | `PAYMENT_REQUIRED` | 402 | The workspace has used all of its monthly credits; the message says when they reset and links to the plan page |
836
+ | `PAYMENT_REQUIRED` | 402 | The workspace has used all of its monthly credits, or requests are on a billing hold (for example an unpaid invoice); see [Out of credits and billing holds](#out-of-credits-and-billing-holds-402) |
794
837
  | `NOT_FOUND` | 404 | Resource not found, including academic paper IDs and papers without public PDFs |
795
838
  | `CONFLICT` | 409 | Operation conflicts with the current state |
796
839
  | `UNPROCESSABLE_CONTENT` | 422 | Document could not be processed, including empty documents, no readable text, and extraction failures |
@@ -853,12 +896,15 @@ import type {
853
896
  } from "@pdfvector/instance-client";
854
897
  ```
855
898
 
856
- ## Runtime Support
899
+ Request and response types are inferred from the API contract, so `client.document.parse(...)` is fully typed without extra imports. With `skipLibCheck: false`, also install `@opentelemetry/api` (an optional type dependency of oRPC), or use `@pdfvector/client`. They reference the standard `fetch` types (`Blob`, `ReadableStream`, `AbortSignal`), so include the `dom` lib or `@types/node`.
900
+
901
+ The contract (oRPC router with zod schemas) and `pdfvectorModelSchema` are exported from the main entry:
857
902
 
858
- - **Node.js**: 20+
859
- - **Bun**: 1.0+
860
- - **ESM only** (CommonJS is not supported)
861
- - Uses standard `fetch` API
903
+ ```typescript
904
+ import { contract, pdfvectorModelSchema } from "@pdfvector/instance-client";
905
+
906
+ pdfvectorModelSchema.parse("nano"); // "nano" | "mini" | "pro" | "max"
907
+ ```
862
908
 
863
909
  ## Support
864
910
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfvector/instance-client",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "Official TypeScript/JavaScript SDK for PDF Vector API - Parse PDF/Word/Image/Excel documents to clean, structured markdown format and search academic publications across multiple databases",
6
6
  "license": "MIT",