简单链接缩短器

API 文档

用于创建永久 301 短链的 JSON API,支持中间页与 PNG QR。

API 概览

基础 URL: https://pth.bz

端点

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

Content-Type: application/json

请求

Body JSON:

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

响应

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"
}
其他状态
  • 400 错误请求 - JSON/URL 无效。
  • 405 不允许的方法 - 使用 POST。
  • 429 请求过多 - 超出限制。
  • 500 内部错误。

选择重定向

301(默认)

快速永久重定向: /CODE

中间页(防机器人)

短暂 JS 步骤并隐藏来源: /i/CODE

QR 代码(PNG)

  • For 301: /?qr=CODE
  • For interstitial: /?qi=CODE
  • 可选像素大小:(200–2048) &px=640
<img src="https://pth.bz/?qr=AbC1234&px=640" alt="QR" />

错误响应

{
  "error": "Too many requests"
}

限制与规则

  • 限制:每IP每10分钟30次。
  • 仅支持 http:// 和 https://。
  • 最大 URL 长度:2000 字符。
  • 仅 JSON:设置 Content-Type: application/json。

示例

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

面向 简单链接缩短器 的官方 Python 库。

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())
本地 URL 校验与服务器规则一致:仅 http/https,不含用户信息;允许 localhost 与无点 IP;IDN 转换为 punycode。