[PR #123] [MERGED] feat(usage): 添加provider健康检查接口 #268

Closed
opened 2026-02-27 07:18:45 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/justlovemaki/AIClient-2-API/pull/123
Author: @unihon
Created: 12/22/2025
Status: Merged
Merged: 12/22/2025
Merged by: @justlovemaki

Base: mainHead: feature/provider-health-api


📝 Commits (2)

  • 5dc1c5e feat(usage): 添加provider健康检查接口
  • f9d8357 Merge branch 'justlovemaki:main' into feature/provider-health-api

📊 Changes

2 files changed (+128 additions, -1 deletions)

View changed files

📝 src/request-handler.js (+34 -1)
📝 src/service-manager.js (+94 -0)

📄 Description

概要

添加独立的provider健康检查接口(有别于web UI管理中provider信息接口),用于系统provider检测
数据源基于providerPoolManager、PROVIDER_POOLS_FILE_PATH

应用场景

通过获取provider状态,结合相关监控、告警系统整合

使用案例

结合Uptime Kuma,实现provider异常告警通知

# 获取所有已启用的provider记录状态
curl  http://host:port/provider_health

# 支持provider, customName过滤记录
curl  http://host:port/provider_health?provider=gemini-antigravity&customName=hello

# 支持unhealthRatioThreshold控制不健康比例的阈值, 当unhealthyRatio超过阈值返回summaryHealth: false
curl  http://host:port/provider_health?unhealthRatioThreshold=0.3

响应样例

{
	"timestamp": "2025-12-21T16:22:51.390Z",
	"items": [
		{
			"customName": "gg",
			"isHealthy": true,
			"lastErrorTime": null,
			"lastErrorMessage": null,
			"identify": "gg::claude-kiro-oauth::./configs/kiro/1766327484403_kiro-auth-token/1766327484403_kiro-auth-token.json",
			"provider": "claude-kiro-oauth"
		},
		{
			"customName": null,
			"isHealthy": true,
			"lastErrorTime": null,
			"lastErrorMessage": null,
			"identify": "NoCustomName::gemini-antigravity::./configs/antigravity/1766329435057_antigravity-credential-1766054214572.json",
			"provider": "gemini-antigravity"
		}
	],
	"count": 2,
	"unhealthyCount": 0,
	"unhealthyRatio": 0,
	"unhealthySummeryMessage": null,
	"summaryHealth": true
}

Provider Health 状态查询接口说明

接口地址

GET /provider_health

请求参数(Query Parameters)

参数名 类型 是否必填 默认值 说明
provider string Provider 标识,用于过滤指定 Provider(如 gemini-antigravity
customName string Provider 实例的自定义名称,用于进一步精确过滤
unhealthRatioThreshold number 0.0001 不健康比例阈值,范围 0 ~ 1,用于判断整体是否健康

响应体结构说明(Response Body)

字段名 类型 说明
timestamp string 统计时间
items array Provider 实例健康状态列表
count number 返回的 Provider 实例总数
unhealthyCount number 不健康实例数量
unhealthyRatio number 不健康实例占比(unhealthyCount / count
unhealthySummeryMessage string | null 不健康汇总说明信息(如触发阈值时的描述)
summaryHealth boolean 根据 unhealthRatioThreshold 计算出的整体健康状态

items 数组字段说明

items 中的每一项表示一个 Provider 实例的健康状态。

字段名 类型 说明
provider string Provider 标识(如 gemini-antigravityclaude-kiro-oauth
customName string | null Provider 实例自定义名称,未设置时为 null
identify string 实例唯一标识,通常由 customName + provider + 配置路径/BaseURL 组合生成
isHealthy boolean 当前实例是否健康
lastErrorTime string | null 最近一次错误发生时间
lastErrorMessage string | null 最近一次错误的详细信息

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/justlovemaki/AIClient-2-API/pull/123 **Author:** [@unihon](https://github.com/unihon) **Created:** 12/22/2025 **Status:** ✅ Merged **Merged:** 12/22/2025 **Merged by:** [@justlovemaki](https://github.com/justlovemaki) **Base:** `main` ← **Head:** `feature/provider-health-api` --- ### 📝 Commits (2) - [`5dc1c5e`](https://github.com/justlovemaki/AIClient-2-API/commit/5dc1c5e5181ea404ddf15a738be8f020909f34b8) feat(usage): 添加provider健康检查接口 - [`f9d8357`](https://github.com/justlovemaki/AIClient-2-API/commit/f9d83571ceb5cbd58b55672eb301f40428bfd3b7) Merge branch 'justlovemaki:main' into feature/provider-health-api ### 📊 Changes **2 files changed** (+128 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/request-handler.js` (+34 -1) 📝 `src/service-manager.js` (+94 -0) </details> ### 📄 Description ## 概要 添加独立的provider健康检查接口(有别于web UI管理中provider信息接口),用于系统provider检测 数据源基于providerPoolManager、PROVIDER_POOLS_FILE_PATH ## 应用场景 通过获取provider状态,结合相关监控、告警系统整合 ## 使用案例 结合[Uptime Kuma](https://github.com/louislam/uptime-kuma),实现provider异常告警通知 ```bash # 获取所有已启用的provider记录状态 curl http://host:port/provider_health # 支持provider, customName过滤记录 curl http://host:port/provider_health?provider=gemini-antigravity&customName=hello # 支持unhealthRatioThreshold控制不健康比例的阈值, 当unhealthyRatio超过阈值返回summaryHealth: false curl http://host:port/provider_health?unhealthRatioThreshold=0.3 ```` ## 响应样例 ```json { "timestamp": "2025-12-21T16:22:51.390Z", "items": [ { "customName": "gg", "isHealthy": true, "lastErrorTime": null, "lastErrorMessage": null, "identify": "gg::claude-kiro-oauth::./configs/kiro/1766327484403_kiro-auth-token/1766327484403_kiro-auth-token.json", "provider": "claude-kiro-oauth" }, { "customName": null, "isHealthy": true, "lastErrorTime": null, "lastErrorMessage": null, "identify": "NoCustomName::gemini-antigravity::./configs/antigravity/1766329435057_antigravity-credential-1766054214572.json", "provider": "gemini-antigravity" } ], "count": 2, "unhealthyCount": 0, "unhealthyRatio": 0, "unhealthySummeryMessage": null, "summaryHealth": true } ``` --- ## Provider Health 状态查询接口说明 ### 接口地址 GET /provider_health ### 请求参数(Query Parameters) | 参数名 | 类型 | 是否必填 | 默认值 | 说明 | |-----|-----|--------|------|------| | provider | string | 否 | 无 | Provider 标识,用于过滤指定 Provider(如 `gemini-antigravity`) | | customName | string | 否 | 无 | Provider 实例的自定义名称,用于进一步精确过滤 | | unhealthRatioThreshold | number | 否 | 0.0001 | 不健康比例阈值,范围 `0 ~ 1`,用于判断整体是否健康 | ### 响应体结构说明(Response Body) | 字段名 | 类型 | 说明 | |------|------|------| | timestamp | string 统计时间 | | items | array | Provider 实例健康状态列表 | | count | number | 返回的 Provider 实例总数 | | unhealthyCount | number | 不健康实例数量 | | unhealthyRatio | number | 不健康实例占比(`unhealthyCount / count`) | | unhealthySummeryMessage | string \| null | 不健康汇总说明信息(如触发阈值时的描述) | | summaryHealth | boolean | 根据 `unhealthRatioThreshold` 计算出的整体健康状态 | --- #### items 数组字段说明 `items` 中的每一项表示一个 Provider 实例的健康状态。 | 字段名 | 类型 | 说明 | |------|------|------| | provider | string | Provider 标识(如 `gemini-antigravity`、`claude-kiro-oauth`) | | customName | string \| null | Provider 实例自定义名称,未设置时为 `null` | | identify | string | 实例唯一标识,通常由 `customName + provider + 配置路径/BaseURL` 组合生成 | | isHealthy | boolean | 当前实例是否健康 | | lastErrorTime | string \| null | 最近一次错误发生时间 | | lastErrorMessage | string \| null | 最近一次错误的详细信息 | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 07:18:45 +03:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/AIClient-2-API-justlovemaki#268
No description provided.