Simple URL Shortener

API Documentation

Simple JSON API to create short links with permanent 301, optional interstitial, and PNG QR codes.

API Overview

Base URL: https://pth.bz

Endpoint

POST https://pth.bz/api/shorten

Content-Type: application/json

Request

Body JSON:

{
  "url": "https://example.com/landing?utm_source=newsletter"
}

Response

200 OK:

{
  "short_url_301": "https://pth.bz/AbC1234",
  "short_url_js": "https://pth.bz/i/AbC1234",
  "qr_301_png_url": "https://pth.bz/?qr=AbC1234",
  "qr_js_png_url": "https://pth.bz/?qi=AbC1234"
}
Other statuses
  • 400 Bad Request - invalid JSON, missing url, or invalid URL.
  • 405 Method Not Allowed - use POST.
  • 429 Too Many Requests - rate limit exceeded.
  • 500 Internal error - transient server error.

Choosing redirect

301 (default)

Fast permanent redirect: /CODE

Interstitial (anti-bot)

Short JS step and referrer is hidden: /i/CODE

QR codes (PNG)

  • For 301: /?qr=CODE
  • For interstitial: /?qi=CODE
  • Optional size in px: (200–2048) &px=640
<img src="https://pth.bz/?qr=AbC1234&px=640" alt="QR" />

Error responses

{
  "error": "Too many requests"
}

Limits and rules

  • Rate limit: 30 requests per 10 minutes per IP (HTTP 429 on exceed).
  • Only http:// and https:// links are allowed.
  • Max URL length: 2000 characters.
  • JSON only: set Content-Type: application/json.

Examples

curl
curl -X POST "https://pth.bz/api/shorten" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}'
JavaScript (fetch)
const res = await fetch('https://pth.bz/api/shorten', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ url: 'https://example.com' })
});
const data = await res.json();
console.log(data.short_url_301, data.short_url_js);
Python (requests)
import requests

r = requests.post('https://pth.bz/api/shorten', json={'url': 'https://example.com'})
print(r.status_code, r.json())

SDKs

Python SDK

Official Python library for Simple URL Shortener.

Install
pip install pthbz
Quick start (sync)
from pthbz import PthBzClient

client = PthBzClient(base_url="https://pth.bz")
res = client.shorten("https://example.com/landing?utm_source=newsletter")
print(res.short_url_301)   # https://pth.bz/AbC1234
print(res.short_url_js)    # https://pth.bz/i/AbC1234
print(res.qr_301_png_url)  # https://pth.bz/?qr=AbC1234
print(res.qr_js_png_url)   # https://pth.bz/?qi=AbC1234
client.close()
Async variant
import asyncio
from pthbz import AsyncPthBzClient

async def main():
    async with AsyncPthBzClient(base_url="https://pth.bz") as client:
        res = await client.shorten("https://example.com")
        print(res.short_url_301)

asyncio.run(main())
Local URL validation mirrors server rules: only http/https, userinfo forbidden, localhost and dotless IP allowed, IDN → punycode.