POST
/translate
请求体 (JSON):
{
"text": "Hello, world",
"target_lang": "zh-Hans",
"source_lang": "en"
}
target_lang 必填,需大小写匹配;可用 BCP-47 全名或上方下拉中的裸代码。
source_lang 可省略,由服务端自动检测;填写时需在 源语言 列表内。
- 单次文本上限 6000 字符。
成功响应:
{ "status": 0, "text": "你好,世界", "alternatives": ["..."] }
失败响应:
{ "status": 1, "msg": "错误信息" }
GET
/languages
返回当前会话下服务端下发的可用源/目标语言列表及单次文本上限。
{ "source": ["en","zh",...], "target": ["en-US","zh-Hans",...], "max_text_len": 6000 }
GET
/metrics
运行时指标 (JSON),含 QPS、平均延迟、缓存命中率、会话池利用率。
{
"requests_total": 19, "errors_total": 0, "rejected_total": 0,
"inflight": 0, "avg_latency_ms": 626.1,
"cache": { "size": 12, "cap": 4096, "hits": 7, "misses": 12 },
"pool": { "live": 5, "idle": 4, "max": 32,
"acquired": 12, "created": 5, "reused": 7,
"evicted": 0, "wait_count": 0 }
}
pool.reused / created:会话复用 vs 新建数;created 多说明池/预热不足。
pool.wait_count:因池满而排队的次数,持续增长应调大 -pool。
cache.hits / misses:重复文本走缓存的次数。
GET
/health
健康检查 (始终可访问)。返回探针就绪状态与激活码剩余时间:
{
"status": 0, "ready": true,
"license_valid": true, "license_remaining_seconds": 2592000
}