License
Configure Exchange export authorization, query remaining quota, and handle license errors.
Exchange reads the license inside the server process that runs @univerjs-pro/exchange-node. For the conversion itself, see Office file import and export.
Configure authorization
The standard approach is to set UNIVER_LICENSE and UNIVER_LICENSE_KEY in the environment. Calling configureExchange is then optional: the SDK reads the environment once, on the first export or quota query, and keeps that configuration for the rest of the process. When neither variable is set, Free applies. When the variables are set but the credentials are invalid, calls return an error, and those credentials cannot be used for export.
For explicit configuration, call configureExchange({ license, licenseKey }). The function returns Promise<void> and ignores the environment completely, so await it before starting exports that should use the new credentials.
import { configureExchange, getExportQuota } from '@univerjs-pro/exchange-node'await configureExchange({ license: '<license content>', licenseKey: '<licenseKey content>',})const quota = await getExportQuota()Pass the complete license and licenseKey contents supplied by the license provider, not paths to files. Set both values together and read them from the application's secret management system.
| Input | Behavior |
|---|---|
Do not call configureExchange | Both environment variables are read on first use. Free applies when neither variable is set. |
configureExchange({ license, licenseKey }) | Only the explicit credentials are used. The environment is ignored. |
configureExchange({}) | Free is selected explicitly. The environment is ignored. |
| Only one credential in the selected source | The call returns INVALID_ARGUMENT. The other field is never filled from a different source. |
Once a complete environment configuration has been read, it stays fixed even if a later operation fails. To replace the default credentials at runtime, call configureExchange and await it. A failed call leaves the previous configuration in place, so handle the error before starting new exports.
ESM and CommonJS share a single configuration within the same JavaScript context. Each worker_threads Worker must configure itself or initialize from its own environment. An export uses the configuration that was in place when the public export method was called; changing credentials later does not affect exports that have already started.
Provide authorization for one operation
To authorize a single call without changing the default configuration, pass a complete license and licenseKey pair in the options of an export API or of getExportQuota. The following example queries the quota and exports with the same credentials:
import { UniverInstanceType } from '@univerjs/core'import { ExchangeFormat, exportToBuffer, getExportQuota } from '@univerjs-pro/exchange-node'const credentials = { license: '<license content>', licenseKey: '<licenseKey content>' }const quota = await getExportQuota(credentials)const output = await exportToBuffer(workbook, { type: UniverInstanceType.UNIVER_SHEET, format: ExchangeFormat.XLSX, ...credentials,})File exports, Snapshot exports, and the optional PDF exports accept the same pair. When both fields are omitted, the default configuration applies; when only one field is supplied, the call returns INVALID_ARGUMENT. An explicit pair is never completed from the default configuration or from the environment, and an empty string does not count as an omitted field. Invalid credentials return LICENSE_INVALID, and the SDK does not fall back to the default commercial license.
Optional PDF support
Install the PDF extension package and import its entry before configuring authorization:
pnpm add @univerjs-pro/exchange-node @univerjs-pro/exchange-pdf-node-bindingimport '@univerjs-pro/exchange-node/pdf'import { configureExchange, getExportQuota } from '@univerjs-pro/exchange-node'await configureExchange({ license: '<license content>', licenseKey: '<licenseKey content>',})const quota = await getExportQuota()The import registers PDF support, and the native components load when they are first used. PDF uses the same importBuffer, importFile, exportToBuffer, exportToFile, and corresponding Snapshot APIs, with UniverInstanceType.UNIVER_PDF and ExchangeFormat.PDF. An application that handles only PDF does not need the Office native component. Environment-based configuration applies to PDF as well.
Query remaining quota
getExportQuota({ license, licenseKey }) returns Promise<ExportQuota> for the Office and PDF quota that the authorization shares. When the credentials are omitted, the call queries the default configuration. The call accepts no Unit type and does not check whether a particular export type is permitted; that check occurs during the export.
A query neither consumes nor reserves quota, and it does not check the SDK version, the activation time, or the export type entitlement. A zero balance still returns a successful snapshot. Other requests may consume quota immediately afterward, so handle the errors returned by the actual export as well.
Before the authorization takes effect, a query against a limited quota returns the snapshot for the first authorization month, whose periodStart lies in the future. A successful query, or a valid status, does not mean that export is permitted. The SDK checks version, activation, type entitlement, available quota, and concurrency during the export.
| Field | Type | Meaning |
|---|---|---|
licenseStatus | 'not_configured' | 'expired' | 'valid' | The export subscription is unconfigured, expired, or not yet expired. valid does not mean that the export admission checks have passed. Invalid credentials return an error. |
expiresAt | string | null | Expiry of the export subscription as a UTC ISO timestamp. null when nothing is configured or no expiry applies. |
observedAt | string | UTC ISO timestamp of this snapshot. |
limit | number | null | Current monthly export limit. null when the quota is unlimited. |
used | number | null | Successful exports in the current month. null when the quota is unlimited. |
reserved | number | null | In-flight exports that hold quota in the current month. null when the quota is unlimited. |
remaining | number | null | Exports still available, calculated as max(0, limit - used - reserved). null when the quota is unlimited. |
periodStart | string | null | Inclusive UTC ISO start of the queried monthly quota window. The first period starts in the future, before activation. null when the quota is unlimited. |
periodEnd | string | null | Exclusive UTC ISO end of the queried monthly quota window. null when the quota is unlimited. |
For Free (Freemium), quota represents the monthly watermark-free export allowance. When remaining reaches zero, complete files can continue to be exported with watermarks. After a commercial subscription expires, Free rules apply with its existing monthly allowance and reset cycle. Continued commercial production use requires renewal of the commercial license.
periodEnd marks the start of the next monthly quota window; expiresAt marks the end of the export subscription. During a valid subscription, exports use commercial quota. Once that quota is exhausted, exports resume at the next monthly reset or with a valid license upgrade providing more quota. On subscription expiry, exports follow Free rules with the existing Free allowance and its monthly reset cycle.
Example of a limited-quota snapshot:
{ "licenseStatus": "valid", "expiresAt": "2027-10-19T23:59:59Z", "observedAt": "2026-10-21T09:00:00Z", "limit": 500, "used": 20, "reserved": 1, "remaining": 479, "periodStart": "2026-10-19T00:00:00Z", "periodEnd": "2026-11-19T00:00:00Z"}Use export quota
Free (Freemium) includes 10 watermark-free exports per authorization month. From the 11th successful export of the month, complete files continue to be exported with watermarks. Each monthly reset restores the watermark-free allowance to 10 exports. Commercial export quota, concurrency, and version entitlements follow the purchased license. At the license level, both Free and commercial licenses allow unlimited file size and cell count. Use the query response for the current period and remaining allowance.
Imports require no export authorization and consume no export quota. Within one deployment, Office and PDF exports that use the same commercial license share quota. The Exchange conversion formats are listed in Office file import and export.
Each successful conversion counts once; returning a Buffer counts as success. The count remains recorded if a subsequent file write, upload, or download fails. Another successful conversion counts again. After the Free watermark-free allowance is exhausted, complete exports continue with watermarks. Once a valid commercial license exhausts its export quota, further exports require the next monthly reset or a valid license upgrade providing more quota.
Handle errors
Identify errors by the structured code rather than by parsing the message text. The UI can map error codes to localized messages. Retain the diagnostic details for technical support.
import { UniverInstanceType } from '@univerjs/core'import { ExchangeError, ExchangeFormat, exportToBuffer } from '@univerjs-pro/exchange-node'try { const output = await exportToBuffer(workbook, { type: UniverInstanceType.UNIVER_SHEET, format: ExchangeFormat.XLSX, })} catch (error) { if (error instanceof ExchangeError) { // Display the message for error.code, e.g. LICENSE_EXPORT_QUOTA_EXCEEDED when the quota runs out console.error(error.code) } else { throw error }}The table below states whether an error originates from a quota query (getExportQuota) or from an actual export. Both APIs return Promises, so failures require await and try/catch.
| Code | Operation | Meaning and response |
|---|---|---|
LICENSE_EXPORT_QUOTA_EXCEEDED | Export only | The commercial export quota for the current period is insufficient. Query quota or contact sales to adjust the license. Free exports continue with watermarks after the watermark-free allowance is exhausted. |
LICENSE_CONCURRENCY_TIMEOUT | Export only | Waiting for an export concurrency slot timed out. Reduce concurrent exports before submitting again. |
LICENSE_UNIT_TYPE_REJECTED | Export only | The export type is not covered by the license, or its type entitlement has expired. Provide a valid license that covers the type. |
LICENSE_INVALID | Query, export | The license is invalid. Check the complete credentials, or request an update from the license provider. |
LICENSE_POLICY_INVALID | Query, export | The authorization configuration does not meet the SDK requirements. Request an update from the license provider. |
LICENSE_NOT_YET_EFFECTIVE | Export only | The authorization has not yet taken effect. Use it after its effective date. |
LICENSE_VERSION_NOT_ALLOWED | Export only | The current SDK version is outside the licensed range. Use a matching version or update the license. |
UNSUPPORTED_FORMAT | Export only | The format is unsupported or does not match the Unit type. Check the export options. |
INVALID_FILE | Export only | The conversion input is invalid. Check the input contents. |
INCOMPLETE_SNAPSHOT | Export only | The export data is incomplete. Provide complete data or a complete Snapshot. |
CONVERSION_FAILED | Export only | The conversion failed. Retain the error and check the input contents. |
IO_ERROR | Export only | File input or output failed. If the conversion succeeded and writing the output failed, that export has already been consumed. |
INVALID_ARGUMENT | Query, export | Arguments or credentials are incomplete. Check the configuration. |
NATIVE_LOAD_FAILED | Query, export | A native SDK component failed to load. Check that the installed packages match the runtime environment. |
LICENSE_USAGE_STATE_INVALID | Query, export | The license usage state cannot be verified. Retain the error and contact technical support. |
LICENSE_USAGE_STORAGE_ERROR | Query, export | License usage processing failed. Retain the error, contact technical support, and do not resubmit automatically. |
The application can build expiry reminders from licenseStatus and expiresAt. The SDK does not return a separate list of notices.
After a license usage processing error, do not infer from the error alone whether the export was counted. Retain the full error and contact technical support.
How is this guide?