# Tools API

> Convert documents to PDF and capture screenshots using the Tools API.

Tools API
---------

The Tools API lets you convert documents to PDF and capture screenshots of web pages. Each user receives 1,000 API credits per month for free, which reset on the first of each month.

### Getting started

1. Create an API key in **Settings > API keys**
2. Check your credit balance in **Settings > API credits**
3. Include your API key in requests using the Authorization header

For detailed instructions on creating API keys and authenticating requests, see the [API authentication guide](https://ploi.cloud/documentation/api/api-authentication).

### API credits

- Each user gets **1,000 credits per month**
- Credits reset automatically on the **1st of each month**
- All API calls cost **1 credit**
- Balance and health checks are **free**

View your current balance at any time in Settings > API credits, or call the balance endpoint.

### Available endpoints

**Free endpoints**
- `GET /api/v1/tools/health` - Check if the service is available
- `GET /api/v1/tools/balance` - Get your current credit balance

**PDF conversion (1 credit each)**
- `POST /api/v1/tools/pdf/convert/url` - Convert a web page to PDF
- `POST /api/v1/tools/pdf/convert/html` - Convert HTML to PDF
- `POST /api/v1/tools/pdf/convert/markdown` - Convert Markdown to PDF
- `POST /api/v1/tools/pdf/convert/office` - Convert Office documents to PDF
- `POST /api/v1/tools/pdf/merge` - Merge multiple PDFs into one

**Screenshots (1 credit each)**
- `POST /api/v1/tools/screenshot/url` - Screenshot a web page
- `POST /api/v1/tools/screenshot/html` - Screenshot HTML content

### PDF conversion

Convert web pages, HTML, Markdown, or Office documents to PDF format.

**URL to PDF** - Pass a publicly accessible URL:
```
POST /api/v1/tools/pdf/convert/url
{"url": "https://example.com"}
```

**HTML to PDF** - Pass HTML content directly:
```
POST /api/v1/tools/pdf/convert/html
{"html": "<html><body><h1>Hello</h1></body></html>"}
```

**Markdown to PDF** - Pass Markdown content:
```
POST /api/v1/tools/pdf/convert/markdown
{"markdown": "# Hello World\n\nThis is **bold** text."}
```

**Office to PDF** - Upload a file (Word, Excel, PowerPoint, etc.):
```
POST /api/v1/tools/pdf/convert/office
Content-Type: multipart/form-data
file: document.docx
```

Supported formats: .docx, .doc, .xlsx, .xls, .pptx, .ppt, .odt, .ods, .odp, .rtf, .txt, .csv

**Merge PDFs** - Combine multiple PDF files:
```
POST /api/v1/tools/pdf/merge
Content-Type: multipart/form-data
files[]: file1.pdf
files[]: file2.pdf
```

### Screenshots

Capture screenshots of web pages or HTML content.

**URL screenshot:**
```
POST /api/v1/tools/screenshot/url
{"url": "https://example.com", "width": 1920, "height": 1080, "format": "png"}
```

**HTML screenshot:**
```
POST /api/v1/tools/screenshot/html
{"html": "<html><body><h1>Hello</h1></body></html>", "width": 800, "height": 600}
```

Options:
- `width` - Viewport width (100-4096 pixels, default 1920)
- `height` - Viewport height (100-4096 pixels, default 1080)
- `format` - Image format: `png` or `jpeg` (default png)

### Error responses

| Status | Meaning |
|--------|---------|
| 402 | Insufficient credits - wait for monthly reset or check your balance |
| 422 | Validation error - check the required fields |
| 502 | Service temporarily unavailable - try again later |

### API documentation

For complete endpoint documentation with all parameters and examples, visit the [interactive API docs](https://ploi.cloud/docs/api) and tap 'Tools'.
