# Truncate API
> Truncate text cleanly. Cut a string to a maximum number of characters — at the end, the start or the middle — breaking on word boundaries so words are never chopped in half, and adding an ellipsis (which counts toward the limit). Middle truncation keeps the start and end and elides the centre, ideal for long file paths and IDs. A words endpoint trims to a number of whole words instead. Everything is emoji- and Unicode-safe (it counts code points, not bytes), so multi-byte characters and emoji are never split. Perfect for previews and teasers, table cells and cards, meta descriptions, breadcrumbs and CLI output. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 3 endpoints. Distinct from word wrapping, case conversion and text statistics.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/truncate-api/..."
```

## Pricing
- **Free** (Free) — 1,205 calls/Mo, 2 req/s
- **Starter** ($2/Mo) — 10,450 calls/Mo, 8 req/s
- **Pro** ($22/Mo) — 155,500 calls/Mo, 20 req/s
- **Mega** ($60/Mo) — 820,000 calls/Mo, 50 req/s

## Endpoints

### Truncate

#### `GET /v1/truncate` — Truncate by characters

**Parameters:**
- `text` (query, required, string) — Text to truncate Example: `The quick brown fox jumps over the lazy dog`
- `length` (query, optional, string) — Max characters (default 100) Example: `20`
- `position` (query, optional, string) — end|start|middle (default end) Example: `end`
- `ellipsis` (query, optional, string) — Ellipsis (default …)
- `preserve_words` (query, optional, string) — true/false (default true)

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/truncate-api/v1/truncate?text=The+quick+brown+fox+jumps+over+the+lazy+dog&length=20&position=end"
```

**Response:**
```json
{
    "data": {
        "position": "end",
        "truncated": "The quick brown…",
        "was_truncated": true,
        "original_length": 43,
        "truncated_length": 16
    },
    "meta": {
        "timestamp": "2026-06-03T09:25:08.981Z",
        "request_id": "4e7050c3-8df7-4283-a556-2d668d0af459"
    },
    "status": "ok",
    "message": "Truncate by characters",
    "success": true
}
```

#### `GET /v1/words` — Truncate by words

**Parameters:**
- `text` (query, required, string) — Text to truncate Example: `The quick brown fox jumps over the lazy dog`
- `words` (query, optional, string) — Max words (default 20) Example: `5`
- `ellipsis` (query, optional, string) — Ellipsis (default …)

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/truncate-api/v1/words?text=The+quick+brown+fox+jumps+over+the+lazy+dog&words=5"
```

**Response:**
```json
{
    "data": {
        "truncated": "The quick brown fox jumps…",
        "was_truncated": true,
        "original_words": 9,
        "truncated_words": 5
    },
    "meta": {
        "timestamp": "2026-06-03T09:25:09.085Z",
        "request_id": "538a81ed-ea17-4085-8a89-1031d76d25fa"
    },
    "status": "ok",
    "message": "Truncate by words",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/truncate-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "name": "Truncate API",
        "notes": "The ellipsis counts toward the character length. middle keeps the start and end and elides the centre (handy for long paths/IDs). Nothing is stored.",
        "version": "v1",
        "endpoints": [
            {
                "path": "/v1/truncate",
                "params": {
                    "text": "the text (required)",
                    "length": "max characters (default 100)",
                    "ellipsis": "default …",
                    "position": "end|start|middle",
                    "preserve_words": "true/false (default true)"
                },
                "returns": "the truncated text"
            },
            {
                "path": "/v1/words",
                "params": {
                    "text": "the text (required)",
                    "words": "max words (default 20)",
                    "ellipsis": "default …"
                },
                "returns": "the text cut to N whole words"
            },
            {
                "path": "/v1/meta",
                "params": [],
                "returns": "this document"
            }
        ],
        "description": "Truncate text cleanly. Cut to a maximum number of characters at the end, start or middle, breaking on word boundaries (so words are never chopped in half) and adding an ellipsis — or truncate to a number of whole words. Emoji-safe (counts code points, not bytes). Pure local, no key."
    },
   
…(truncated, see openapi.json for full schema)
```


---
Marketplace page: https://www.oanor.com/api/truncate-api
OpenAPI spec: https://www.oanor.com/api/truncate-api/openapi.json
