# HTML to Text API

> HTML to Text extracts clean plain text from raw HTML markup, reporting word counts and character counts. It identifies main article bodies automatically, records the extraction method used, and notes whether parsing succeeded.

**Endpoint:** `POST https://api.apiverve.com/v1/htmltotext`  
**Category:** Data Processing  
**Cost:** 2 credits per call  
**Canonical page:** https://apiverve.com/marketplace/htmltotext

## Overview

An HTML to text API for extracting text from HTML in emails, scraped pages and CMS content. HTML to Text works by parsing the HTML content and extracting the text. Text extraction is done by removing the HTML tags and returning the plain text content. Advanced algorithms are used to ensure accurate text extraction.

## Authentication

Every call carries your key in an `x-api-key` header. The same key works across the whole
APIVerve catalog — there are no per-API subscriptions. Responses always use the same three
top-level keys: `status`, `error`, and `data`.

## Example request

```bash
curl -X POST "https://api.apiverve.com/v1/htmltotext" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html":"<!doctype html> <html>  <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>","mode":"value"}'
```

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `html` | string | Yes | The HTML to convert to text |
| `mode` | string | No | auto (default): the main article, or all text when no article is found; article: the main article only; full: all visible text minus navigation, sidebars and banners, for emails, homepages and other non-article HTML. default auto. One of: auto, article, full |

## Response fields

- `text` — string · The article text extracted from the HTML, or null when no article body could be identified
- `parsed` — boolean · Whether article text was successfully extracted - false when the HTML held no identifiable article body
- `extractionMethod` — string · How the text was obtained: article when article-body extraction succeeded, markup when it fell back to reading all the markup, none when no text was found.
- `detectedLanguage` — object · Detected language with confidence score; null when the extracted text is under 20 characters, too short to detect reliably · (premium)
  - `detectedLanguage.language` — string · (premium)
  - `detectedLanguage.confidence` — number · (premium)
- `characterCount` — number · Number of characters in extracted text
- `wordCount` — number · Number of words in extracted text

## Sample response

```json
{
  "status": "ok",
  "error": null,
  "data": {
    "text": "This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.",
    "parsed": true,
    "extractionMethod": "article",
    "detectedLanguage": {
      "language": "english",
      "confidence": 0.3507446808510638
    },
    "characterCount": 118,
    "wordCount": 23
  }
}
```

## Use cases

- **Inbound Email Parsing** — Strip HTML markup from customer support emails before passing unformatted message bodies into ticket triage queues.
- **Search Engine Indexing** — When crawling web pages, remove formatting tags and extract readable text to compute accurate word counts for search indices.
- **LLM Prompt Preparation** — To minimize prompt token counts, data engineers strip raw article markup down to readable text before querying language models.
- **Feed Snippet Generation** — Content aggregators convert rich blog markup into plain text snippets for previews, push notifications, and mobile readers.

## SDKs

- **npm** — `npm install @apiverve/htmltotext` (https://www.npmjs.com/package/@apiverve/htmltotext)
- **PyPI** — `pip install apiverve-htmltotext` (https://pypi.org/project/apiverve-htmltotext/)
- **NuGet** — `dotnet add package APIVerve.API.HTMLtoText` (https://www.nuget.org/packages/APIVerve.API.HTMLtoText)
- **Source** — https://github.com/apiverve/htmltotext-api

## More

- Full reference: https://docs.apiverve.com/ref/htmltotext
- Get an API key: https://dashboard.apiverve.com
- Full catalog: https://apiverve.com/marketplace
