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

# Referencia

> Node.js/TypeScript client classes, methods and options.

# Referencia

## `MarkpdfClient`

```ts theme={null}
import { MarkpdfClient } from "@markpdf/sdk";

const client = new MarkpdfClient({
  apiKey: "YOUR_API_KEY",              // o process.env.MARKPDF_API_KEY
  baseUrl: "https://api.markpdf.tech", // optional, production default
  timeoutMs: 300_000,                 // default 300000 (5 min)
  maxRetries: 2,                      // reintentos en 429/5xx
});
```

<ParamField body="apiKey" type="string" required>
  Your API key. If you don't pass it, the client reads `process.env.MARKPDF_API_KEY` (Node) or `Deno.env` (Deno).
</ParamField>

<ParamField body="baseUrl" type="string" default="https://api.markpdf.tech">
  URL base of API.
</ParamField>

<ParamField body="timeoutMs" type="number" default="300000">
  Timeout per request in milliseconds, implemented with `AbortController`.
</ParamField>

<ParamField body="maxRetries" type="number" default="2">
  Automatic retries with exponential backoff in `429` and `5xx`.
</ParamField>

<ParamField body="fetch" type="typeof fetch">
  Implementation of `fetch` to use. By default it uses the global `fetch` of the runtime. Useful for injecting a `fetch` with a proxy or for tests.
</ParamField>

## Methods

They all accept the same options as the [query params of API](/docs/api/parameters), in camelCase.

### `convertFile`

```ts theme={null}
client.convertFile(
  data: Buffer | Uint8Array | Blob | File,
  options?: {
    filename?: string;
    inputFormat?: InputFormat;   // default "auto"
    mode?: ConvertMode;          // default "fast"
    engine?: Engine;             // default "auto"
    clean?: boolean;             // default true
    imageOcr?: boolean;          // default false
    hybridOcr?: boolean;         // default false
    responseFormat?: "markdown" | "json"; // default "markdown"
    pages?: string;
    outputUrl?: string;
    outputEncoding?: "identity" | "gzip" | "zstd";
    outputHeadUrl?: string;
    autoPoll?: boolean;          // default true
  }
): Promise<string | ConversionResult>
```

Upload content to `POST /convert/raw`. Returns `Promise<string>` with Markdown, or `Promise<ConversionResult>` if `responseFormat: "json"`.

<ParamField body="autoPoll" type="boolean" default="true">
  If the server responds `202` (backends saturated), SDK automatically polls `GET /jobs/{id}`. With `autoPoll: false`, the method throws `MarkpdfJobQueuedError` with `jobId` to do a manual poll. See [Streaming and async](/docs/sdks/nodejs/streaming-and-async).
</ParamField>

### `convertFromUrl`

```ts theme={null}
client.convertFromUrl(
  url: string,
  options?: {
    filename?: string;
    inputFormat?: InputFormat;
    mode?: ConvertMode;
    engine?: Engine;
    clean?: boolean;
    imageOcr?: boolean;
    hybridOcr?: boolean;
    responseFormat?: "markdown" | "json";
    pages?: string;
    outputUrl?: string;
    outputEncoding?: "identity" | "gzip" | "zstd";
    outputHeadUrl?: string;
    autoPoll?: boolean;
  }
): Promise<string | ConversionResult>
```

Llama a `POST /convert/from-url`.

### `convertStream`

```ts theme={null}
client.convertStream(
  input: { data: Buffer | Blob | File } | { url: string },
  options?: {
    filename?: string;
    inputFormat?: InputFormat;
    clean?: boolean;
    slim?: boolean;                     // default true
    streamSlimStrategy?: "off" | "sampled" | "full"; // default "sampled"
  }
): AsyncIterable<string>
```

Returns a `AsyncIterable<string>` that emits Markdown fragments as they arrive by `POST /convert/stream` or `/convert/stream-from-url`. See [Streaming and async](/docs/sdks/nodejs/streaming-and-async).

### `pdfIndex`

```ts theme={null}
client.pdfIndex(url: string, options?: { filename?: string }): Promise<PdfSpine>
```

Call `POST /pdf/index`. Returns the typed spine — same fields as [`POST /pdf/index`](/docs/api/pdf-index).

```ts theme={null}
const spine = await client.pdfIndex("https://bucket.example.com/report.pdf?sig=...");
for (const section of spine.sections) {
  console.log(section.page, section.level, section.text);
}
```

### `getJob`

```ts theme={null}
client.getJob(jobId: string): Promise<JobStatus>
```

Consulta manualmente `GET /jobs/{id}`.

## Tipos

### `ConversionResult`

```ts theme={null}
interface ConversionResult {
  markdown: string;
  filename: string;
  inputFormat: string;
  engine: string;
  sizeBytes: number;
  markdownBytes: number;
  tokenSavedEstimate: number;
  timings: {
    convertMs: number;
    cleanMs: number;
    totalWorkerMs: number;
    uploadMs: number;
    totalRequestMs: number;
  };
}
```

### `PdfSpine`

```ts theme={null}
interface PdfSpine {
  pageCount: number;
  inputBytes: number;
  fontModel: { bodySize: number; headingSizes: number[] };
  sections: Array<{ page: number; level: number; text: string }>;
  repeatedHeadersFooters: string[];
  pages: Array<{ page: number; chars: number; firstLine: string; headings: unknown[] }>;
  pagesTruncated: boolean;
  estimatedTokensFull: number;
  estimatedTokensSpineOnly: number;
}
```

### `JobStatus`

```ts theme={null}
interface JobStatus {
  jobId: string;
  status: "queued" | "processing" | "completed" | "failed";
  body?: string | Record<string, unknown>;
  error?: string;
}
```

All types are exported from `@markpdf/sdk` for you to use in your own code:

```ts theme={null}
import type { ConversionResult, PdfSpine, JobStatus, ConvertMode } from "@markpdf/sdk";
```
