@talonic/docs 0.21.29 → 0.21.30
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/content.js +1164 -141
- package/package.json +1 -1
package/dist/content.js
CHANGED
|
@@ -46028,264 +46028,1287 @@ var sections_default = [
|
|
|
46028
46028
|
slug: "sdk-introduction",
|
|
46029
46029
|
parentSlug: "sdk-overview",
|
|
46030
46030
|
title: "Introduction",
|
|
46031
|
-
seoTitle: "Node SDK Introduction \u2014
|
|
46032
|
-
description: "Official Talonic SDK for Node.js and TypeScript
|
|
46031
|
+
seoTitle: "Talonic Node.js SDK Introduction \u2014 TypeScript Client Docs",
|
|
46032
|
+
description: "Official Talonic SDK for Node.js and TypeScript: extract structured, schema-validated data from any document with typed resources, retries, and a CLI.",
|
|
46033
46033
|
content: [
|
|
46034
|
-
{
|
|
46035
|
-
|
|
46036
|
-
|
|
46034
|
+
{
|
|
46035
|
+
type: "paragraph",
|
|
46036
|
+
text: "Official Talonic SDK for Node.js and TypeScript. Extract structured, schema-validated data from any document."
|
|
46037
|
+
},
|
|
46038
|
+
{
|
|
46039
|
+
type: "paragraph",
|
|
46040
|
+
text: "The SDK wraps the [Talonic REST API](https://talonic.com/docs/api) with a typed client, automatic retries, structured errors, and a CLI. Zero runtime dependencies."
|
|
46041
|
+
},
|
|
46042
|
+
{
|
|
46043
|
+
type: "paragraph",
|
|
46044
|
+
text: "The client exposes resource objects for every API namespace: **documents**, **extractions**, **schemas**, **jobs**, **fields**, **credits**, **pricing**, and **usage**. Each resource provides typed methods that return structured responses with rate-limit and cost metadata attached."
|
|
46045
|
+
},
|
|
46046
|
+
{
|
|
46047
|
+
type: "paragraph",
|
|
46048
|
+
text: "Every HTTP call goes through a shared transport layer that handles authentication, retries with exponential backoff, timeout enforcement, and error mapping. You configure these behaviors once in the constructor and every method call inherits them."
|
|
46049
|
+
},
|
|
46050
|
+
{
|
|
46051
|
+
type: "paragraph",
|
|
46052
|
+
text: "The top-level `extract()` method is the fastest path from document to structured data. Pass a local file path, a remote URL, in-memory bytes, or a previously uploaded `document_id` alongside an inline schema or a saved `schema_id`. The SDK reads the file, uploads it as multipart form data, and returns typed JSON in a single await. Every response also carries `rateLimit` and `cost` metadata parsed from response headers, so you can build budget-aware pipelines without extra API calls."
|
|
46053
|
+
},
|
|
46054
|
+
{
|
|
46055
|
+
type: "code",
|
|
46056
|
+
language: "typescript",
|
|
46057
|
+
title: "Create a client and extract",
|
|
46058
|
+
code: "import { Talonic } from '@talonic/node'\n\nconst talonic = new Talonic({ apiKey: process.env.TALONIC_API_KEY! })\n\n// Extract structured data from a local PDF\nconst result = await talonic.extract({\n file_path: './contract.pdf',\n schema: {\n type: 'object',\n properties: {\n parties: {\n type: 'array',\n items: {\n type: 'object',\n properties: { name: { type: 'string' }, role: { type: 'string' } },\n },\n },\n effective_date: { type: 'string', format: 'date' },\n termination_clause: { type: 'string' },\n governing_law: { type: 'string' },\n },\n },\n})\n\nconsole.log(result.data)\n// { parties: [{ name: 'Acme Corp', role: 'Licensor' }, ...], effective_date: '2025-01-15', ... }\nconsole.log(result.cost)\n// { costCredits: 8, costEur: 0.04, balanceCredits: 1892, ... }"
|
|
46059
|
+
},
|
|
46060
|
+
{
|
|
46061
|
+
type: "paragraph",
|
|
46062
|
+
text: "Beyond extraction, the SDK provides full CRUD access to your workspace. Use `talonic.documents` to list, inspect, re-extract, filter, and delete uploaded files. Use `talonic.schemas` to create and manage reusable extraction definitions that keep your output consistent across calls and team members. Use `talonic.jobs` for asynchronous batch extraction across many documents, and `talonic.credits.getBalance()` to monitor your workspace credit balance, burn rate, and projected runway."
|
|
46063
|
+
},
|
|
46064
|
+
{
|
|
46065
|
+
type: "code",
|
|
46066
|
+
language: "typescript",
|
|
46067
|
+
title: "Explore your workspace",
|
|
46068
|
+
code: "// List all documents in your workspace\nconst docs = await talonic.documents.list({ limit: 10 })\nconsole.log(docs.data.map(d => d.filename))\n\n// Search across documents, fields, sources, and schemas\nconst hits = await talonic.search('indemnification clause')\nconsole.log(hits.documents)\nconsole.log(hits.fieldMatches)\n\n// Check your credit balance\nconst balance = await talonic.credits.getBalance()\nconsole.log(`${balance.balance_credits} credits remaining (${balance.projected_runway_days} days runway)`)"
|
|
46069
|
+
},
|
|
46070
|
+
{
|
|
46071
|
+
type: "paragraph",
|
|
46072
|
+
text: "The SDK ships both ESM and CJS builds with full TypeScript declarations, so it integrates cleanly into any modern Node.js project. Every error is a typed `TalonicError` subclass with `status`, `code`, and `requestId` properties, making it straightforward to handle failures in a structured way. The global `search()` method lets you query across documents, fields, sources, and schemas in a single call, useful for building search interfaces or validating that data exists before running an extraction."
|
|
46073
|
+
},
|
|
46074
|
+
{
|
|
46075
|
+
type: "callout",
|
|
46076
|
+
text: "**Looking for the AI agent path?** [`@talonic/mcp`](https://talonic.com/docs/mcp) wraps this SDK as a Model Context Protocol server. Install it into Claude Desktop, Cursor, Cline, Continue, or Cowork and any MCP-aware agent can extract documents directly."
|
|
46077
|
+
}
|
|
46037
46078
|
],
|
|
46038
46079
|
related: [
|
|
46039
|
-
{
|
|
46040
|
-
|
|
46041
|
-
|
|
46080
|
+
{
|
|
46081
|
+
label: "Installation",
|
|
46082
|
+
slug: "sdk-installation"
|
|
46083
|
+
},
|
|
46084
|
+
{
|
|
46085
|
+
label: "Quick Start",
|
|
46086
|
+
slug: "sdk-quickstart"
|
|
46087
|
+
},
|
|
46088
|
+
{
|
|
46089
|
+
label: "Extract",
|
|
46090
|
+
slug: "sdk-extract"
|
|
46091
|
+
}
|
|
46042
46092
|
],
|
|
46043
46093
|
faq: [
|
|
46044
|
-
{
|
|
46045
|
-
|
|
46094
|
+
{
|
|
46095
|
+
question: "What is @talonic/node?",
|
|
46096
|
+
answer: "The official Talonic SDK for Node.js and TypeScript. It extracts structured, schema-validated data from any document with a typed client, automatic retries, and structured errors."
|
|
46097
|
+
},
|
|
46098
|
+
{
|
|
46099
|
+
question: "Does the Talonic SDK have dependencies?",
|
|
46100
|
+
answer: "No. @talonic/node has zero runtime dependencies and requires Node.js 18 or newer."
|
|
46101
|
+
},
|
|
46102
|
+
{
|
|
46103
|
+
question: "What resources does the SDK expose?",
|
|
46104
|
+
answer: "The client exposes documents, extractions, schemas, jobs, fields, credits, pricing, and usage as typed resource objects. Each provides methods that map to the corresponding REST API endpoints."
|
|
46105
|
+
},
|
|
46106
|
+
{
|
|
46107
|
+
question: "What file formats does the Talonic SDK support?",
|
|
46108
|
+
answer: "The SDK supports PDF, PNG, JPG, TIFF, WebP, BMP, GIF, DOCX, DOC, XLSX, XLS, PPTX, PPT, TXT, Markdown, CSV, TSV, JSON, XML, HTML, EML, MSG, and ZIP files. MIME types are inferred from the file extension, or you can set content_type explicitly."
|
|
46109
|
+
},
|
|
46110
|
+
{
|
|
46111
|
+
question: "Does the SDK include a search method?",
|
|
46112
|
+
answer: "Yes. The top-level talonic.search() method runs a global omnisearch across documents, fields, sources, and schemas. It returns categorized hits for each entity type and accepts an optional limit parameter to control results per type."
|
|
46113
|
+
},
|
|
46114
|
+
{
|
|
46115
|
+
question: "How does the SDK handle rate limiting and costs?",
|
|
46116
|
+
answer: "Every response includes rateLimit metadata (limit, remaining, resetAt) parsed from X-RateLimit-* headers. Extract responses also carry cost metadata (costCredits, costEur, balanceCredits) parsed from X-Talonic-Cost-* headers. The SDK retries 429 rate-limit responses automatically, respecting the server-provided reset timestamp."
|
|
46117
|
+
}
|
|
46046
46118
|
],
|
|
46047
|
-
mentions: [
|
|
46119
|
+
mentions: [
|
|
46120
|
+
"Node.js",
|
|
46121
|
+
"TypeScript",
|
|
46122
|
+
"SDK",
|
|
46123
|
+
"document extraction"
|
|
46124
|
+
]
|
|
46048
46125
|
},
|
|
46049
46126
|
{
|
|
46050
46127
|
slug: "sdk-installation",
|
|
46051
46128
|
parentSlug: "sdk-overview",
|
|
46052
46129
|
title: "Installation",
|
|
46053
|
-
seoTitle: "Install Talonic Node SDK
|
|
46054
|
-
description: "Install the
|
|
46130
|
+
seoTitle: "Install @talonic/node \u2014 Talonic Node.js SDK Setup Guide",
|
|
46131
|
+
description: "Install the official Talonic Node.js SDK with npm, yarn, pnpm, or bun. Requires Node.js 18+, ships ESM and CJS builds, and has zero runtime dependencies.",
|
|
46055
46132
|
content: [
|
|
46056
|
-
{
|
|
46057
|
-
|
|
46133
|
+
{
|
|
46134
|
+
type: "code",
|
|
46135
|
+
language: "bash",
|
|
46136
|
+
code: "npm install @talonic/node"
|
|
46137
|
+
},
|
|
46138
|
+
{
|
|
46139
|
+
type: "paragraph",
|
|
46140
|
+
text: "The SDK requires Node.js 18 or newer and has zero runtime dependencies, so installing it adds exactly one package to your `node_modules`. There is nothing else to configure: no build step, no peer dependencies, and no native bindings. The published package includes the compiled JavaScript, TypeScript declaration files, and the `talonic` CLI binary."
|
|
46141
|
+
},
|
|
46142
|
+
{
|
|
46143
|
+
type: "paragraph",
|
|
46144
|
+
text: "The package works with npm, yarn, pnpm, and bun. It ships ESM and CJS builds with full TypeScript declarations, so it integrates cleanly into any modern Node.js project without additional configuration."
|
|
46145
|
+
},
|
|
46146
|
+
{
|
|
46147
|
+
type: "paragraph",
|
|
46148
|
+
text: "The SDK relies on the built-in `fetch` available in Node.js 18+. If you are running an older Node.js version, pass a fetch polyfill (such as `node-fetch`) via the `fetch` constructor option."
|
|
46149
|
+
},
|
|
46150
|
+
{
|
|
46151
|
+
type: "code",
|
|
46152
|
+
language: "bash",
|
|
46153
|
+
title: "Install with other package managers",
|
|
46154
|
+
code: "# yarn\nyarn add @talonic/node\n\n# pnpm\npnpm add @talonic/node\n\n# bun\nbun add @talonic/node"
|
|
46155
|
+
},
|
|
46156
|
+
{
|
|
46157
|
+
type: "paragraph",
|
|
46158
|
+
text: "After installation the `talonic` CLI binary is available in your project. Run `npx talonic --help` to verify the install. The CLI covers the most common operations \u2014 extraction, schema listing, and document listing \u2014 so you can test your API key from the terminal before writing any code. If you installed globally with `npm install -g @talonic/node`, the `talonic` command is available directly without `npx`."
|
|
46159
|
+
},
|
|
46160
|
+
{
|
|
46161
|
+
type: "heading",
|
|
46162
|
+
level: 3,
|
|
46163
|
+
id: "get-api-key",
|
|
46164
|
+
text: "Get an API key (30 seconds)"
|
|
46165
|
+
},
|
|
46166
|
+
{
|
|
46167
|
+
type: "paragraph",
|
|
46168
|
+
text: "Every user runs against their own Talonic workspace, so each user needs their own key. Workspaces are fully isolated: the documents you upload, the schemas you create, and the extractions you run are private to your workspace and invisible to every other account. Keys carry the `tlnc_` prefix and authenticate every SDK and CLI call via a bearer header."
|
|
46169
|
+
},
|
|
46170
|
+
{
|
|
46171
|
+
type: "list",
|
|
46172
|
+
ordered: true,
|
|
46173
|
+
items: [
|
|
46174
|
+
"Sign up at [app.talonic.com](https://app.talonic.com). Free tier: 50 extractions per day, no credit card.",
|
|
46175
|
+
"Settings \u2192 API Keys \u2192 Create New Key.",
|
|
46176
|
+
"Copy the `tlnc_` value.",
|
|
46177
|
+
"Set it as the `TALONIC_API_KEY` environment variable, or pass it directly to the client constructor."
|
|
46178
|
+
]
|
|
46179
|
+
},
|
|
46180
|
+
{
|
|
46181
|
+
type: "code",
|
|
46182
|
+
language: "typescript",
|
|
46183
|
+
title: "Verify your installation",
|
|
46184
|
+
code: "import { Talonic } from '@talonic/node'\n\nconst talonic = new Talonic({ apiKey: process.env.TALONIC_API_KEY! })\n\n// Quick smoke test: check your credit balance\nconst balance = await talonic.credits.getBalance()\nconsole.log(`Connected! Balance: ${balance.balance_credits} credits (${balance.tier} tier)`)"
|
|
46185
|
+
},
|
|
46186
|
+
{
|
|
46187
|
+
type: "paragraph",
|
|
46188
|
+
text: "The constructor validates that the `apiKey` is a non-empty string and that a `fetch` implementation is available. It throws a `TypeError` immediately if either check fails, so you will catch configuration problems at startup rather than on the first API call. The SDK does not validate the `tlnc_` prefix or contact the server during construction; authentication errors surface on the first actual request as a `TalonicAuthError` with status 401 or 403."
|
|
46189
|
+
},
|
|
46190
|
+
{
|
|
46191
|
+
type: "code",
|
|
46192
|
+
language: "bash",
|
|
46193
|
+
title: "Verify from the terminal",
|
|
46194
|
+
code: '# Set your API key\nexport TALONIC_API_KEY=tlnc_your_key_here\n\n# Test the connection by listing your saved schemas\nnpx talonic schemas list\n# { "data": [ ... ], "pagination": { ... }, ... }'
|
|
46195
|
+
},
|
|
46196
|
+
{
|
|
46197
|
+
type: "callout",
|
|
46198
|
+
text: "Store your API key in an environment variable or secrets manager. Never commit `tlnc_` values to version control."
|
|
46199
|
+
}
|
|
46058
46200
|
],
|
|
46059
46201
|
related: [
|
|
46060
|
-
{
|
|
46061
|
-
|
|
46202
|
+
{
|
|
46203
|
+
label: "Authentication",
|
|
46204
|
+
slug: "sdk-authentication"
|
|
46205
|
+
},
|
|
46206
|
+
{
|
|
46207
|
+
label: "Quick Start",
|
|
46208
|
+
slug: "sdk-quickstart"
|
|
46209
|
+
}
|
|
46062
46210
|
],
|
|
46063
46211
|
faq: [
|
|
46064
|
-
{
|
|
46212
|
+
{
|
|
46213
|
+
question: "How do I install the Talonic SDK?",
|
|
46214
|
+
answer: "Run npm install @talonic/node. Requires Node.js 18+ with zero runtime dependencies. Also works with yarn, pnpm, and bun."
|
|
46215
|
+
},
|
|
46216
|
+
{
|
|
46217
|
+
question: "How do I get a Talonic API key?",
|
|
46218
|
+
answer: "Sign up at app.talonic.com (free tier, no credit card), then go to Settings > API Keys > Create New Key. Keys use the tlnc_ prefix."
|
|
46219
|
+
},
|
|
46220
|
+
{
|
|
46221
|
+
question: "Does the SDK ship ESM and CJS builds?",
|
|
46222
|
+
answer: "Yes. The package includes both ESM and CJS builds with full TypeScript declarations. It integrates into any modern Node.js project without additional bundler configuration, and the types are auto-discovered by TypeScript without manual setup."
|
|
46223
|
+
},
|
|
46224
|
+
{
|
|
46225
|
+
question: "How do I verify my installation is working?",
|
|
46226
|
+
answer: "After installing, create a Talonic client with your API key and call talonic.credits.getBalance(). If the call succeeds and returns your balance, the SDK is correctly installed and your key is valid. From the terminal, run npx talonic schemas list as an equivalent smoke test."
|
|
46227
|
+
}
|
|
46065
46228
|
],
|
|
46066
|
-
mentions: [
|
|
46229
|
+
mentions: [
|
|
46230
|
+
"npm",
|
|
46231
|
+
"API key",
|
|
46232
|
+
"Node.js 18"
|
|
46233
|
+
]
|
|
46067
46234
|
},
|
|
46068
46235
|
{
|
|
46069
46236
|
slug: "sdk-authentication",
|
|
46070
46237
|
parentSlug: "sdk-overview",
|
|
46071
46238
|
title: "Authentication",
|
|
46072
|
-
seoTitle: "
|
|
46073
|
-
description: "
|
|
46239
|
+
seoTitle: "API Key Authentication \u2014 Talonic Node.js SDK Setup Docs",
|
|
46240
|
+
description: "Create a Talonic API key at app.talonic.com and authenticate the Node SDK via the TALONIC_API_KEY environment variable or the apiKey constructor option.",
|
|
46074
46241
|
content: [
|
|
46075
|
-
{
|
|
46076
|
-
|
|
46077
|
-
"
|
|
46078
|
-
|
|
46079
|
-
|
|
46080
|
-
"
|
|
46081
|
-
|
|
46082
|
-
|
|
46242
|
+
{
|
|
46243
|
+
type: "paragraph",
|
|
46244
|
+
text: "Every request the SDK makes is authenticated with a workspace API key. Keys carry the `tlnc_` prefix and are sent as an `Authorization: Bearer` header on every HTTP call, so you never handle raw headers yourself. Each user runs against their own Talonic workspace: the documents you upload, the schemas you create, and the extractions you run are private to your workspace and invisible to every other account."
|
|
46245
|
+
},
|
|
46246
|
+
{
|
|
46247
|
+
type: "paragraph",
|
|
46248
|
+
text: "Getting a key takes about thirty seconds. Sign up at [app.talonic.com](https://app.talonic.com) \u2014 the free tier includes 50 extractions per day with no credit card \u2014 then open Settings \u2192 API Keys \u2192 Create New Key and copy the `tlnc_` value. Set it as the `TALONIC_API_KEY` environment variable, or pass it directly to the client constructor via the `apiKey` option if your deployment injects secrets differently."
|
|
46249
|
+
},
|
|
46250
|
+
{
|
|
46251
|
+
type: "code",
|
|
46252
|
+
language: "typescript",
|
|
46253
|
+
title: "Authenticate the client",
|
|
46254
|
+
code: "import { Talonic } from '@talonic/node'\n\n// Recommended: read the key from the environment\nconst talonic = new Talonic({ apiKey: process.env.TALONIC_API_KEY! })\n\n// The same key also powers the bundled CLI:\n// export TALONIC_API_KEY=tlnc_your_key_here\n// npx talonic schemas list"
|
|
46255
|
+
},
|
|
46256
|
+
{
|
|
46257
|
+
type: "paragraph",
|
|
46258
|
+
text: "The constructor validates that `apiKey` is a non-empty string and throws a `TypeError` immediately if it is missing, so misconfiguration surfaces at startup rather than mid-pipeline. It does not contact the server or validate the `tlnc_` prefix during construction: an invalid or revoked key surfaces on the first real request as a `TalonicAuthError` with status 401, and a key lacking permission for an operation surfaces as the same class with status 403."
|
|
46259
|
+
},
|
|
46260
|
+
{
|
|
46261
|
+
type: "code",
|
|
46262
|
+
language: "typescript",
|
|
46263
|
+
title: "Handle authentication failures",
|
|
46264
|
+
code: "import { Talonic, TalonicAuthError } from '@talonic/node'\n\nconst talonic = new Talonic({ apiKey: process.env.TALONIC_API_KEY! })\n\ntry {\n const schemas = await talonic.schemas.list()\n console.log(`Authenticated \u2014 ${schemas.data.length} schemas visible`)\n} catch (err) {\n if (err instanceof TalonicAuthError) {\n // 401: key missing/invalid/revoked; 403: insufficient permissions\n console.error(`Auth failed (status ${err.status}): ${err.message}`)\n process.exit(1)\n }\n throw err\n}"
|
|
46265
|
+
},
|
|
46266
|
+
{
|
|
46267
|
+
type: "paragraph",
|
|
46268
|
+
text: "Authentication errors are never retried: the SDK throws `TalonicAuthError` on the first 401 or 403 response regardless of the `maxRetries` setting, because retrying a bad credential cannot succeed. That makes a cheap read-only call such as `talonic.schemas.list()` a good startup health check \u2014 it verifies the key, the network path, and the base URL in one request without consuming any credits."
|
|
46269
|
+
},
|
|
46270
|
+
{
|
|
46271
|
+
type: "callout",
|
|
46272
|
+
variant: "warning",
|
|
46273
|
+
text: "Treat `tlnc_` keys like passwords: store them in environment variables or a secrets manager, never commit them to version control, and rotate them from the dashboard (Settings \u2192 API Keys) if one leaks. The CLI deliberately has no `--api-key` flag so keys stay out of shell history."
|
|
46274
|
+
}
|
|
46083
46275
|
],
|
|
46084
46276
|
related: [
|
|
46085
|
-
{
|
|
46086
|
-
|
|
46277
|
+
{
|
|
46278
|
+
label: "Configuration",
|
|
46279
|
+
slug: "sdk-configuration"
|
|
46280
|
+
},
|
|
46281
|
+
{
|
|
46282
|
+
label: "Quick Start",
|
|
46283
|
+
slug: "sdk-quickstart"
|
|
46284
|
+
},
|
|
46285
|
+
{
|
|
46286
|
+
label: "Error Classes",
|
|
46287
|
+
slug: "sdk-error-classes"
|
|
46288
|
+
}
|
|
46087
46289
|
],
|
|
46088
46290
|
faq: [
|
|
46089
|
-
{
|
|
46291
|
+
{
|
|
46292
|
+
question: "How do I get a Talonic API key?",
|
|
46293
|
+
answer: "Sign up at app.talonic.com (the free tier includes 50 extractions per day, no credit card), then go to Settings > API Keys > Create New Key and copy the tlnc_ value. Set it as TALONIC_API_KEY or pass it to the constructor as apiKey."
|
|
46294
|
+
},
|
|
46295
|
+
{
|
|
46296
|
+
question: "Does the SDK validate my API key when I create the client?",
|
|
46297
|
+
answer: "No. The constructor only checks that apiKey is a non-empty string; it makes no network calls. An invalid key surfaces on the first request as a TalonicAuthError with status 401, and insufficient permissions surface as status 403."
|
|
46298
|
+
},
|
|
46299
|
+
{
|
|
46300
|
+
question: "Are API keys shared across a workspace?",
|
|
46301
|
+
answer: "Keys belong to a workspace, and workspaces are fully isolated from each other. Anyone with a key for a workspace sees that workspace's documents, schemas, and extractions \u2014 so issue separate keys per environment and rotate them from the dashboard when needed."
|
|
46302
|
+
},
|
|
46303
|
+
{
|
|
46304
|
+
question: "Are authentication failures retried?",
|
|
46305
|
+
answer: "No. 401 and 403 responses are non-retryable: the SDK throws TalonicAuthError immediately regardless of maxRetries, because retrying a bad credential cannot succeed. Fix or rotate the key and retry the call yourself."
|
|
46306
|
+
}
|
|
46090
46307
|
],
|
|
46091
|
-
mentions: [
|
|
46308
|
+
mentions: [
|
|
46309
|
+
"API key",
|
|
46310
|
+
"TALONIC_API_KEY",
|
|
46311
|
+
"tlnc_",
|
|
46312
|
+
"authentication",
|
|
46313
|
+
"workspace"
|
|
46314
|
+
]
|
|
46092
46315
|
},
|
|
46093
46316
|
{
|
|
46094
46317
|
slug: "sdk-quickstart",
|
|
46095
46318
|
parentSlug: "sdk-overview",
|
|
46096
46319
|
title: "Quick Start",
|
|
46097
|
-
seoTitle: "
|
|
46098
|
-
description: "Extract structured data from a
|
|
46320
|
+
seoTitle: "Quick Start \u2014 Extract Document Data with Talonic Node SDK",
|
|
46321
|
+
description: "Extract structured data from a PDF in five lines of TypeScript: create a Talonic client, call extract() with a schema, and read typed, validated results.",
|
|
46099
46322
|
content: [
|
|
46100
|
-
{
|
|
46323
|
+
{
|
|
46324
|
+
type: "paragraph",
|
|
46325
|
+
text: "Extract structured data from a document in five lines. Create a client, call **extract()** with a file and schema, and read the typed result."
|
|
46326
|
+
},
|
|
46327
|
+
{
|
|
46328
|
+
type: "code",
|
|
46329
|
+
language: "typescript",
|
|
46330
|
+
title: "Extract an invoice",
|
|
46331
|
+
code: "import { Talonic } from '@talonic/node'\n\nconst talonic = new Talonic({ apiKey: process.env.TALONIC_API_KEY! })\n\nconst result = await talonic.extract({\n file_path: './invoice.pdf',\n schema: {\n type: 'object',\n properties: {\n vendor_name: { type: 'string' },\n invoice_number: { type: 'string' },\n total_amount: { type: 'number' },\n due_date: { type: 'string', format: 'date' },\n },\n },\n})\n\nconsole.log(result.data)\n// { vendor_name: 'Acme Corp', invoice_number: 'INV-2024-0847', total_amount: 14250, due_date: '2024-03-15' }"
|
|
46332
|
+
},
|
|
46333
|
+
{
|
|
46334
|
+
type: "paragraph",
|
|
46335
|
+
text: 'The `result` object contains the extracted `data` matching your schema, plus `rateLimit` and `cost` metadata. The `data` fields are typed according to your schema definition, so `total_amount` comes back as a number and `due_date` as a date string. Pass a full JSON Schema with `type: "object"` and `properties` for reliable results; when you omit the `required` array, the SDK auto-populates it from `properties` so the API cannot silently return `null` for fields you clearly intended to extract.'
|
|
46336
|
+
},
|
|
46337
|
+
{
|
|
46338
|
+
type: "paragraph",
|
|
46339
|
+
text: "You can also pass `file_url` for remote files or `file` with `filename` for in-memory bytes (Blob, Buffer, or Uint8Array). For documents already uploaded to your workspace, pass `document_id` to skip the upload step entirely. The SDK accepts exactly one file source per call and validates this at runtime, throwing a `TalonicError` with code `missing_file_source` or `multiple_file_sources` if the constraint is violated."
|
|
46340
|
+
},
|
|
46341
|
+
{
|
|
46342
|
+
type: "code",
|
|
46343
|
+
language: "typescript",
|
|
46344
|
+
title: "Extract from a URL",
|
|
46345
|
+
code: "// Extract from a remote file \u2014 no local download needed\nconst result = await talonic.extract({\n file_url: 'https://example.com/reports/q4-2025.pdf',\n schema: {\n type: 'object',\n properties: {\n report_title: { type: 'string' },\n period: { type: 'string' },\n revenue: { type: 'number' },\n net_income: { type: 'number' },\n highlights: { type: 'array', items: { type: 'string' } },\n },\n },\n})\n\nconsole.log(result.data.revenue) // 4250000\nconsole.log(result.confidence?.overall) // 0.94\nconsole.log(result.document.pages) // 12"
|
|
46346
|
+
},
|
|
46347
|
+
{
|
|
46348
|
+
type: "paragraph",
|
|
46349
|
+
text: "All **extract()** calls are async and return a `Promise`. The SDK handles retries, timeouts, and error mapping automatically, so you only need a single `try/catch` around your call for error handling. Retryable failures (429, 5xx, network errors, timeouts) are retried up to `maxRetries` times with exponential backoff, so transient hiccups do not require manual retry logic."
|
|
46350
|
+
},
|
|
46351
|
+
{
|
|
46352
|
+
type: "code",
|
|
46353
|
+
language: "typescript",
|
|
46354
|
+
title: "Extract with error handling",
|
|
46355
|
+
code: "import { Talonic, TalonicAuthError, TalonicValidationError, TalonicError } from '@talonic/node'\n\nconst talonic = new Talonic({ apiKey: process.env.TALONIC_API_KEY! })\n\ntry {\n const result = await talonic.extract({\n file_path: './receipt.png',\n schema: {\n type: 'object',\n properties: {\n merchant: { type: 'string' },\n date: { type: 'string', format: 'date' },\n total: { type: 'number' },\n items: {\n type: 'array',\n items: {\n type: 'object',\n properties: { name: { type: 'string' }, price: { type: 'number' } },\n },\n },\n },\n },\n })\n console.log(`Extracted ${result.data.items?.length ?? 0} line items from ${result.document.filename}`)\n console.log(`Cost: ${result.cost?.costCredits} credits, balance: ${result.cost?.balanceCredits}`)\n} catch (err) {\n if (err instanceof TalonicAuthError) {\n console.error('Invalid API key \u2014 check TALONIC_API_KEY')\n } else if (err instanceof TalonicValidationError) {\n console.error(`Bad request: ${err.message} (code: ${err.code})`)\n } else if (err instanceof TalonicError) {\n console.error(`Talonic error: ${err.code} (status ${err.status}, request ${err.requestId})`)\n }\n}"
|
|
46356
|
+
},
|
|
46357
|
+
{
|
|
46358
|
+
type: "paragraph",
|
|
46359
|
+
text: "The `extract()` response includes rich metadata beyond the extracted data. The `document` block contains the filename, page count, file size, detected MIME type, and detected language. The optional `confidence` block provides an overall confidence score and per-field scores. The `processing` block reports duration, pages processed, and the region that handled the request. Use these fields to build quality gates and observability into your extraction pipeline."
|
|
46360
|
+
},
|
|
46361
|
+
{
|
|
46362
|
+
type: "code",
|
|
46363
|
+
language: "typescript",
|
|
46364
|
+
title: "Re-extract a previously uploaded document with a saved schema",
|
|
46365
|
+
code: "// Use document_id + schema_id to re-extract without re-uploading\nconst result = await talonic.extract({\n document_id: 'doc_abc123',\n schema_id: 'sch_def456',\n instructions: 'Focus on the indemnification and liability sections',\n include_markdown: true,\n})\n\nconsole.log(result.data) // structured extraction\nconsole.log(result.markdown) // raw OCR markdown (when include_markdown is true)\nconsole.log(result.schema) // { source: 'saved', id: 'sch_def456', definition: { ... } }"
|
|
46366
|
+
},
|
|
46367
|
+
{
|
|
46368
|
+
type: "callout",
|
|
46369
|
+
text: "This example uses top-level `await`. If your environment does not support it, wrap the code in an `async` function."
|
|
46370
|
+
}
|
|
46101
46371
|
],
|
|
46102
46372
|
related: [
|
|
46103
|
-
{
|
|
46104
|
-
|
|
46105
|
-
|
|
46373
|
+
{
|
|
46374
|
+
label: "Extract",
|
|
46375
|
+
slug: "sdk-extract"
|
|
46376
|
+
},
|
|
46377
|
+
{
|
|
46378
|
+
label: "Schemas",
|
|
46379
|
+
slug: "sdk-schemas"
|
|
46380
|
+
},
|
|
46381
|
+
{
|
|
46382
|
+
label: "Configuration",
|
|
46383
|
+
slug: "sdk-configuration"
|
|
46384
|
+
}
|
|
46106
46385
|
],
|
|
46107
46386
|
faq: [
|
|
46108
|
-
{
|
|
46387
|
+
{
|
|
46388
|
+
question: "How do I extract data from a PDF with the Talonic SDK?",
|
|
46389
|
+
answer: "Import Talonic, create a client with your API key, and call talonic.extract() with a file path and schema. The result contains structured, schema-validated JSON."
|
|
46390
|
+
},
|
|
46391
|
+
{
|
|
46392
|
+
question: "What does the extract result contain?",
|
|
46393
|
+
answer: "The result includes a data object with fields matching your schema, plus rateLimit (limit, remaining, resetAt) and cost (credits consumed, EUR value, post-call balance) metadata. It also contains document metadata (filename, pages, size_bytes, mime_type), optional confidence scores (overall and per-field), and processing info (duration_ms, region)."
|
|
46394
|
+
},
|
|
46395
|
+
{
|
|
46396
|
+
question: "Can I extract from a URL instead of a local file?",
|
|
46397
|
+
answer: "Yes. Pass file_url instead of file_path to extract from a remote document. The SDK fetches the file server-side, so you do not need to download it first."
|
|
46398
|
+
},
|
|
46399
|
+
{
|
|
46400
|
+
question: "Can I pass natural-language instructions to guide extraction?",
|
|
46401
|
+
answer: "Yes. The extract() method accepts an optional instructions parameter where you can provide natural-language guidance like 'Focus on the indemnification section' or 'Extract amounts in USD only'. Instructions are forwarded to the extraction engine alongside the schema to improve accuracy for ambiguous documents."
|
|
46402
|
+
},
|
|
46403
|
+
{
|
|
46404
|
+
question: "How do I extract only specific pages from a PDF?",
|
|
46405
|
+
answer: "Pass the options.page_range parameter with a page specification like '1-5' or '1,3,7-10'. This tells the extraction engine to process only those pages, which reduces processing time and credit consumption for large documents."
|
|
46406
|
+
},
|
|
46407
|
+
{
|
|
46408
|
+
question: "What happens if I pass both schema and schema_id?",
|
|
46409
|
+
answer: "The SDK throws a TalonicError with code 'multiple_schemas' immediately, before making any API call. You must provide at most one schema source: either an inline schema object or a schema_id referencing a saved schema."
|
|
46410
|
+
}
|
|
46109
46411
|
],
|
|
46110
|
-
mentions: [
|
|
46412
|
+
mentions: [
|
|
46413
|
+
"extract",
|
|
46414
|
+
"schema",
|
|
46415
|
+
"TypeScript"
|
|
46416
|
+
]
|
|
46111
46417
|
},
|
|
46112
46418
|
{
|
|
46113
46419
|
slug: "sdk-configuration",
|
|
46114
46420
|
parentSlug: "sdk-client",
|
|
46115
46421
|
title: "Configuration",
|
|
46116
|
-
seoTitle: "
|
|
46117
|
-
description: "Configure the Talonic client
|
|
46118
|
-
content: [
|
|
46119
|
-
{
|
|
46120
|
-
|
|
46121
|
-
|
|
46122
|
-
|
|
46123
|
-
|
|
46124
|
-
|
|
46125
|
-
|
|
46126
|
-
|
|
46422
|
+
seoTitle: "Client Configuration Options \u2014 Talonic Node.js SDK Docs",
|
|
46423
|
+
description: "Configure the Talonic client constructor: apiKey, baseUrl, timeout, maxRetries, and a custom fetch implementation for testing, proxies, and polyfills.",
|
|
46424
|
+
content: [
|
|
46425
|
+
{
|
|
46426
|
+
type: "paragraph",
|
|
46427
|
+
text: "Create a `Talonic` instance by passing a configuration object to the constructor. The only required field is `apiKey`; all other options have sensible defaults. The client validates the key format on construction and throws a `TypeError` if it is missing or empty."
|
|
46428
|
+
},
|
|
46429
|
+
{
|
|
46430
|
+
type: "code",
|
|
46431
|
+
language: "typescript",
|
|
46432
|
+
title: "All options",
|
|
46433
|
+
code: "import { Talonic } from '@talonic/node'\n\nconst talonic = new Talonic({\n apiKey: process.env.TALONIC_API_KEY!,\n baseUrl: 'https://api.talonic.com', // default\n timeout: 60_000, // ms; default 60s\n maxRetries: 3, // 429, 500, 502, 503, 504, network, timeout\n fetch: customFetch, // optional override (e.g. for testing)\n})"
|
|
46434
|
+
},
|
|
46435
|
+
{
|
|
46436
|
+
type: "paragraph",
|
|
46437
|
+
text: "The `TalonicConfig` interface defines the constructor shape. The `apiKey` field is the only required parameter and must be a non-empty string. The constructor does not validate the `tlnc_` prefix or make any network calls; it only checks that the key is present and that a `fetch` implementation is available. Authentication failures surface on the first API call as a `TalonicAuthError` with status 401 (invalid key) or 403 (insufficient permissions)."
|
|
46438
|
+
},
|
|
46439
|
+
{
|
|
46440
|
+
type: "paragraph",
|
|
46441
|
+
text: "The `fetch` option lets you inject a custom implementation for testing or proxying. In production on Node.js 18+, the SDK uses the built-in `globalThis.fetch` automatically. If no fetch implementation is available (Node < 18 without a polyfill), the constructor throws a `TypeError` with a clear message."
|
|
46442
|
+
},
|
|
46443
|
+
{
|
|
46444
|
+
type: "code",
|
|
46445
|
+
language: "typescript",
|
|
46446
|
+
title: "Testing with a mock fetch",
|
|
46447
|
+
code: "import { Talonic } from '@talonic/node'\n\n// Inject a custom fetch for testing\nconst mockFetch = async (url: string, init?: RequestInit) => {\n console.log(`Request: ${init?.method} ${url}`)\n return new Response(JSON.stringify({ balance_credits: 1000, tier: 'free' }), {\n status: 200,\n headers: { 'content-type': 'application/json' },\n })\n}\n\nconst talonic = new Talonic({\n apiKey: 'tlnc_test_key',\n fetch: mockFetch as typeof fetch,\n})\n\nconst balance = await talonic.credits.getBalance()\nconsole.log(balance.balance_credits) // 1000"
|
|
46448
|
+
},
|
|
46449
|
+
{
|
|
46450
|
+
type: "paragraph",
|
|
46451
|
+
text: "Adjust `timeout` for long-running extractions on large documents; the default of 60 seconds covers most cases. For multi-page PDFs or image-heavy documents, consider increasing to 120 seconds or more. Set `maxRetries` to `0` to disable automatic retries entirely, which is useful during development when you want to see errors immediately. In production, the default of 3 retries with exponential backoff handles most transient failures without any manual intervention."
|
|
46452
|
+
},
|
|
46453
|
+
{
|
|
46454
|
+
type: "code",
|
|
46455
|
+
language: "typescript",
|
|
46456
|
+
title: "Production configuration",
|
|
46457
|
+
code: "// Production: higher timeout for large documents, default retries\nconst talonic = new Talonic({\n apiKey: process.env.TALONIC_API_KEY!,\n timeout: 120_000, // 2 minutes for large documents\n maxRetries: 3, // default \u2014 retries 429, 5xx, network, timeout\n})\n\n// Development: fast feedback, no retries\nconst devClient = new Talonic({\n apiKey: process.env.TALONIC_API_KEY!,\n timeout: 30_000,\n maxRetries: 0, // fail immediately on errors\n})"
|
|
46458
|
+
},
|
|
46459
|
+
{
|
|
46460
|
+
type: "paragraph",
|
|
46461
|
+
text: "The `baseUrl` option defaults to `https://api.talonic.com` and is useful for pointing at staging environments or local proxies during development. Trailing slashes are stripped automatically. Every HTTP request sent by the SDK includes an `Authorization: Bearer <apiKey>` header, a `User-Agent: talonic-node/<version>` header, and `Accept: application/json`. For non-FormData bodies, `Content-Type: application/json` is set automatically. You can override headers on individual requests through the transport layer, but the constructor-level options cover all common configuration needs."
|
|
46462
|
+
},
|
|
46463
|
+
{
|
|
46464
|
+
type: "callout",
|
|
46465
|
+
text: "API keys use the `tlnc_` prefix. Store them in environment variables or a secrets manager rather than hard-coding them in source files."
|
|
46466
|
+
},
|
|
46467
|
+
{
|
|
46468
|
+
type: "param-table",
|
|
46469
|
+
params: [
|
|
46470
|
+
{
|
|
46471
|
+
name: "apiKey",
|
|
46472
|
+
type: "string",
|
|
46473
|
+
required: true,
|
|
46474
|
+
description: "Your Talonic API key. Starts with `tlnc_`."
|
|
46475
|
+
},
|
|
46476
|
+
{
|
|
46477
|
+
name: "baseUrl",
|
|
46478
|
+
type: "string",
|
|
46479
|
+
description: "API base URL. Trailing slashes are stripped automatically.",
|
|
46480
|
+
default: "https://api.talonic.com"
|
|
46481
|
+
},
|
|
46482
|
+
{
|
|
46483
|
+
name: "timeout",
|
|
46484
|
+
type: "number",
|
|
46485
|
+
description: "Request timeout in milliseconds. Applies per-request including retries.",
|
|
46486
|
+
default: "60000"
|
|
46487
|
+
},
|
|
46488
|
+
{
|
|
46489
|
+
name: "maxRetries",
|
|
46490
|
+
type: "number",
|
|
46491
|
+
description: "Max retry attempts for transient failures (429, 5xx, network, timeout). Set to 0 to disable.",
|
|
46492
|
+
default: "3"
|
|
46493
|
+
},
|
|
46494
|
+
{
|
|
46495
|
+
name: "fetch",
|
|
46496
|
+
type: "function",
|
|
46497
|
+
description: "Custom fetch implementation for testing, instrumentation, or polyfilling Node < 18."
|
|
46498
|
+
}
|
|
46499
|
+
]
|
|
46500
|
+
}
|
|
46127
46501
|
],
|
|
46128
46502
|
related: [
|
|
46129
|
-
{
|
|
46130
|
-
|
|
46503
|
+
{
|
|
46504
|
+
label: "Retries & Backoff",
|
|
46505
|
+
slug: "sdk-retries"
|
|
46506
|
+
},
|
|
46507
|
+
{
|
|
46508
|
+
label: "Installation",
|
|
46509
|
+
slug: "sdk-installation"
|
|
46510
|
+
},
|
|
46511
|
+
{
|
|
46512
|
+
label: "Authentication",
|
|
46513
|
+
slug: "sdk-authentication"
|
|
46514
|
+
}
|
|
46131
46515
|
],
|
|
46132
|
-
faq: [
|
|
46133
|
-
|
|
46516
|
+
faq: [
|
|
46517
|
+
{
|
|
46518
|
+
question: "How do I configure the Talonic SDK client?",
|
|
46519
|
+
answer: "Pass an options object to new Talonic() with apiKey (required), and optional baseUrl, timeout, maxRetries, and fetch. All options except apiKey have sensible defaults."
|
|
46520
|
+
},
|
|
46521
|
+
{
|
|
46522
|
+
question: "Can I disable automatic retries?",
|
|
46523
|
+
answer: "Yes. Set maxRetries to 0 in the constructor options. The SDK will throw on the first failure without retrying. This is useful during development for fast feedback on errors."
|
|
46524
|
+
},
|
|
46525
|
+
{
|
|
46526
|
+
question: "What happens if no fetch implementation is available?",
|
|
46527
|
+
answer: "The constructor throws a TypeError with the message 'no fetch implementation available'. On Node.js 18+ the built-in fetch is used automatically; on older versions, pass a polyfill via the fetch option."
|
|
46528
|
+
},
|
|
46529
|
+
{
|
|
46530
|
+
question: "Does the constructor validate the API key with the server?",
|
|
46531
|
+
answer: "No. The constructor only checks that apiKey is a non-empty string and that a fetch implementation exists. It does not make any network calls. Authentication errors (invalid key, insufficient permissions) surface on the first API call as TalonicAuthError with status 401 or 403."
|
|
46532
|
+
},
|
|
46533
|
+
{
|
|
46534
|
+
question: "What headers does the SDK send with every request?",
|
|
46535
|
+
answer: "Every request includes Authorization: Bearer <apiKey>, User-Agent: talonic-node/<version>, and Accept: application/json. For JSON bodies, Content-Type: application/json is set automatically. FormData bodies (used by extract) omit Content-Type to let the browser set the multipart boundary."
|
|
46536
|
+
}
|
|
46537
|
+
],
|
|
46538
|
+
mentions: [
|
|
46539
|
+
"configuration",
|
|
46540
|
+
"apiKey",
|
|
46541
|
+
"timeout",
|
|
46542
|
+
"maxRetries"
|
|
46543
|
+
]
|
|
46134
46544
|
},
|
|
46135
46545
|
{
|
|
46136
46546
|
slug: "sdk-extract",
|
|
46137
46547
|
parentSlug: "sdk-client",
|
|
46138
46548
|
title: "Extract",
|
|
46139
|
-
seoTitle: "
|
|
46140
|
-
description: "
|
|
46549
|
+
seoTitle: "extract() Method \u2014 Talonic Node SDK Document Extraction",
|
|
46550
|
+
description: "Call talonic.extract() with a file and JSON Schema to receive structured, validated data plus confidence scores and per-call cost metadata in one await.",
|
|
46141
46551
|
content: [
|
|
46142
|
-
{
|
|
46143
|
-
|
|
46144
|
-
|
|
46552
|
+
{
|
|
46553
|
+
type: "paragraph",
|
|
46554
|
+
text: "The top-level `extract()` method is the primary entry point. Send a document and schema, receive structured validated data."
|
|
46555
|
+
},
|
|
46556
|
+
{
|
|
46557
|
+
type: "code",
|
|
46558
|
+
language: "typescript",
|
|
46559
|
+
title: "Extract with inline schema",
|
|
46560
|
+
code: "const result = await talonic.extract({\n file_path: './invoice.pdf',\n schema: {\n type: 'object',\n properties: {\n vendor_name: { type: 'string' },\n invoice_number: { type: 'string' },\n total_amount: { type: 'number' },\n line_items: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n description: { type: 'string' },\n quantity: { type: 'number' },\n unit_price: { type: 'number' },\n },\n },\n },\n },\n },\n})\n\nconsole.log(result.data)\n// { vendor_name: 'Acme Corp', total_amount: 1234.56, ... }\nconsole.log(result.extraction_id) // 'ext_abc123'\nconsole.log(result.confidence) // { overall: 0.95, fields: { vendor_name: 0.99, ... } }"
|
|
46561
|
+
},
|
|
46562
|
+
{
|
|
46563
|
+
type: "paragraph",
|
|
46564
|
+
text: "The method signature is `extract(params: ExtractParams): Promise<WithRateLimit<ExtractResult>>`. The `ExtractParams` interface accepts exactly one file source: `file` (in-memory Blob, Buffer, or Uint8Array), `file_path` (local path read with `fs/promises`), `file_url` (remote URL fetched server-side), or `document_id` (re-extract an existing document). Provide at most one schema source: `schema` (inline object or JSON string) or `schema_id` (UUID of a saved schema). Omit both for auto-discovery, though this is not recommended in production as it may return 500 on some deployments."
|
|
46565
|
+
},
|
|
46566
|
+
{
|
|
46567
|
+
type: "paragraph",
|
|
46568
|
+
text: "Under the hood, **extract()** reads the file from disk (or fetches it from a URL), uploads it as multipart form data, and returns the structured result in a single round-trip. The response includes a `cost` block with credit consumption and a `rateLimit` object parsed from response headers."
|
|
46569
|
+
},
|
|
46570
|
+
{
|
|
46571
|
+
type: "code",
|
|
46572
|
+
language: "typescript",
|
|
46573
|
+
title: "Extract from a URL with options",
|
|
46574
|
+
code: "const result = await talonic.extract({\n file_url: 'https://example.com/contracts/nda-2025.pdf',\n schema_id: 'sch_def456',\n instructions: 'Focus on termination and non-compete clauses',\n include_markdown: true,\n options: {\n page_range: '1-5',\n language_hint: 'en',\n strict: true,\n },\n})\n\nconsole.log(result.markdown) // raw OCR text (because include_markdown: true)\nconsole.log(result.document.pages) // 5\nconsole.log(result.processing?.duration_ms) // 2340"
|
|
46575
|
+
},
|
|
46576
|
+
{
|
|
46577
|
+
type: "paragraph",
|
|
46578
|
+
text: "Additional parameters fine-tune extraction behavior. The `instructions` field accepts natural-language guidance forwarded to the extraction engine. Set `include_markdown: true` to receive the raw OCR-converted markdown alongside structured data. The `options` object supports `page_range` (e.g. `'1-5'` or `'1,3,7-10'` for PDFs), `language_hint` (ISO 639-1 code), `strict` mode (omit fields not in the schema), and `include_raw_text`. The `content_type` parameter lets you override MIME type inference when the file extension is misleading."
|
|
46579
|
+
},
|
|
46580
|
+
{
|
|
46581
|
+
type: "paragraph",
|
|
46582
|
+
text: "For best results, always supply a `schema` or `schema_id` rather than relying on auto-discovery. Inline schemas work well for one-off extractions, while saved schemas (via `schema_id`) keep your extraction definitions consistent across calls and team members."
|
|
46583
|
+
},
|
|
46584
|
+
{
|
|
46585
|
+
type: "code",
|
|
46586
|
+
language: "typescript",
|
|
46587
|
+
title: "Extract in-memory bytes",
|
|
46588
|
+
code: "import { readFile } from 'node:fs/promises'\n\n// Pass a Buffer or Uint8Array directly\nconst buffer = await readFile('./scan.tiff')\nconst result = await talonic.extract({\n file: buffer,\n filename: 'scan.tiff',\n content_type: 'image/tiff',\n schema: {\n type: 'object',\n properties: {\n patient_name: { type: 'string' },\n date_of_service: { type: 'string', format: 'date' },\n diagnosis_codes: { type: 'array', items: { type: 'string' } },\n total_charges: { type: 'number' },\n },\n },\n})\n\n// The ExtractResult includes document metadata\nconsole.log(result.document.mime_type) // 'image/tiff'\nconsole.log(result.document.size_bytes) // 4521984\nconsole.log(result.document.language_detected) // 'en'"
|
|
46589
|
+
},
|
|
46590
|
+
{
|
|
46591
|
+
type: "paragraph",
|
|
46592
|
+
text: "The `ExtractResult` response is a rich object. The `extraction_id` is a stable identifier you can use with `talonic.extractions.get()` or `talonic.extractions.getData()` to retrieve the result later. The `document` block includes `id`, `filename`, `pages`, `size_bytes`, `mime_type`, `type_detected`, and `language_detected`. The `confidence` block provides `overall` and per-field scores between 0 and 1. The `schema` block shows the source (`'inline'` or `'saved'`), the resolved definition, and a `save_url` for persisting inline schemas. The `links` block provides URLs for the extraction, document, and dashboard views."
|
|
46593
|
+
},
|
|
46594
|
+
{
|
|
46595
|
+
type: "paragraph",
|
|
46596
|
+
text: "The SDK validates parameters before making the API call. Passing zero or more than one file source throws a `TalonicError` with code `missing_file_source` or `multiple_file_sources`. Passing both `schema` and `schema_id` throws `multiple_schemas`. When using JSON Schema format with `properties` but no `required` array, the SDK auto-populates `required` with all property keys to prevent the silent-empty-data footgun where the API returns null for every field."
|
|
46597
|
+
},
|
|
46598
|
+
{
|
|
46599
|
+
type: "callout",
|
|
46600
|
+
text: "Every **extract()** response carries `cost` metadata (credits consumed, EUR value, post-call balance) and `rateLimit` info. Use these to build budget-aware pipelines without extra API calls."
|
|
46601
|
+
}
|
|
46145
46602
|
],
|
|
46146
46603
|
related: [
|
|
46147
|
-
{
|
|
46148
|
-
|
|
46149
|
-
|
|
46604
|
+
{
|
|
46605
|
+
label: "Schemas",
|
|
46606
|
+
slug: "sdk-schemas"
|
|
46607
|
+
},
|
|
46608
|
+
{
|
|
46609
|
+
label: "Documents",
|
|
46610
|
+
slug: "sdk-documents"
|
|
46611
|
+
},
|
|
46612
|
+
{
|
|
46613
|
+
label: "Quick Start",
|
|
46614
|
+
slug: "sdk-quickstart"
|
|
46615
|
+
}
|
|
46150
46616
|
],
|
|
46151
|
-
faq: [
|
|
46152
|
-
|
|
46617
|
+
faq: [
|
|
46618
|
+
{
|
|
46619
|
+
question: "What inputs does talonic.extract() accept?",
|
|
46620
|
+
answer: "It accepts file_path (local file), file_url (remote URL), file (in-memory Blob, Buffer, or Uint8Array with filename), or document_id (previously uploaded). Provide a schema or schema_id for the extraction definition."
|
|
46621
|
+
},
|
|
46622
|
+
{
|
|
46623
|
+
question: "Does extract() return cost information?",
|
|
46624
|
+
answer: "Yes. Every extract response includes a cost block with costCredits, costEur, balanceCredits, cellsResolvedRegistry, and cellsResolvedAi parsed from response headers."
|
|
46625
|
+
},
|
|
46626
|
+
{
|
|
46627
|
+
question: "Can I extract the same document with different schemas?",
|
|
46628
|
+
answer: "Yes. Pass the document_id from a previous upload along with a new schema or schema_id. The document is not re-uploaded, saving bandwidth and credits."
|
|
46629
|
+
},
|
|
46630
|
+
{
|
|
46631
|
+
question: "What does the auto-populate required behavior do?",
|
|
46632
|
+
answer: "When you pass a JSON Schema with properties but no required array, the SDK automatically adds all property keys to required. This prevents the silent-empty-data issue where the API returns null with confidence 0 for every field you intended to extract."
|
|
46633
|
+
},
|
|
46634
|
+
{
|
|
46635
|
+
question: "What file formats does extract() support?",
|
|
46636
|
+
answer: "The SDK supports PDF, PNG, JPG, TIFF, WebP, BMP, GIF, DOCX, DOC, XLSX, XLS, PPTX, PPT, TXT, Markdown, CSV, TSV, JSON, XML, HTML, EML, MSG, and ZIP. MIME types are inferred from the file extension. Use content_type to override when the extension is misleading."
|
|
46637
|
+
},
|
|
46638
|
+
{
|
|
46639
|
+
question: "How do I include the raw OCR text in the response?",
|
|
46640
|
+
answer: "Set include_markdown: true in the extract params. The response will include a markdown field containing the full OCR-converted text that the extraction engine used as input. This is useful for debugging extraction quality or building custom post-processing."
|
|
46641
|
+
}
|
|
46642
|
+
],
|
|
46643
|
+
mentions: [
|
|
46644
|
+
"extract",
|
|
46645
|
+
"schema",
|
|
46646
|
+
"file_path",
|
|
46647
|
+
"file_url",
|
|
46648
|
+
"document_id"
|
|
46649
|
+
]
|
|
46153
46650
|
},
|
|
46154
46651
|
{
|
|
46155
46652
|
slug: "sdk-documents",
|
|
46156
46653
|
parentSlug: "sdk-resources",
|
|
46157
46654
|
title: "Documents",
|
|
46158
|
-
seoTitle: "
|
|
46159
|
-
description: "List,
|
|
46655
|
+
seoTitle: "Documents Resource \u2014 Talonic Node SDK API Reference",
|
|
46656
|
+
description: "List, retrieve, filter, re-extract, and delete workspace documents with talonic.documents, including OCR markdown retrieval and cursor-based pagination.",
|
|
46160
46657
|
content: [
|
|
46161
|
-
{
|
|
46658
|
+
{
|
|
46659
|
+
type: "paragraph",
|
|
46660
|
+
text: "The **documents** resource lets you manage uploaded files in your workspace. Every call to **extract()** creates a document automatically, but you can also list, inspect, re-extract, filter, and delete documents independently."
|
|
46661
|
+
},
|
|
46662
|
+
{
|
|
46663
|
+
type: "code",
|
|
46664
|
+
language: "typescript",
|
|
46665
|
+
title: "Core document operations",
|
|
46666
|
+
code: "// List documents with cursor-based pagination\nconst docs = await talonic.documents.list({ limit: 50 })\nconsole.log(docs.data.map(d => d.filename))\nconsole.log(docs.pagination) // { next_cursor: '...', has_more: true }\n\n// Get a single document with full metadata\nconst doc = await talonic.documents.get('doc_abc123')\nconsole.log(doc.filename) // 'invoice.pdf'\nconsole.log(doc.status) // 'completed'\nconsole.log(doc.pages) // 3\nconsole.log(doc.triage) // { sensitivity: 'internal', pii_detected: true, ... }\n\n// Get OCR markdown\nconst md = await talonic.documents.getMarkdown('doc_abc123')\nconsole.log(md.markdown) // '# Invoice\\n\\nVendor: Acme Corp...'"
|
|
46667
|
+
},
|
|
46668
|
+
{
|
|
46669
|
+
type: "paragraph",
|
|
46670
|
+
text: "The `list()` method accepts `ListDocumentsParams` with filtering by `source_id`, `status` (`'pending'`, `'processing'`, `'completed'`, `'error'`), date range (`after`, `before` as ISO 8601 strings), and full-text `search` across filenames and extracted content. Pagination uses cursor-based navigation: pass `limit` for page size and `cursor` from a previous response's `pagination.next_cursor` to fetch the next page. The legacy `page` and `per_page` parameters are accepted as aliases but cursor-based is the canonical form. Results include a `pagination` object with `next_cursor` and `has_more`."
|
|
46671
|
+
},
|
|
46672
|
+
{
|
|
46673
|
+
type: "paragraph",
|
|
46674
|
+
text: "Use **getMarkdown()** to retrieve the raw OCR output for a document. This is useful for debugging extraction quality or building custom post-processing pipelines on top of the parsed text."
|
|
46675
|
+
},
|
|
46676
|
+
{
|
|
46677
|
+
type: "code",
|
|
46678
|
+
language: "typescript",
|
|
46679
|
+
title: "Filter documents by extracted field values",
|
|
46680
|
+
code: "// Filter documents using composable conditions on extracted fields\nconst filtered = await talonic.documents.filter({\n conditions: [\n { field: 'vendor.name', operator: 'eq', value: 'Acme Corp' },\n { field: 'total_amount', operator: 'gt', value: 10000 },\n ],\n sort: { field: 'invoice_date', direction: 'desc' },\n limit: 25,\n})\n\nconsole.log(filtered.total) // 47\nconsole.log(filtered.documents) // [{ id: '...', filename: '...', fieldValues: { ... } }, ...]"
|
|
46681
|
+
},
|
|
46682
|
+
{
|
|
46683
|
+
type: "paragraph",
|
|
46684
|
+
text: "The **filter()** method lets you query documents by extracted field values using composable conditions. Each condition specifies a `field` (canonical name like `'vendor.name'`) or `fieldId` (UUID), an `operator` (`eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `between`, `contains`, `is_empty`, `is_not_empty`), and a `value`. The `between` operator also accepts `valueTo` for range queries. Results include `fieldValues` with the matched field data for each document hit. You can optionally scope results to a specific source connection with `source_connection_id`."
|
|
46685
|
+
},
|
|
46686
|
+
{
|
|
46687
|
+
type: "code",
|
|
46688
|
+
language: "typescript",
|
|
46689
|
+
title: "Re-extract and delete",
|
|
46690
|
+
code: "// Re-run extraction on an existing document (e.g. after schema update)\nconst reExtracted = await talonic.documents.reExtract('doc_abc123')\nconsole.log(reExtracted.status) // 'processing'\nconsole.log(reExtracted.message) // 'Re-extraction started'\n\n// Delete a document and all associated extractions (irreversible)\nconst deleted = await talonic.documents.delete('doc_abc123')\nconsole.log(deleted.deleted) // true"
|
|
46691
|
+
},
|
|
46692
|
+
{
|
|
46693
|
+
type: "paragraph",
|
|
46694
|
+
text: "The **get()** method returns a `Document` object with full metadata including `triage` classification data when available. The triage block contains `sensitivity` (public, internal, restricted), `department`, `jurisdiction` (ISO country code), `pii_detected`, `pii_categories`, `regulated_data`, and `confidentiality_marking`. The `processing_log` array shows each pipeline step with status, duration, and detail. These fields are populated progressively as the document moves through the processing pipeline."
|
|
46695
|
+
},
|
|
46696
|
+
{
|
|
46697
|
+
type: "callout",
|
|
46698
|
+
text: "Deleting a document also removes all associated extractions. If you need to preserve extraction history, fetch the data with **extractions.getData()** before deleting."
|
|
46699
|
+
}
|
|
46162
46700
|
],
|
|
46163
46701
|
related: [
|
|
46164
|
-
{
|
|
46165
|
-
|
|
46702
|
+
{
|
|
46703
|
+
label: "Extract",
|
|
46704
|
+
slug: "sdk-extract"
|
|
46705
|
+
},
|
|
46706
|
+
{
|
|
46707
|
+
label: "Extractions",
|
|
46708
|
+
slug: "sdk-extractions"
|
|
46709
|
+
}
|
|
46166
46710
|
],
|
|
46167
|
-
faq: [
|
|
46168
|
-
|
|
46711
|
+
faq: [
|
|
46712
|
+
{
|
|
46713
|
+
question: "How do I list documents with the Talonic SDK?",
|
|
46714
|
+
answer: "Call talonic.documents.list() with optional parameters like limit, cursor, status, source_id, after, before, and search. Results are paginated using cursor-based navigation."
|
|
46715
|
+
},
|
|
46716
|
+
{
|
|
46717
|
+
question: "What does getMarkdown() return?",
|
|
46718
|
+
answer: "It returns the raw OCR markdown output for a document, which is the text the extraction engine uses as input. Useful for debugging or building custom processing pipelines."
|
|
46719
|
+
},
|
|
46720
|
+
{
|
|
46721
|
+
question: "Does deleting a document remove its extractions?",
|
|
46722
|
+
answer: "Yes. Deleting a document removes all associated extraction results. Retrieve any data you need before calling delete()."
|
|
46723
|
+
},
|
|
46724
|
+
{
|
|
46725
|
+
question: "How do I filter documents by extracted field values?",
|
|
46726
|
+
answer: "Use talonic.documents.filter() with an array of conditions. Each condition specifies a field name or fieldId, an operator (eq, gt, contains, between, etc.), and a value. You can combine multiple conditions, add sort order, and paginate with page and limit parameters."
|
|
46727
|
+
},
|
|
46728
|
+
{
|
|
46729
|
+
question: "What is the triage field on documents?",
|
|
46730
|
+
answer: "The triage block contains automatic classification output including sensitivity tier, department, jurisdiction, PII detection, regulated data flags, and confidentiality markings. It is populated by the Talonic classification pipeline after document ingestion and may be null for newly uploaded documents."
|
|
46731
|
+
}
|
|
46732
|
+
],
|
|
46733
|
+
mentions: [
|
|
46734
|
+
"documents",
|
|
46735
|
+
"list",
|
|
46736
|
+
"get",
|
|
46737
|
+
"delete",
|
|
46738
|
+
"markdown"
|
|
46739
|
+
]
|
|
46169
46740
|
},
|
|
46170
46741
|
{
|
|
46171
46742
|
slug: "sdk-extractions",
|
|
46172
46743
|
parentSlug: "sdk-resources",
|
|
46173
46744
|
title: "Extractions",
|
|
46174
|
-
seoTitle: "
|
|
46175
|
-
description: "Query extraction results,
|
|
46745
|
+
seoTitle: "Extractions Resource \u2014 Talonic Node SDK API Reference",
|
|
46746
|
+
description: "Query extraction results with talonic.extractions: list runs, fetch structured data as JSON or CSV, and patch field values with audited human corrections.",
|
|
46176
46747
|
content: [
|
|
46177
|
-
{
|
|
46748
|
+
{
|
|
46749
|
+
type: "paragraph",
|
|
46750
|
+
text: "The **extractions** resource gives you access to the structured data produced by each extraction run. Every **extract()** call creates an extraction record that you can query, export, and correct after the fact."
|
|
46751
|
+
},
|
|
46752
|
+
{
|
|
46753
|
+
type: "code",
|
|
46754
|
+
language: "typescript",
|
|
46755
|
+
title: "List and retrieve extractions",
|
|
46756
|
+
code: "// List extractions for a specific document\nconst extractions = await talonic.extractions.list({\n document_id: 'doc_abc123',\n status: 'complete',\n limit: 10,\n})\n\nfor (const ext of extractions.data) {\n console.log(`${ext.id}: confidence ${ext.confidence_overall}, created ${ext.created_at}`)\n}\n\n// Get full extraction with per-field confidence\nconst extraction = await talonic.extractions.get('ext_xyz789')\nconsole.log(extraction.data) // { vendor_name: 'Acme', total: 1500, ... }\nconsole.log(extraction.confidence?.overall) // 0.94\nconsole.log(extraction.confidence?.fields) // { vendor_name: 0.99, total: 0.91, ... }\nconsole.log(extraction.metadata?.processing_time_ms) // 1820"
|
|
46757
|
+
},
|
|
46758
|
+
{
|
|
46759
|
+
type: "paragraph",
|
|
46760
|
+
text: "The `list()` method accepts `ListExtractionsParams` with optional filters for `document_id`, `schema_id`, and `status` (`'complete'`, `'processing'`, `'failed'`). Pagination uses cursor-based navigation with `cursor` and `limit` parameters. The legacy `page` and `per_page` parameters are accepted for compatibility. Each extraction in the list response includes a compact `confidence_overall` number, while the individual `get()` response includes the full `confidence` object with per-field scores."
|
|
46761
|
+
},
|
|
46762
|
+
{
|
|
46763
|
+
type: "paragraph",
|
|
46764
|
+
text: "Use **getData()** to retrieve extraction results as JSON (default) or CSV. The JSON format returns typed objects matching your schema definition, while CSV is convenient for spreadsheet workflows or bulk data exports. The method uses TypeScript overloads: calling with `{ format: 'json' }` or no options returns `WithRateLimit<Record<string, unknown>>`, while `{ format: 'csv' }` returns a plain `string`."
|
|
46765
|
+
},
|
|
46766
|
+
{
|
|
46767
|
+
type: "code",
|
|
46768
|
+
language: "typescript",
|
|
46769
|
+
title: "Export extraction data",
|
|
46770
|
+
code: `// Get structured data as JSON (default)
|
|
46771
|
+
const jsonData = await talonic.extractions.getData('ext_xyz789')
|
|
46772
|
+
console.log(jsonData) // { vendor_name: 'Acme', line_items: [...], total: 1500 }
|
|
46773
|
+
|
|
46774
|
+
// Get structured data as CSV for spreadsheet workflows
|
|
46775
|
+
const csvData = await talonic.extractions.getData('ext_xyz789', { format: 'csv' })
|
|
46776
|
+
console.log(csvData)
|
|
46777
|
+
// "vendor_name,total,due_date\\nAcme Corp,1500,2025-03-15"
|
|
46778
|
+
|
|
46779
|
+
// Write CSV to file
|
|
46780
|
+
import { writeFile } from 'node:fs/promises'
|
|
46781
|
+
await writeFile('./export.csv', csvData)`
|
|
46782
|
+
},
|
|
46783
|
+
{
|
|
46784
|
+
type: "paragraph",
|
|
46785
|
+
text: "The **patch()** method submits field-level corrections back to the extraction. Corrections improve future extraction accuracy for similar documents by feeding the correction loop, so submitting them is worth the effort even if you fix the value downstream. Each correction specifies the `field` name, the corrected `value`, and an optional `reason` string explaining the change. The `propagate` parameter controls scope: `'this_document_only'` (default) applies the correction to this extraction only, while `'all_similar'` propagates it to similar extractions across your workspace."
|
|
46786
|
+
},
|
|
46787
|
+
{
|
|
46788
|
+
type: "code",
|
|
46789
|
+
language: "typescript",
|
|
46790
|
+
title: "Submit corrections",
|
|
46791
|
+
code: "// Submit field-level corrections to improve future accuracy\nawait talonic.extractions.patch('ext_xyz789', {\n corrections: [\n {\n field: 'vendor_name',\n value: 'Acme Corporation',\n reason: 'Full legal name required',\n },\n {\n field: 'total_amount',\n value: 14250.00,\n reason: 'OCR misread decimal separator',\n },\n ],\n propagate: 'all_similar', // apply to similar documents too\n})"
|
|
46792
|
+
},
|
|
46793
|
+
{
|
|
46794
|
+
type: "paragraph",
|
|
46795
|
+
text: "The `Extraction` interface includes metadata about the extraction run. The `metadata` block provides `pages` (number of pages processed), `language` (detected language code), `document_type` (detected document category), and `processing_time_ms`. The `links` object contains URLs for the extraction resource, related endpoints, and the dashboard view. Use these links to build navigation between the SDK and the Talonic web dashboard."
|
|
46796
|
+
},
|
|
46797
|
+
{
|
|
46798
|
+
type: "callout",
|
|
46799
|
+
text: "A single document can have multiple extractions if it was re-extracted with different schemas. Use **list({ document_id })** to see all extraction runs for a given document."
|
|
46800
|
+
}
|
|
46801
|
+
],
|
|
46802
|
+
related: [
|
|
46803
|
+
{
|
|
46804
|
+
label: "Extract",
|
|
46805
|
+
slug: "sdk-extract"
|
|
46806
|
+
},
|
|
46807
|
+
{
|
|
46808
|
+
label: "Documents",
|
|
46809
|
+
slug: "sdk-documents"
|
|
46810
|
+
}
|
|
46811
|
+
],
|
|
46812
|
+
faq: [
|
|
46813
|
+
{
|
|
46814
|
+
question: "How do I get extraction data as CSV?",
|
|
46815
|
+
answer: 'Call talonic.extractions.getData(id, { format: "csv" }) to receive the structured data as a CSV string. The return type is a plain string rather than a WithRateLimit wrapper.'
|
|
46816
|
+
},
|
|
46817
|
+
{
|
|
46818
|
+
question: "What does the patch() method do?",
|
|
46819
|
+
answer: "It submits field-level corrections to an extraction result. Each correction specifies a field name, corrected value, and optional reason. Corrections are fed back into the extraction engine to improve accuracy for similar documents in future runs. Use the propagate parameter to control whether corrections apply to this document only or all similar documents."
|
|
46820
|
+
},
|
|
46821
|
+
{
|
|
46822
|
+
question: "Can a document have multiple extractions?",
|
|
46823
|
+
answer: "Yes. Re-extracting a document with a different schema creates a new extraction record. Use extractions.list({ document_id }) to retrieve all runs for one document."
|
|
46824
|
+
},
|
|
46825
|
+
{
|
|
46826
|
+
question: "What is the difference between get() and getData()?",
|
|
46827
|
+
answer: "The get() method returns the full Extraction object including metadata, confidence scores, status, timestamps, and links alongside the extracted data. The getData() method returns just the extracted field values as a plain JSON object or CSV string, without the surrounding metadata. Use get() for inspection and debugging, getData() for data export and downstream processing."
|
|
46828
|
+
},
|
|
46829
|
+
{
|
|
46830
|
+
question: "How do I filter extractions by status?",
|
|
46831
|
+
answer: "Pass the status parameter to extractions.list() with one of 'complete', 'processing', or 'failed'. You can combine this with document_id and schema_id filters to narrow results further. Pagination is cursor-based using cursor and limit parameters."
|
|
46832
|
+
}
|
|
46833
|
+
],
|
|
46834
|
+
mentions: [
|
|
46835
|
+
"extractions",
|
|
46836
|
+
"getData",
|
|
46837
|
+
"corrections",
|
|
46838
|
+
"CSV",
|
|
46839
|
+
"JSON"
|
|
46840
|
+
]
|
|
46841
|
+
},
|
|
46842
|
+
{
|
|
46843
|
+
slug: "sdk-schemas",
|
|
46844
|
+
parentSlug: "sdk-resources",
|
|
46845
|
+
title: "Schemas",
|
|
46846
|
+
seoTitle: "Schemas Resource \u2014 Talonic Node.js SDK API Reference",
|
|
46847
|
+
description: "Create, list, update, and delete reusable JSON Schema extraction definitions with talonic.schemas for consistent structured output across all documents.",
|
|
46848
|
+
content: [
|
|
46849
|
+
{
|
|
46850
|
+
type: "paragraph",
|
|
46851
|
+
text: "The **schemas** resource manages reusable extraction definitions. Instead of passing an inline `schema` on every **extract()** call, create a named schema once and reference it by `schema_id` across all your extractions."
|
|
46852
|
+
},
|
|
46853
|
+
{
|
|
46854
|
+
type: "code",
|
|
46855
|
+
language: "typescript",
|
|
46856
|
+
title: "Create and use a saved schema",
|
|
46857
|
+
code: "// Create a reusable schema for invoice extraction\nconst schema = await talonic.schemas.create({\n name: 'Invoice Schema v2',\n description: 'Standard invoice fields for AP automation',\n definition: {\n type: 'object',\n properties: {\n vendor_name: { type: 'string', description: 'Legal entity name of the vendor' },\n invoice_number: { type: 'string' },\n invoice_date: { type: 'string', format: 'date' },\n due_date: { type: 'string', format: 'date' },\n total_amount: { type: 'number' },\n currency: { type: 'string' },\n line_items: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n description: { type: 'string' },\n quantity: { type: 'number' },\n unit_price: { type: 'number' },\n },\n },\n },\n },\n },\n})\n\nconsole.log(schema.id) // 'sch_abc123'\nconsole.log(schema.short_id) // 'SCH-3A4D79D2'\nconsole.log(schema.version) // 1\n\n// Use the saved schema for extraction\nconst result = await talonic.extract({\n file_path: './invoice.pdf',\n schema_id: schema.id,\n})"
|
|
46858
|
+
},
|
|
46859
|
+
{
|
|
46860
|
+
type: "paragraph",
|
|
46861
|
+
text: "The `create()` method accepts a `CreateSchemaParams` object with `name` (required), `definition` (required, JSON Schema object), and an optional `description`. The returned `Schema` object includes `id` (canonical UUID), `short_id` (human-readable identifier like `'SCH-3A4D79D2'` visible in the dashboard), `version` (starts at 1, bumps on each update), `field_count`, `extraction_count`, and `links` with URLs for the schema, its extractions, and the dashboard view. Both `id` and `short_id` are accepted as lookup keys on `get()`, `update()`, and `delete()`."
|
|
46862
|
+
},
|
|
46863
|
+
{
|
|
46864
|
+
type: "paragraph",
|
|
46865
|
+
text: 'Schema definitions follow JSON Schema format with `type: "object"` and `properties`. Each property specifies a field name and type that the extraction engine will resolve. Updating a schema does not retroactively change existing extractions, but all future **extract()** calls using that `schema_id` will pick up the new definition. The `version` field is bumped automatically on each update so you can track which version a given extraction used.'
|
|
46866
|
+
},
|
|
46867
|
+
{
|
|
46868
|
+
type: "code",
|
|
46869
|
+
language: "typescript",
|
|
46870
|
+
title: "List, update, and delete schemas",
|
|
46871
|
+
code: "// List all schemas in the workspace\nconst schemas = await talonic.schemas.list()\nfor (const s of schemas.data) {\n console.log(`${s.name} (v${s.version}): ${s.field_count} fields, ${s.extraction_count} extractions`)\n}\n\n// Update a schema definition (bumps version, does not change existing extractions)\nconst updated = await talonic.schemas.update('sch_abc123', {\n name: 'Invoice Schema v3',\n definition: {\n type: 'object',\n properties: {\n vendor_name: { type: 'string' },\n invoice_number: { type: 'string' },\n total_amount: { type: 'number' },\n tax_amount: { type: 'number' }, // new field\n payment_terms: { type: 'string' }, // new field\n },\n },\n})\nconsole.log(updated.version) // 2\n\n// Delete a schema (existing extractions are retained)\nconst deleted = await talonic.schemas.delete('sch_abc123')\nconsole.log(deleted.deleted) // true"
|
|
46872
|
+
},
|
|
46873
|
+
{
|
|
46874
|
+
type: "paragraph",
|
|
46875
|
+
text: "Saved schemas are workspace-scoped, so every team member with API access can reference the same `schema_id`. This makes schemas the right tool for standardising extraction output across a pipeline or team. The `update()` method uses HTTP PUT and replaces the entire schema definition. Pass all fields you want to keep, not just the changes. The `delete()` method removes the schema but retains all existing extractions that used it, so historical data is preserved."
|
|
46876
|
+
},
|
|
46877
|
+
{
|
|
46878
|
+
type: "code",
|
|
46879
|
+
language: "typescript",
|
|
46880
|
+
title: "Retrieve a schema by ID",
|
|
46881
|
+
code: "// Get a schema by canonical UUID or short_id\nconst schema = await talonic.schemas.get('sch_abc123')\n// or: await talonic.schemas.get('SCH-3A4D79D2')\n\nconsole.log(schema.name) // 'Invoice Schema v2'\nconsole.log(schema.definition) // { type: 'object', properties: { ... } }\nconsole.log(schema.created_at) // '2025-06-01T10:30:00.000Z'\nconsole.log(schema.updated_at) // '2025-06-15T14:22:00.000Z'\nconsole.log(schema.links) // { self: '...', extractions: '...', dashboard: '...' }"
|
|
46882
|
+
},
|
|
46883
|
+
{
|
|
46884
|
+
type: "callout",
|
|
46885
|
+
variant: "warning",
|
|
46886
|
+
text: 'Use full JSON Schema format (`type: "object"` with `properties`) rather than the flat key-type shorthand. The server-side normaliser for the shorthand format is not fully supported yet.'
|
|
46887
|
+
}
|
|
46178
46888
|
],
|
|
46179
46889
|
related: [
|
|
46180
|
-
{
|
|
46181
|
-
|
|
46182
|
-
|
|
46183
|
-
|
|
46184
|
-
|
|
46185
|
-
|
|
46186
|
-
|
|
46187
|
-
|
|
46188
|
-
parentSlug: "sdk-resources",
|
|
46189
|
-
title: "Schemas",
|
|
46190
|
-
seoTitle: "SDK Schemas Resource \u2014 Talonic Docs",
|
|
46191
|
-
description: "Create, list, get, update, and delete reusable extraction schemas via the Talonic Node SDK.",
|
|
46192
|
-
content: [
|
|
46193
|
-
{ type: "code", language: "typescript", title: "Schemas API", code: "// List all schemas\nawait talonic.schemas.list()\n\n// Get a schema\nawait talonic.schemas.get(id)\n\n// Create a new schema\nawait talonic.schemas.create({ name, definition })\n\n// Update a schema\nawait talonic.schemas.update(id, { ... })\n\n// Delete a schema\nawait talonic.schemas.delete(id)" }
|
|
46890
|
+
{
|
|
46891
|
+
label: "Extract",
|
|
46892
|
+
slug: "sdk-extract"
|
|
46893
|
+
},
|
|
46894
|
+
{
|
|
46895
|
+
label: "Jobs",
|
|
46896
|
+
slug: "sdk-jobs"
|
|
46897
|
+
}
|
|
46194
46898
|
],
|
|
46195
|
-
|
|
46196
|
-
{
|
|
46197
|
-
|
|
46899
|
+
faq: [
|
|
46900
|
+
{
|
|
46901
|
+
question: "How do I create a reusable schema?",
|
|
46902
|
+
answer: "Call talonic.schemas.create({ name, definition }) with a JSON Schema definition. The returned object includes id and short_id. Use either as schema_id in future extract calls."
|
|
46903
|
+
},
|
|
46904
|
+
{
|
|
46905
|
+
question: "Are schemas shared across team members?",
|
|
46906
|
+
answer: "Yes. Schemas are workspace-scoped. Anyone with API access to the workspace can reference the same schema_id in their extract calls."
|
|
46907
|
+
},
|
|
46908
|
+
{
|
|
46909
|
+
question: "Does updating a schema change existing extractions?",
|
|
46910
|
+
answer: "No. Updating a schema bumps the version number and only affects future extract calls that reference that schema_id. Existing extraction results remain unchanged and retain their original schema version."
|
|
46911
|
+
},
|
|
46912
|
+
{
|
|
46913
|
+
question: "What happens to extractions when I delete a schema?",
|
|
46914
|
+
answer: "Existing extractions are retained when you delete a schema. The extraction data remains accessible via the extractions resource. Only the schema definition itself is removed, so you can no longer use that schema_id for new extractions."
|
|
46915
|
+
},
|
|
46916
|
+
{
|
|
46917
|
+
question: "Can I look up a schema by its short_id?",
|
|
46918
|
+
answer: "Yes. Both the canonical UUID (id) and the human-readable short_id (e.g. 'SCH-3A4D79D2') are accepted as lookup keys on get(), update(), and delete(). The short_id is displayed in the Talonic dashboard for easy reference."
|
|
46919
|
+
}
|
|
46198
46920
|
],
|
|
46199
|
-
|
|
46200
|
-
|
|
46921
|
+
mentions: [
|
|
46922
|
+
"schemas",
|
|
46923
|
+
"JSON Schema",
|
|
46924
|
+
"create",
|
|
46925
|
+
"update"
|
|
46926
|
+
]
|
|
46201
46927
|
},
|
|
46202
46928
|
{
|
|
46203
46929
|
slug: "sdk-jobs",
|
|
46204
46930
|
parentSlug: "sdk-resources",
|
|
46205
46931
|
title: "Jobs",
|
|
46206
|
-
seoTitle: "
|
|
46207
|
-
description: "
|
|
46932
|
+
seoTitle: "Batch Jobs Resource \u2014 Talonic Node SDK API Reference",
|
|
46933
|
+
description: "Run asynchronous batch extraction with talonic.jobs: create jobs from document sets, poll live progress, retrieve structured results, and cancel safely.",
|
|
46208
46934
|
content: [
|
|
46209
|
-
{
|
|
46935
|
+
{
|
|
46936
|
+
type: "paragraph",
|
|
46937
|
+
text: "The **jobs** resource handles asynchronous batch extraction across multiple documents. Create a job with a `schema_id` and an array of `document_ids`, then poll for completion or fetch results when the job finishes."
|
|
46938
|
+
},
|
|
46939
|
+
{
|
|
46940
|
+
type: "code",
|
|
46941
|
+
language: "typescript",
|
|
46942
|
+
title: "Create and monitor a batch job",
|
|
46943
|
+
code: "// Create a batch extraction job\nconst job = await talonic.jobs.create({\n schema_id: 'sch_abc123',\n document_ids: ['doc_001', 'doc_002', 'doc_003', 'doc_004', 'doc_005'],\n name: 'Q4 Invoice Batch',\n})\n\nconsole.log(job.id) // 'job_xyz789'\nconsole.log(job.status) // 'queued'\n\n// Poll for completion\nlet current = await talonic.jobs.get(job.id)\nwhile (current.status === 'queued' || current.status === 'processing') {\n console.log(`Progress: ${current.completed_documents}/${current.total_documents} (${current.current_phase})`)\n await new Promise(r => setTimeout(r, 5000))\n current = await talonic.jobs.get(job.id)\n}\n\nconsole.log(`Job ${current.status}: ${current.completed_documents} completed, ${current.failed_documents} failed`)"
|
|
46944
|
+
},
|
|
46945
|
+
{
|
|
46946
|
+
type: "paragraph",
|
|
46947
|
+
text: "The `create()` method accepts `CreateJobParams` with `schema_id` (required), optional `document_ids` (array of document UUIDs to process), and optional `name` (human-readable label). When `document_ids` is omitted, the job processes all unprocessed documents in the workspace. The returned `Job` object includes `id`, `status`, `progress`, `total_documents`, `completed_documents`, `failed_documents`, `current_phase`, `estimated_completion`, and `links` with URLs for the job and its results."
|
|
46948
|
+
},
|
|
46949
|
+
{
|
|
46950
|
+
type: "paragraph",
|
|
46951
|
+
text: "Jobs run server-side and process documents in parallel. Use **get()** to poll the job status (`'queued'`, `'processing'`, `'completed'`, `'failed'`, `'cancelled'`) and **getResults()** to retrieve the extraction output once complete. For long-running batches, poll on a reasonable interval such as every 5 seconds. The `grid_stats` block on the job object provides `total_cells`, `filled`, `empty`, and `fill_rate` for monitoring extraction quality across the batch."
|
|
46952
|
+
},
|
|
46953
|
+
{
|
|
46954
|
+
type: "code",
|
|
46955
|
+
language: "typescript",
|
|
46956
|
+
title: "Retrieve batch results",
|
|
46957
|
+
code: "// Get structured results from a completed job\nconst results = await talonic.jobs.getResults('job_xyz789')\n\nfor (const row of results.data) {\n console.log(`${row.document_filename}: ${JSON.stringify(row.values)}`)\n}\n// invoice_001.pdf: { vendor_name: 'Acme', total: 1500, ... }\n// invoice_002.pdf: { vendor_name: 'Globex', total: 3200, ... }\n\n// Export to CSV or send to your database\nconst rows = results.data.map(r => ({\n filename: r.document_filename,\n document_id: r.document_id,\n ...r.values,\n}))"
|
|
46958
|
+
},
|
|
46959
|
+
{
|
|
46960
|
+
type: "paragraph",
|
|
46961
|
+
text: "Use **cancel()** to abort a job that is still in progress. Cancelled jobs stop processing remaining documents but any extractions already completed are preserved and accessible via **getResults()**. The `cancelled_at` timestamp is set on the job object when cancellation takes effect."
|
|
46962
|
+
},
|
|
46963
|
+
{
|
|
46964
|
+
type: "code",
|
|
46965
|
+
language: "typescript",
|
|
46966
|
+
title: "List and cancel jobs",
|
|
46967
|
+
code: "// List jobs filtered by status\nconst runningJobs = await talonic.jobs.list({ status: 'processing', limit: 10 })\nfor (const j of runningJobs.data) {\n console.log(`${j.id}: ${j.completed_documents}/${j.total_documents} (est. ${j.estimated_completion})`)\n}\n\n// Cancel a job \u2014 partial results are retained\nconst cancelled = await talonic.jobs.cancel('job_xyz789')\nconsole.log(cancelled.status) // 'cancelled'\nconsole.log(cancelled.cancelled_at) // '2025-06-15T14:30:00.000Z'\n\n// Retrieve whatever completed before cancellation\nconst partial = await talonic.jobs.getResults('job_xyz789')\nconsole.log(`Retrieved ${partial.data.length} results before cancellation`)"
|
|
46968
|
+
},
|
|
46969
|
+
{
|
|
46970
|
+
type: "paragraph",
|
|
46971
|
+
text: "The `list()` method accepts `ListJobsParams` with optional `status` filter, cursor-based pagination (`cursor` and `limit`), and `order` for sorting. The `JobResults` response contains a `data` array where each entry has `document_id`, `document_filename`, and `values` (the extracted field data). This flat structure makes it straightforward to aggregate results across documents for reporting or database insertion."
|
|
46972
|
+
},
|
|
46973
|
+
{
|
|
46974
|
+
type: "callout",
|
|
46975
|
+
text: "Jobs require a saved `schema_id` rather than an inline schema. Create your schema with **schemas.create()** first, then pass the returned ID to **jobs.create()**."
|
|
46976
|
+
}
|
|
46210
46977
|
],
|
|
46211
46978
|
related: [
|
|
46212
|
-
{
|
|
46213
|
-
|
|
46979
|
+
{
|
|
46980
|
+
label: "Schemas",
|
|
46981
|
+
slug: "sdk-schemas"
|
|
46982
|
+
},
|
|
46983
|
+
{
|
|
46984
|
+
label: "Extract",
|
|
46985
|
+
slug: "sdk-extract"
|
|
46986
|
+
},
|
|
46987
|
+
{
|
|
46988
|
+
label: "Extractions",
|
|
46989
|
+
slug: "sdk-extractions"
|
|
46990
|
+
}
|
|
46214
46991
|
],
|
|
46215
|
-
faq: [
|
|
46216
|
-
|
|
46992
|
+
faq: [
|
|
46993
|
+
{
|
|
46994
|
+
question: "How do I run batch extraction with the Talonic SDK?",
|
|
46995
|
+
answer: "Call talonic.jobs.create({ schema_id, document_ids }) to start an async batch job, then poll with talonic.jobs.get(id) or retrieve results with talonic.jobs.getResults(id). Omit document_ids to process all unprocessed documents in the workspace."
|
|
46996
|
+
},
|
|
46997
|
+
{
|
|
46998
|
+
question: "Can I use an inline schema with jobs?",
|
|
46999
|
+
answer: "No. Jobs require a saved schema_id. Create your schema first with talonic.schemas.create(), then pass the returned ID to talonic.jobs.create()."
|
|
47000
|
+
},
|
|
47001
|
+
{
|
|
47002
|
+
question: "What happens to completed extractions if I cancel a job?",
|
|
47003
|
+
answer: "Extractions already completed before cancellation are preserved. You can still retrieve them with talonic.jobs.getResults(id). The job status changes to 'cancelled' and the cancelled_at timestamp is set."
|
|
47004
|
+
},
|
|
47005
|
+
{
|
|
47006
|
+
question: "How do I monitor batch job progress?",
|
|
47007
|
+
answer: "Poll talonic.jobs.get(id) on a regular interval (e.g. every 5 seconds). The Job object includes completed_documents, total_documents, failed_documents, current_phase, progress, estimated_completion, and grid_stats with fill_rate for quality monitoring."
|
|
47008
|
+
},
|
|
47009
|
+
{
|
|
47010
|
+
question: "What job statuses are available for filtering?",
|
|
47011
|
+
answer: "Jobs can be in one of five statuses: 'queued' (waiting to start), 'processing' (actively extracting), 'completed' (all documents processed), 'failed' (terminal error), or 'cancelled' (manually stopped). Use the status parameter on list() to filter."
|
|
47012
|
+
}
|
|
47013
|
+
],
|
|
47014
|
+
mentions: [
|
|
47015
|
+
"jobs",
|
|
47016
|
+
"batch",
|
|
47017
|
+
"async"
|
|
47018
|
+
]
|
|
46217
47019
|
},
|
|
46218
47020
|
{
|
|
46219
47021
|
slug: "sdk-cli-usage",
|
|
46220
47022
|
parentSlug: "sdk-cli",
|
|
46221
47023
|
title: "Usage",
|
|
46222
|
-
seoTitle: "Talonic CLI
|
|
46223
|
-
description: "Use the talonic CLI
|
|
47024
|
+
seoTitle: "Talonic CLI \u2014 Terminal Document Extraction for Node.js",
|
|
47025
|
+
description: "Use the bundled talonic CLI to extract documents, list schemas and documents, and script its JSON output from the terminal with only an API key in env.",
|
|
46224
47026
|
content: [
|
|
46225
|
-
{
|
|
46226
|
-
|
|
46227
|
-
talonic documents
|
|
47027
|
+
{
|
|
47028
|
+
type: "paragraph",
|
|
47029
|
+
text: "The package ships with a `talonic` binary for terminal-based workflows. It focuses on the operations you reach for most often outside of code: running an extraction against a local file, listing your saved schemas, and inspecting the documents in your workspace. Every command is a thin wrapper over the same SDK client, so authentication, retries, and error mapping behave exactly as they do in TypeScript."
|
|
47030
|
+
},
|
|
47031
|
+
{
|
|
47032
|
+
type: "code",
|
|
47033
|
+
language: "bash",
|
|
47034
|
+
title: "Basic usage",
|
|
47035
|
+
code: `# Extract structured data from a file with an inline schema
|
|
46228
47036
|
talonic extract ./invoice.pdf \\
|
|
46229
|
-
--schema='{"vendor_name":"string","total_amount":"number"}'
|
|
46230
|
-
|
|
47037
|
+
--schema='{"type":"object","properties":{"vendor_name":{"type":"string"},"total_amount":{"type":"number"}}}'
|
|
47038
|
+
|
|
47039
|
+
# Extract with a saved schema
|
|
47040
|
+
talonic extract ./contract.pdf --schema-id=sch_abc123
|
|
47041
|
+
|
|
47042
|
+
# List schemas in your workspace
|
|
47043
|
+
talonic schemas list
|
|
47044
|
+
|
|
47045
|
+
# List documents with paging and a status filter
|
|
47046
|
+
talonic documents list --per-page=20 --status=completed
|
|
47047
|
+
|
|
47048
|
+
# Show help and version
|
|
47049
|
+
talonic --help
|
|
47050
|
+
talonic --version`
|
|
47051
|
+
},
|
|
47052
|
+
{
|
|
47053
|
+
type: "paragraph",
|
|
47054
|
+
text: "The CLI reads `TALONIC_API_KEY` from the environment and exits with an error message if it is missing. Set `TALONIC_BASE_URL` to point at a staging environment or local proxy; it maps directly to the SDK's `baseUrl` option. There is intentionally no `--api-key` flag, so keys never end up in your shell history. All successful output is pretty-printed JSON on stdout, making it straightforward to pipe into `jq`, `grep`, or any other tool that accepts JSON input."
|
|
47055
|
+
},
|
|
47056
|
+
{
|
|
47057
|
+
type: "code",
|
|
47058
|
+
language: "bash",
|
|
47059
|
+
title: "Supported commands",
|
|
47060
|
+
code: "# Schemas\ntalonic schemas list # list all saved schemas\ntalonic schemas get sch_abc123 # get one schema by ID\n\n# Documents\ntalonic documents list # list documents\ntalonic documents list --per-page=10 # page size\ntalonic documents list --status=error # filter: pending | processing | completed | error\ntalonic documents get doc_abc123 # get one document by ID\n\n# Extraction\ntalonic extract <file_path> [options]\n# --schema='<json>' inline schema (full JSON Schema recommended)\n# --schema-id=<id> use a saved schema\n# --instructions='<text>' natural-language extraction guidance\n# --include-markdown include OCR markdown in the response\n\n# Environment\n# TALONIC_API_KEY (required) your tlnc_ API key\n# TALONIC_BASE_URL (optional) override the API base URL"
|
|
47061
|
+
},
|
|
47062
|
+
{
|
|
47063
|
+
type: "paragraph",
|
|
47064
|
+
text: "Command output is the full SDK response serialized with two-space indentation, so list commands return an object with `data` and `pagination` keys \u2014 plus the `rateLimit` and `cost` metadata the SDK attaches to every response. Keep that envelope in mind when scripting: document IDs live at `.data[].id`, not at the top level. Extract output mirrors the `ExtractResult` shape, with the structured fields under `.data`."
|
|
47065
|
+
},
|
|
47066
|
+
{
|
|
47067
|
+
type: "code",
|
|
47068
|
+
language: "bash",
|
|
47069
|
+
title: "Scripting with jq",
|
|
47070
|
+
code: "# Extract all document IDs\ntalonic documents list | jq '.data[].id'\n\n# Filenames of completed documents\ntalonic documents list --status=completed | jq '.data[].filename'\n\n# Run an extraction and keep only the structured fields\ntalonic extract ./invoice.pdf --schema-id=sch_abc123 | jq '.data'\n\n# Check the remaining rate-limit budget on any call\ntalonic schemas list | jq '.rateLimit'\n\n# Save a full extraction result to a file\ntalonic extract ./contract.pdf --schema-id=sch_abc123 > result.json"
|
|
47071
|
+
},
|
|
47072
|
+
{
|
|
47073
|
+
type: "paragraph",
|
|
47074
|
+
text: "Because the CLI constructs a standard SDK client, transient failures (429 rate limits, 5xx responses, network errors, timeouts) are retried automatically with exponential backoff before anything is reported. When a command does fail, the error goes to stderr as plain-text lines \u2014 `Error: <message>` followed by indented `code:`, `status:`, and `request-id:` lines when available \u2014 and the process exits with status 1. Stdout stays reserved for clean JSON, so redirects and pipes never mix data with diagnostics."
|
|
47075
|
+
},
|
|
47076
|
+
{
|
|
47077
|
+
type: "paragraph",
|
|
47078
|
+
text: "The CLI is deliberately smaller than the SDK: operations like schema creation, extraction listing, batch jobs, corrections, and credit queries are SDK-only today. For anything beyond extract, schema lookup, and document lookup, write a short script against `@talonic/node` instead \u2014 the Quick Start covers the same flows in a few lines of TypeScript. `talonic --help` always prints the current, authoritative command list for the version you have installed."
|
|
47079
|
+
},
|
|
47080
|
+
{
|
|
47081
|
+
type: "callout",
|
|
47082
|
+
text: "Set `TALONIC_API_KEY` in your shell profile or `.env` file to avoid passing it on every invocation. The CLI does not support an `--api-key` flag, which prevents accidental key exposure in shell history."
|
|
47083
|
+
}
|
|
46231
47084
|
],
|
|
46232
47085
|
related: [
|
|
46233
|
-
{
|
|
46234
|
-
|
|
47086
|
+
{
|
|
47087
|
+
label: "Install",
|
|
47088
|
+
slug: "sdk-installation"
|
|
47089
|
+
},
|
|
47090
|
+
{
|
|
47091
|
+
label: "Extract",
|
|
47092
|
+
slug: "sdk-extract"
|
|
47093
|
+
},
|
|
47094
|
+
{
|
|
47095
|
+
label: "Quick Start",
|
|
47096
|
+
slug: "sdk-quickstart"
|
|
47097
|
+
}
|
|
46235
47098
|
],
|
|
46236
47099
|
faq: [
|
|
46237
|
-
{
|
|
47100
|
+
{
|
|
47101
|
+
question: "Does the Talonic SDK include a CLI?",
|
|
47102
|
+
answer: "Yes. The talonic binary ships with @talonic/node and supports extraction (talonic extract), schema listing and lookup (talonic schemas list/get), and document listing and lookup (talonic documents list/get). Install via npm install @talonic/node and run it with npx talonic, or install globally."
|
|
47103
|
+
},
|
|
47104
|
+
{
|
|
47105
|
+
question: "How do I set the API key for the CLI?",
|
|
47106
|
+
answer: "Export TALONIC_API_KEY in your shell environment; the CLI reads it automatically and exits with an error if it is missing. There is no --api-key flag, which prevents accidental key exposure in shell history. TALONIC_BASE_URL optionally overrides the API base URL."
|
|
47107
|
+
},
|
|
47108
|
+
{
|
|
47109
|
+
question: "Can I pipe CLI output to other tools?",
|
|
47110
|
+
answer: "Yes. Successful output is pretty-printed JSON on stdout, so you can pipe it into jq or any JSON-aware tool. List commands wrap results in a data array (use .data[].id in jq), and errors go to stderr as plain text, so stdout always contains clean parseable JSON."
|
|
47111
|
+
},
|
|
47112
|
+
{
|
|
47113
|
+
question: "Does the CLI retry failed requests?",
|
|
47114
|
+
answer: "Yes. The CLI builds a standard SDK client under the hood, so 429s, 5xx responses, network errors, and timeouts are retried automatically with exponential backoff and jitter before an error is reported. There is no separate retry configuration for the CLI."
|
|
47115
|
+
},
|
|
47116
|
+
{
|
|
47117
|
+
question: "Can I manage jobs, extractions, or credits from the CLI?",
|
|
47118
|
+
answer: "Not yet. The CLI currently covers extract, schemas list/get, and documents list/get. Batch jobs, extraction queries, corrections, schema creation, and credit balance checks are available through the SDK \u2014 a few lines of TypeScript with @talonic/node cover each of those flows."
|
|
47119
|
+
},
|
|
47120
|
+
{
|
|
47121
|
+
question: "What format should the --schema flag use?",
|
|
47122
|
+
answer: 'Pass a JSON string. Full JSON Schema with type "object" and a properties map is recommended, matching the SDK guidance \u2014 the flat key-type shorthand is not yet reliably normalised server-side. Quote the value in single quotes so your shell passes the JSON through unmodified.'
|
|
47123
|
+
}
|
|
46238
47124
|
],
|
|
46239
|
-
mentions: [
|
|
47125
|
+
mentions: [
|
|
47126
|
+
"CLI",
|
|
47127
|
+
"terminal",
|
|
47128
|
+
"talonic binary",
|
|
47129
|
+
"jq"
|
|
47130
|
+
]
|
|
46240
47131
|
},
|
|
46241
47132
|
{
|
|
46242
47133
|
slug: "sdk-error-classes",
|
|
46243
47134
|
parentSlug: "sdk-errors",
|
|
46244
47135
|
title: "Error Classes",
|
|
46245
|
-
seoTitle: "
|
|
46246
|
-
description: "
|
|
46247
|
-
content: [
|
|
46248
|
-
{
|
|
46249
|
-
|
|
46250
|
-
|
|
46251
|
-
|
|
46252
|
-
|
|
46253
|
-
|
|
46254
|
-
|
|
46255
|
-
|
|
46256
|
-
|
|
46257
|
-
|
|
46258
|
-
{
|
|
47136
|
+
seoTitle: "Error Classes \u2014 Talonic Node SDK Typed Error Reference",
|
|
47137
|
+
description: "Every Talonic SDK failure is a typed TalonicError subclass carrying status, code, retryable, and requestId, mapped from HTTP statuses and transport faults.",
|
|
47138
|
+
content: [
|
|
47139
|
+
{
|
|
47140
|
+
type: "paragraph",
|
|
47141
|
+
text: "Every failure is a `TalonicError` subclass with `status`, `code`, `retryable`, and `requestId` properties. The class hierarchy maps HTTP status codes to specific error types so you can handle each failure category independently."
|
|
47142
|
+
},
|
|
47143
|
+
{
|
|
47144
|
+
type: "code",
|
|
47145
|
+
language: "typescript",
|
|
47146
|
+
title: "Available error classes",
|
|
47147
|
+
code: "import {\n TalonicError, // base class \u2014 catches all SDK errors\n TalonicAuthError, // 401, 403 \u2014 invalid key or insufficient permissions\n TalonicNotFoundError, // 404 \u2014 resource does not exist\n TalonicValidationError, // 400, 409, 413, 422 \u2014 bad input, conflict, file too large\n TalonicRateLimitError, // 429 \u2014 rate limited (after retries exhausted)\n TalonicServerError, // 500, 502, 503, 504 \u2014 server error (after retries exhausted)\n TalonicNetworkError, // DNS / TCP failures \u2014 status: 0, code: 'network_error'\n TalonicTimeoutError, // request exceeded configured timeout \u2014 status: 0, code: 'timeout'\n} from '@talonic/node'"
|
|
47148
|
+
},
|
|
47149
|
+
{
|
|
47150
|
+
type: "paragraph",
|
|
47151
|
+
text: "Each error class maps to a specific failure category. **TalonicAuthError** covers authentication and permission failures (401, 403). **TalonicValidationError** covers request rejections like bad input, conflicts, oversized files, or unprocessable entities (400, 409, 413, 422). **TalonicRateLimitError** and **TalonicServerError** are only thrown after all retries are exhausted."
|
|
47152
|
+
},
|
|
47153
|
+
{
|
|
47154
|
+
type: "code",
|
|
47155
|
+
language: "typescript",
|
|
47156
|
+
title: "Error class properties",
|
|
47157
|
+
code: "// Every TalonicError subclass carries these properties:\ntry {\n await talonic.extract({ file_path: './doc.pdf', schema_id: 'sch_invalid' })\n} catch (err) {\n if (err instanceof TalonicError) {\n err.code // 'invalid_schema' \u2014 machine-readable error code\n err.status // 422 \u2014 HTTP status (0 for network/timeout)\n err.message // 'Schema sch_invalid not found' \u2014 human-readable\n err.retryable // false \u2014 was this error retried?\n err.requestId // 'req_abc123' \u2014 server trace ID (undefined for transport errors)\n err.name // 'TalonicValidationError' \u2014 class name\n }\n}"
|
|
47158
|
+
},
|
|
47159
|
+
{
|
|
47160
|
+
type: "paragraph",
|
|
47161
|
+
text: '**TalonicNetworkError** and **TalonicTimeoutError** represent transport-level failures that never reached the server. Both carry `status: 0` and are retried automatically. The `code` property is set to `"network_error"` or `"timeout"` respectively, and `retryable` is always `true`. `TalonicNetworkError` preserves the original error as `cause` for debugging DNS failures, TCP resets, and unreachable hosts. `TalonicTimeoutError` includes a `timeoutMs` property with the configured timeout value that was exceeded.'
|
|
47162
|
+
},
|
|
47163
|
+
{
|
|
47164
|
+
type: "code",
|
|
47165
|
+
language: "typescript",
|
|
47166
|
+
title: "Transport-level error details",
|
|
47167
|
+
code: "import { TalonicNetworkError, TalonicTimeoutError, TalonicRateLimitError } from '@talonic/node'\n\ntry {\n await talonic.extract({ file_path: './doc.pdf', schema_id: 'sch_abc123' })\n} catch (err) {\n if (err instanceof TalonicTimeoutError) {\n console.error(`Request timed out after ${err.timeoutMs}ms`)\n // err.status === 0, err.code === 'timeout', err.retryable === true\n }\n\n if (err instanceof TalonicNetworkError) {\n console.error(`Network failure: ${err.message}`)\n console.error(`Original error: ${err.cause}`) // underlying DNS/TCP error\n // err.status === 0, err.code === 'network_error', err.retryable === true\n }\n\n if (err instanceof TalonicRateLimitError) {\n console.error(`Rate limited. Limit: ${err.rateLimit.limit}, remaining: ${err.rateLimit.remaining}`)\n console.error(`Resets at: ${err.rateLimit.resetAt.toISOString()}`)\n // err.rateLimit provides { limit, remaining, resetAt } from response headers\n }\n}"
|
|
47168
|
+
},
|
|
47169
|
+
{
|
|
47170
|
+
type: "paragraph",
|
|
47171
|
+
text: "All error classes extend the base `TalonicError`, so a single `catch` with `instanceof TalonicError` captures every SDK failure. Use more specific subclasses when you need to branch on failure mode, such as showing a different message for auth errors versus validation errors. The `TalonicRateLimitError` is unique in carrying a `rateLimit` property with `limit`, `remaining`, and `resetAt` (Date) from the response headers, useful for scheduling manual retries after the SDK's own retries are exhausted."
|
|
47172
|
+
},
|
|
47173
|
+
{
|
|
47174
|
+
type: "paragraph",
|
|
47175
|
+
text: "The SDK also throws client-side `TalonicError` instances (not subclasses) for parameter validation failures before any network request is made. These carry `status: 0`, `retryable: false`, and codes like `missing_file_source`, `multiple_file_sources`, `multiple_schemas`, or `missing_field_reference`. They indicate programming errors in how the SDK is called rather than server-side failures."
|
|
47176
|
+
},
|
|
47177
|
+
{
|
|
47178
|
+
type: "callout",
|
|
47179
|
+
text: "Every error includes a `requestId` property (when available) that maps to the server-side request log. Include it in support tickets for fast debugging."
|
|
47180
|
+
}
|
|
46259
47181
|
],
|
|
46260
47182
|
related: [
|
|
46261
|
-
{
|
|
46262
|
-
|
|
47183
|
+
{
|
|
47184
|
+
label: "Retries & Backoff",
|
|
47185
|
+
slug: "sdk-retries"
|
|
47186
|
+
},
|
|
47187
|
+
{
|
|
47188
|
+
label: "Configuration",
|
|
47189
|
+
slug: "sdk-configuration"
|
|
47190
|
+
}
|
|
46263
47191
|
],
|
|
46264
47192
|
faq: [
|
|
46265
|
-
{
|
|
47193
|
+
{
|
|
47194
|
+
question: "What error types does the Talonic SDK throw?",
|
|
47195
|
+
answer: "The SDK throws typed subclasses of TalonicError: TalonicAuthError (401/403), TalonicNotFoundError (404), TalonicValidationError (400/409/413/422), TalonicRateLimitError (429), TalonicServerError (5xx), TalonicNetworkError, and TalonicTimeoutError. Client-side validation errors use the base TalonicError class."
|
|
47196
|
+
},
|
|
47197
|
+
{
|
|
47198
|
+
question: "What is the requestId property on errors?",
|
|
47199
|
+
answer: "It is a server-assigned identifier for the request that failed. Include it in support tickets or logs for fast debugging. It may be undefined for transport-level errors (network, timeout) that never reached the server, and for client-side validation errors."
|
|
47200
|
+
},
|
|
47201
|
+
{
|
|
47202
|
+
question: "Are TalonicNetworkError and TalonicTimeoutError retried automatically?",
|
|
47203
|
+
answer: "Yes. Both are marked retryable: true and the SDK retries them up to maxRetries times with exponential backoff. They are only thrown after all retry attempts are exhausted."
|
|
47204
|
+
},
|
|
47205
|
+
{
|
|
47206
|
+
question: "What client-side validation errors does the SDK throw?",
|
|
47207
|
+
answer: "The SDK throws TalonicError (base class) with status 0 and retryable false for parameter validation failures: missing_file_source (no file provided to extract), multiple_file_sources (more than one file source), multiple_schemas (both schema and schema_id provided), and missing_field_reference (filter condition without field or fieldId)."
|
|
47208
|
+
},
|
|
47209
|
+
{
|
|
47210
|
+
question: "How does TalonicRateLimitError differ from other error classes?",
|
|
47211
|
+
answer: "TalonicRateLimitError uniquely carries a rateLimit property with limit (max requests per window), remaining (requests left), and resetAt (Date when the window resets). This data comes from the X-RateLimit-* response headers and is useful for scheduling manual retries or implementing backpressure in your application."
|
|
47212
|
+
}
|
|
46266
47213
|
],
|
|
46267
|
-
mentions: [
|
|
47214
|
+
mentions: [
|
|
47215
|
+
"TalonicError",
|
|
47216
|
+
"error handling",
|
|
47217
|
+
"status codes"
|
|
47218
|
+
]
|
|
46268
47219
|
},
|
|
46269
47220
|
{
|
|
46270
47221
|
slug: "sdk-retries",
|
|
46271
47222
|
parentSlug: "sdk-errors",
|
|
46272
47223
|
title: "Retries",
|
|
46273
|
-
seoTitle: "
|
|
46274
|
-
description: "
|
|
47224
|
+
seoTitle: "Retries and Backoff \u2014 Talonic Node SDK Reliability Guide",
|
|
47225
|
+
description: "How the Talonic SDK retries 429s, 5xx responses, network errors, and timeouts with exponential backoff, jitter, and X-RateLimit-Reset-aware wait times.",
|
|
46275
47226
|
content: [
|
|
46276
|
-
{
|
|
46277
|
-
|
|
46278
|
-
|
|
47227
|
+
{
|
|
47228
|
+
type: "paragraph",
|
|
47229
|
+
text: "The SDK retries automatically on `429` (respecting `X-RateLimit-Reset`), `500`, `502`, `503`, `504`, network errors, and timeouts. Backoff is exponential with jitter, capped at 16s."
|
|
47230
|
+
},
|
|
47231
|
+
{
|
|
47232
|
+
type: "paragraph",
|
|
47233
|
+
text: "The API may set `retryable: false` on a specific error; the SDK respects that and does not retry."
|
|
47234
|
+
},
|
|
47235
|
+
{
|
|
47236
|
+
type: "paragraph",
|
|
47237
|
+
text: "The backoff schedule starts at 1 second for the first retry, doubling on each subsequent attempt (1s, 2s, 4s, ...) up to a maximum of 16 seconds. A random jitter of up to 250ms is added to each wait to prevent thundering-herd problems when multiple clients retry simultaneously. The formula is `min(1000 * 2^attempt, 16000) + random(0, 250)` milliseconds."
|
|
47238
|
+
},
|
|
47239
|
+
{
|
|
47240
|
+
type: "code",
|
|
47241
|
+
language: "typescript",
|
|
47242
|
+
title: "Retry behavior in practice",
|
|
47243
|
+
code: "import { Talonic, TalonicServerError, TalonicRateLimitError } from '@talonic/node'\n\n// Default: 3 retries with exponential backoff\n// Attempt 0: immediate request\n// Attempt 1: wait ~1.0-1.25s, then retry\n// Attempt 2: wait ~2.0-2.25s, then retry\n// Attempt 3: wait ~4.0-4.25s, then retry\n// If all fail, throws the last error\n\nconst talonic = new Talonic({\n apiKey: process.env.TALONIC_API_KEY!,\n maxRetries: 3, // default\n})\n\ntry {\n await talonic.extract({ file_path: './doc.pdf', schema_id: 'sch_abc123' })\n} catch (err) {\n if (err instanceof TalonicServerError) {\n // Thrown only after all 3 retries exhausted\n console.error(`Server error after retries: ${err.code} (request ${err.requestId})`)\n }\n if (err instanceof TalonicRateLimitError) {\n // Thrown after retries exhausted; check when the rate limit resets\n console.error(`Rate limited. Resets at: ${err.rateLimit.resetAt}`)\n }\n}"
|
|
47244
|
+
},
|
|
47245
|
+
{
|
|
47246
|
+
type: "paragraph",
|
|
47247
|
+
text: "For `429` rate-limit responses specifically, the SDK reads the `X-RateLimit-Reset` header and waits until the reset timestamp (plus a 100ms buffer) rather than using exponential backoff. If the reset window exceeds 60 seconds, the SDK falls back to standard backoff instead of blocking indefinitely. This means rate-limit retries are usually faster than exponential backoff because the SDK waits exactly the right amount of time rather than guessing."
|
|
47248
|
+
},
|
|
47249
|
+
{
|
|
47250
|
+
type: "code",
|
|
47251
|
+
language: "typescript",
|
|
47252
|
+
title: "Disable retries for development",
|
|
47253
|
+
code: "// In development, disable retries for immediate feedback\nconst talonic = new Talonic({\n apiKey: process.env.TALONIC_API_KEY!,\n maxRetries: 0, // no retries \u2014 throw on first failure\n})\n\n// Errors are thrown immediately without any wait\ntry {\n await talonic.documents.list()\n} catch (err) {\n // err.retryable tells you if this WOULD have been retried\n if (err instanceof TalonicError && err.retryable) {\n console.log('This error would be retried in production (maxRetries > 0)')\n }\n}"
|
|
47254
|
+
},
|
|
47255
|
+
{
|
|
47256
|
+
type: "paragraph",
|
|
47257
|
+
text: "Non-retryable errors are never retried regardless of `maxRetries`. Authentication errors (401, 403), validation errors (400, 409, 413, 422), and not-found errors (404) are thrown immediately on the first attempt. The API can also mark specific errors as non-retryable by setting `retryable: false` in the error response body, which the SDK respects even for status codes that would normally be retried."
|
|
47258
|
+
},
|
|
47259
|
+
{
|
|
47260
|
+
type: "code",
|
|
47261
|
+
language: "typescript",
|
|
47262
|
+
title: "Custom retry logic on top of SDK retries",
|
|
47263
|
+
code: "import { Talonic, TalonicRateLimitError, TalonicError } from '@talonic/node'\n\n// For critical pipelines, add your own retry layer on top\nasync function extractWithFallback(talonic: Talonic, params: Parameters<Talonic['extract']>[0]) {\n try {\n return await talonic.extract(params)\n } catch (err) {\n if (err instanceof TalonicRateLimitError) {\n // SDK retries are exhausted \u2014 wait for the rate limit reset and try once more\n const waitMs = err.rateLimit.resetAt.getTime() - Date.now()\n if (waitMs > 0 && waitMs < 120_000) {\n console.log(`Rate limited. Waiting ${Math.ceil(waitMs / 1000)}s for reset...`)\n await new Promise(r => setTimeout(r, waitMs + 100))\n return await talonic.extract(params)\n }\n }\n throw err\n }\n}"
|
|
47264
|
+
},
|
|
47265
|
+
{
|
|
47266
|
+
type: "paragraph",
|
|
47267
|
+
text: "The transport layer handles `TalonicTimeoutError` and `TalonicNetworkError` as retryable by default. Timeout errors are raised when a request exceeds the configured `timeout` milliseconds (default 60s). Network errors cover DNS failures, TCP resets, and unreachable hosts. Both carry `status: 0` because no HTTP response was received. After all retries are exhausted, the last error is thrown with `retryable: true` still set, so your application code can decide whether to queue the request for later processing."
|
|
47268
|
+
},
|
|
47269
|
+
{
|
|
47270
|
+
type: "callout",
|
|
47271
|
+
text: "Rate limit retries respect the `X-RateLimit-Reset` header from the API, so the SDK waits the exact right amount of time before retrying a 429."
|
|
47272
|
+
}
|
|
46279
47273
|
],
|
|
46280
47274
|
related: [
|
|
46281
|
-
{
|
|
46282
|
-
|
|
46283
|
-
|
|
47275
|
+
{
|
|
47276
|
+
label: "Configuration",
|
|
47277
|
+
slug: "sdk-configuration"
|
|
47278
|
+
},
|
|
47279
|
+
{
|
|
47280
|
+
label: "Error Classes",
|
|
47281
|
+
slug: "sdk-error-classes"
|
|
47282
|
+
}
|
|
46284
47283
|
],
|
|
46285
47284
|
faq: [
|
|
46286
|
-
{
|
|
47285
|
+
{
|
|
47286
|
+
question: "Does the Talonic SDK retry failed requests?",
|
|
47287
|
+
answer: "Yes. It retries on 429, 500, 502, 503, 504, network errors, and timeouts with exponential backoff and jitter, up to maxRetries attempts (default 3). Non-retryable errors like 401, 403, 400, and 404 are thrown immediately."
|
|
47288
|
+
},
|
|
47289
|
+
{
|
|
47290
|
+
question: "What is the maximum backoff time between retries?",
|
|
47291
|
+
answer: "The exponential backoff caps at 16 seconds. For 429 rate-limit errors, the SDK instead waits until the server-provided reset timestamp (plus 100ms buffer), up to a maximum of 60 seconds. If the reset window exceeds 60 seconds, standard backoff is used instead."
|
|
47292
|
+
},
|
|
47293
|
+
{
|
|
47294
|
+
question: "Can the API override the SDK's retry behavior?",
|
|
47295
|
+
answer: "Yes. If the API returns retryable: false on an error response, the SDK will not retry that request regardless of the status code or maxRetries setting."
|
|
47296
|
+
},
|
|
47297
|
+
{
|
|
47298
|
+
question: "What is the exact backoff formula?",
|
|
47299
|
+
answer: "The wait time is min(1000 * 2^attempt, 16000) + random(0, 250) milliseconds. So: ~1s for the first retry, ~2s for the second, ~4s for the third, capping at ~16s. The random jitter of up to 250ms prevents thundering-herd problems when multiple clients retry simultaneously."
|
|
47300
|
+
},
|
|
47301
|
+
{
|
|
47302
|
+
question: "Are timeout and network errors retried?",
|
|
47303
|
+
answer: "Yes. Both TalonicTimeoutError and TalonicNetworkError are marked retryable: true and are retried up to maxRetries times. They carry status: 0 because no HTTP response was received. They are only thrown to your code after all retry attempts are exhausted."
|
|
47304
|
+
}
|
|
46287
47305
|
],
|
|
46288
|
-
mentions: [
|
|
47306
|
+
mentions: [
|
|
47307
|
+
"retry",
|
|
47308
|
+
"backoff",
|
|
47309
|
+
"rate limit",
|
|
47310
|
+
"429"
|
|
47311
|
+
]
|
|
46289
47312
|
}
|
|
46290
47313
|
];
|
|
46291
47314
|
|