Skip to main content

Client Options

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.

All options
import { Talonic } from '@talonic/node'

const talonic = new Talonic({
  apiKey: process.env.TALONIC_API_KEY!,
  baseUrl: 'https://api.talonic.com',   // default
  timeout: 60_000,                       // ms; default 60s
  maxRetries: 3,                         // 429, 500, 502, 503, 504, network, timeout
  fetch: customFetch,                    // optional override (e.g. for testing)
})

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).

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.

Testing with a mock fetch
import { Talonic } from '@talonic/node'

// Inject a custom fetch for testing
const mockFetch = async (url: string, init?: RequestInit) => {
  console.log(`Request: ${init?.method} ${url}`)
  return new Response(JSON.stringify({ balance_credits: 1000, tier: 'free' }), {
    status: 200,
    headers: { 'content-type': 'application/json' },
  })
}

const talonic = new Talonic({
  apiKey: 'tlnc_test_key',
  fetch: mockFetch as typeof fetch,
})

const balance = await talonic.credits.getBalance()
console.log(balance.balance_credits) // 1000

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.

Production configuration
// Production: higher timeout for large documents, default retries
const talonic = new Talonic({
  apiKey: process.env.TALONIC_API_KEY!,
  timeout: 120_000, // 2 minutes for large documents
  maxRetries: 3,    // default — retries 429, 5xx, network, timeout
})

// Development: fast feedback, no retries
const devClient = new Talonic({
  apiKey: process.env.TALONIC_API_KEY!,
  timeout: 30_000,
  maxRetries: 0, // fail immediately on errors
})

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.

API keys use the tlnc_ prefix. Store them in environment variables or a secrets manager rather than hard-coding them in source files.
ParameterTypeDescription
apiKey *stringYour Talonic API key. Starts with `tlnc_`.
baseUrlstringAPI base URL. Trailing slashes are stripped automatically. Default: `https://api.talonic.com`
timeoutnumberRequest timeout in milliseconds. Applies per-request including retries. Default: `60000`
maxRetriesnumberMax retry attempts for transient failures (429, 5xx, network, timeout). Set to 0 to disable. Default: `3`
fetchfunctionCustom fetch implementation for testing, instrumentation, or polyfilling Node < 18.

Frequently asked questions

How do I configure the Talonic SDK client?+
Pass an options object to new Talonic() with apiKey (required), and optional baseUrl, timeout, maxRetries, and fetch. All options except apiKey have sensible defaults.
Can I disable automatic retries?+
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.
What happens if no fetch implementation is available?+
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.
Does the constructor validate the API key with the server?+
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.
What headers does the SDK send with every request?+
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.