> ## Documentation Index
> Fetch the complete documentation index at: https://docs.avraapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js SDK utility services

> Use the AvraAPI Node.js SDK to generate QR codes, barcodes, and PDFs.

Use `avraapi.utilities()` for the four released Utility operations. Image and
binary-PDF modes return `BinaryResponse`; Base64 modes return `ApiResponse`.
Choose the response type before writing application handling code.

<Note>
  Generated output can contain customer or business data. Keep Utility calls
  and generated media in your backend. Use `withPrivacyMode()` immediately
  before an operation, or its existing `privacyMode: true` input, when the
  request needs the one-request AvraAPI privacy guarantee.
</Note>

## Generate a QR code

`generateQr(params)` accepts text, a URL, or a vCard. `png` and `svg` return
`BinaryResponse`; `base64` returns `ApiResponse<QrBase64Data>`.

**SDK function**

```ts title="Copy the SDK call" theme={null}
const response = await avraapi.utilities().generateQr({
  data: 'QR_CONTENT',
});
```

| Field | Use |
| - | - |
| `data` | Text, URL, or vCard value to encode. |
| `format` | Optional: `png` (default), `svg`, or `base64`. |
| `size`, `foregroundColor`, `backgroundColor` | Optional image styling. |
| `logoUrl`, `logoSizePercent` | Optional public logo URL and 5–40% logo size. |
| `privacyMode` | Optional; sends `X-Privacy-Mode: 1`. |

```ts title="Save a styled PNG QR code" theme={null}
import { BinaryResponse } from '@avraapi/node-sdk';

// AvraAPI SDK call.
const response = await avraapi.utilities().generateQr({
  data: 'https://example.com/receipt/ORDER-2026-001',
  format: 'png',
  size: 400,
  foregroundColor: '0450ff',
  backgroundColor: 'ffffff',
  logoUrl: 'https://example.com/brand-mark.png',
  logoSizePercent: 20,
  privacyMode: true,
});

// Your application code.
if (response instanceof BinaryResponse) {
  await response.saveAs('./generated/order-qr.png');
}
```

### PNG or SVG response

For `png` the body is a Buffer with `image/png`; for `svg` it is a Buffer with
`image/svg+xml`. Use `getBuffer()`, `saveAs()`, `contentType`, `size`, and the
nullable `requestId`; do not read media as JSON.

```ts title="Read a Base64 QR response" theme={null}
import { ApiResponse } from '@avraapi/node-sdk';
import type { QrBase64Data } from '@avraapi/node-sdk';

// AvraAPI SDK call.
const response = await avraapi.utilities().generateQr({
  data: 'https://example.com/receipt/ORDER-2026-001',
  format: 'base64',
});

// Your application code.
if (response instanceof ApiResponse) {
  const dataUri = (response.data as QrBase64Data).data_uri;
}
```

### Base64 response

```json theme={null}
{
  "success": true,
  "request_id": "01f00000-0000-4000-8000-000000000021",
  "data": {"format": "base64", "data_uri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..."}
}
```

`logoUrl` must be a public HTTP or HTTPS image AvraAPI can fetch. It applies to
PNG and Base64 output; SVG does not include the logo. See [Generate a QR code](/api-reference/utilities/qr-generate).

## Generate a barcode

`generateBarcode(params): Promise<BinaryResponse>` always returns media; it
has no Base64 mode.

**SDK function**

```ts title="Copy the SDK call" theme={null}
const response = await avraapi.utilities().generateBarcode({
  data: 'BARCODE_CONTENT',
});
```

| Field | Use |
| - | - |
| `data` | Value to encode. |
| `type` | Optional barcode type; default `C128`. |
| `format` | Optional `png` (default) or `svg`. |
| `height`, `widthFactor`, `privacyMode` | Optional rendering and privacy controls. |

```ts title="Save a barcode image" theme={null}
// AvraAPI SDK call.
const response = await avraapi.utilities().generateBarcode({
  data: 'ORDER-2026-001',
  type: 'C128',
  format: 'png',
  height: 80,
  widthFactor: 2,
});

// Your application code.
await response.saveAs('./generated/order-barcode.png');
const isPng = response.isPng();
```

### PNG or SVG response

PNG returns `image/png`; SVG returns `image/svg+xml`. Use `saveAs()`, stream
`getBuffer()` from your own backend, or use `toDataUri()` only in an approved
server-rendered context. The full barcode type rules are in [Generate a barcode](/api-reference/utilities/barcode-generate).

## Generate a PDF from HTML

`generatePdf(params)` renders HTML to a PDF. `responseType: 'binary'` (the
default) returns `BinaryResponse`; `responseType: 'base64'` returns
`ApiResponse<PdfBase64Data>`.

**SDK function**

```ts title="Copy the SDK call" theme={null}
const response = await avraapi.utilities().generatePdf({
  html: '<html><body>Document content</body></html>',
});
```

| Field | Use |
| - | - |
| `html` | HTML document or fragment to render. |
| `responseType` | Optional `binary` (default) or `base64`. |
| `pageSize`, `orientation`, `margins` | Optional layout values; margins are millimetres. |
| `isBase64` | `true` only when `html` is already Base64 encoded. |
| `privacyMode` | Optional; sends `X-Privacy-Mode: 1`. |

```ts title="Save a binary PDF" theme={null}
import { BinaryResponse } from '@avraapi/node-sdk';

// AvraAPI SDK call.
const response = await avraapi.utilities().generatePdf({
  html: '<html><body><h1>Order receipt</h1></body></html>',
  responseType: 'binary',
  pageSize: 'A4',
  orientation: 'portrait',
  margins: { top: 15, right: 15, bottom: 15, left: 15 },
  privacyMode: true,
});

if (response instanceof BinaryResponse) {
  await response.saveAs('./generated/receipt.pdf');
}
```

### Binary PDF response

With `responseType: 'binary'`, the success body is a Buffer with
`application/pdf`. It is not JSON.

```ts title="Read a Base64 PDF response" theme={null}
import { ApiResponse } from '@avraapi/node-sdk';
import type { PdfBase64Data } from '@avraapi/node-sdk';

const response = await avraapi.utilities().generatePdf({
  html: '<html><body><h1>Order receipt</h1></body></html>',
  responseType: 'base64',
  privacyMode: true,
});

if (response instanceof ApiResponse) {
  const data = response.data as PdfBase64Data;
  const base64Pdf = data.data;
  const mediaType = data.media_type;
}
```

### Base64 response

```json theme={null}
{
  "success": true,
  "request_id": "abd340d9-2491-4403-b076-51f395048c8d",
  "data": {"format": "base64", "media_type": "application/pdf", "data": "JVBERi0xLjcKMSAwIG9iago..."}
}
```

The Base64 value is document data, not a download URL. Decode, store, or stream
it only in a protected backend context. See [Generate a PDF](/api-reference/utilities/pdf-generate).

## Generate a PDF from raw HTML with Base64 transport

`generatePdfFromBase64(params)` is the convenience wrapper for complex HTML.
Pass raw, unencoded HTML; the SDK encodes it and calls `generatePdf()` with
`isBase64: true`.

**SDK function**

```ts title="Copy the SDK call" theme={null}
const response = await avraapi.utilities().generatePdfFromBase64({
  html: '<html><body>Document content</body></html>',
});
```

The available optional fields are `responseType`, `pageSize`, `orientation`,
`margins`, and `privacyMode`.

```ts title="Render complex HTML without manual encoding" theme={null}
import { readFile } from 'node:fs/promises';
import { BinaryResponse } from '@avraapi/node-sdk';

// Your application code: raw HTML, not Base64 text.
const html = await readFile('./templates/receipt.html', 'utf8');

// AvraAPI SDK call.
const response = await avraapi.utilities().generatePdfFromBase64({
  html,
  privacyMode: true,
});

if (response instanceof BinaryResponse) {
  await response.saveAs('./generated/receipt.pdf');
}
```

### Response

The response uses the same binary or Base64 shapes as `generatePdf()`, selected
by `responseType`. Do not Base64-encode the HTML yourself before using this
convenience method.

## Handle Utility errors

Utility calls reject with typed SDK errors. Keep available request IDs, avoid
placing generated customer data into logs, and use the common handling pattern
in [Node.js Overview and setup](/sdk/nodejs/overview-and-setup#handle-errors-safely).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.