> ## 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

> Bun client classes, methods and options.

# Referencia

## `MarkpdfClient`

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

const client = new MarkpdfClient({
  apiKey: "YOUR_API_KEY",                 // o Bun.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
  autoPoll: true,                       // default true, ver Streaming y async
});
```

<ParamField body="apiKey" type="string" required>
  Your API key. If you don't pass it, the client reads `Bun.env.MARKPDF_API_KEY`.
</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.
</ParamField>

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

<ParamField body="autoPoll" type="boolean" default="true">
  If the server responds `202` (backends saturated), it automatically polls `GET /jobs/{id}`. It can be overwritten by call.
</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(
  path: string,
  options?: {
    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;
  }
): Promise<string | ConversionResult>
```

Opens `path` with `Bun.file(path)` and passes it as body of `POST /convert/raw` — Bun streams the file directly to the socket, without going through an intermediate `Buffer`. The `filename` is inferred from the base name of `path`.

### `convertBytes`

```ts theme={null}
client.convertBytes(
  data: Uint8Array | ArrayBuffer | Blob,
  filename: string,
  options?: { /* mismas opciones que convertFile */ }
): Promise<string | ConversionResult>
```

Same as `convertFile`, but for data already loaded into memory (for example, the body of an incoming `Request`).

### `convertFromUrl`

```ts theme={null}
client.convertFromUrl(
  url: string,
  filename?: string,
  options?: { /* mismas opciones que convertFile */ }
): Promise<string | ConversionResult>
```

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

### `convertStream`

```ts theme={null}
client.convertStream(
  path: string,
  options?: {
    inputFormat?: InputFormat;
    clean?: boolean;
    slim?: boolean;                     // default true
    streamSlimStrategy?: "off" | "sampled" | "full"; // default "sampled"
  }
): AsyncGenerator<string>
```

Async generator that emits Markdown fragments as they arrive from `POST /convert/stream`, reading the file with `Bun.file(path)`. See [Streaming and async](/docs/sdks/bun/streaming-and-async).

### `pdfIndex`

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

Call `POST /pdf/index`. Returns the typed spine.

```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}`.

### `waitForJob`

```ts theme={null}
client.waitForJob(
  jobId: string,
  options?: { pollIntervalMs?: number; timeoutMs?: number }
): Promise<JobStatus>
```

Polls `GET /jobs/{id}` until the status is `completed` or `failed`, or until `timeoutMs` is exhausted. Used internally by `autoPoll: true`.

## 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/bun`:

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