Acortador de URL simple

Documentación de API

API JSON para crear enlaces cortos con 301 permanente, paso intermedio opcional y QR PNG.

Resumen del API

URL base: https://pth.bz

Endpoint

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

Content-Type: application/json

Solicitud

Body JSON:

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

Respuesta

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"
}
Otros estados
  • 400 Bad Request - JSON no válido, falta url o URL no válida.
  • 405 Method Not Allowed - usa POST.
  • 429 Too Many Requests - límite excedido.
  • 500 Internal error - error interno.

Elegir redirección

301 (por defecto)

Redirección permanente rápida: /CODE

Intersticial (anti-bot)

Paso JS y referente oculto: /i/CODE

Códigos QR (PNG)

  • For 301: /?qr=CODE
  • For interstitial: /?qi=CODE
  • Tamaño opcional en px: (200–2048) &px=640
<img src="https://pth.bz/?qr=AbC1234&px=640" alt="QR" />

Respuestas de error

{
  "error": "Too many requests"
}

Límites y reglas

  • Límite: 30 solicitudes por 10 min/IP.
  • Solo http:// y https://.
  • Longitud máxima de URL: 2000 caracteres.
  • Solo JSON: use Content-Type: application/json.

Ejemplos

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())

SDK

Python SDK

Biblioteca oficial de Python para trabajar con Acortador de URL simple.

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())
La validación local de URL refleja las reglas del servidor: solo http/https, sin userinfo, se permiten localhost e IP sin punto, IDN → punycode.