Skip to main content

AI 中转站测速与可用率自检(api-relay-benchmark)

一个不依赖第三方的小脚本:给你自己常用的中转站端点测可用率、状态码、延迟中位数,输出 Markdown 表格贴进 issue、周报或者监控告警里。

中转站评测/中转站测速/API 中转站可用率 · 不需要装包,只用 Python 标准库。

为什么需要它

中转站的"能不能用"和"快不快"是两件事,而且都会随时间变化。别人写的排行榜是别人那一刻的测量结果;你自己跑一次,才知道此刻哪条线路是通的。

安装

不需要安装。只要 Python 3.8+:

git clone https://github.com/kuku-momo/api-relay-benchmark
cd api-relay-benchmark

用法

# 测两个端点,各跑 3 次
python3 bench.py https://ai.tt2066.top/v1 https://api.openai.com/v1 --key $RELAY_KEY

# 端点写在文件里,跑 5 次,顺便存 JSON
python3 bench.py --file endpoints.txt --rounds 5 --json report.json

输出:

| 端点 | 成功/次数 | 状态码 | 中位延迟 | 最快 | 最慢 |
|---|---|---|---|---|---|
| https://ai.tt2066.top/v1 | 3/3 | 200 | 412.3ms | 388.1ms | 470.9ms |

怎么读结果

  • 4xx 全部失败:Key 不对或模型未开通,不是网络问题;
  • 5xx 抖动:上游通道不稳,看是否连续;
  • 中位延迟高但最快值正常:链路拥塞或限流,不是端点本身慢;
  • 只有 error 列有内容:DNS / TLS / 超时,先查本地网络。

端点填什么

填到 /v1(OpenAI 兼容)。脚本会自动拼 /models。Anthropic 兼容的端点用 /v1/messages,本脚本只测 OpenAI 侧连通性。

相关文档

License

MIT

Metadata

Release files for relay-bench 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for relay-bench 0.1.0
File Interpreter ABI Platform Actions
relay_bench-0.1.0-py3-none-any.whl Python 3 none any Details for relay_bench-0.1.0-py3-none-any.whl

Release files / relay_bench-0.1.0-py3-none-any.whl

Download URL relay_bench-0.1.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9bf97885c9e79efab83b9b8802c3165a27529bc70116b7193d0e0e5073067433
BLAKE2b-256 checksum
How to use checksums
03e334fec72d4aa831d4f2717c3eca0f30c361baee59441fd653cc4f8dcccc4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for relay-bench 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page