coding-proxy 0.1.4a7__py3-none-any.whl → 0.2.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of coding-proxy might be problematic. Click here for more details.
- coding/proxy/cli/__init__.py +18 -4
- coding/proxy/config/config.default.yaml +209 -1
- coding/proxy/config/routing.py +23 -5
- coding/proxy/config/schema.py +13 -0
- coding/proxy/config/vendors.py +50 -0
- coding/proxy/logging/db.py +12 -8
- coding/proxy/logging/stats.py +55 -3
- coding/proxy/routing/executor.py +5 -0
- coding/proxy/routing/model_mapper.py +5 -0
- coding/proxy/routing/session_manager.py +5 -0
- coding/proxy/server/factory.py +53 -0
- coding/proxy/vendors/alibaba.py +27 -0
- coding/proxy/vendors/doubao.py +27 -0
- coding/proxy/vendors/kimi.py +27 -0
- coding/proxy/vendors/minimax.py +27 -0
- coding/proxy/vendors/native_anthropic.py +270 -0
- coding/proxy/vendors/xiaomi.py +27 -0
- coding/proxy/vendors/zhipu.py +6 -236
- {coding_proxy-0.1.4a7.dist-info → coding_proxy-0.2.0a1.dist-info}/METADATA +1 -1
- {coding_proxy-0.1.4a7.dist-info → coding_proxy-0.2.0a1.dist-info}/RECORD +23 -17
- {coding_proxy-0.1.4a7.dist-info → coding_proxy-0.2.0a1.dist-info}/WHEEL +0 -0
- {coding_proxy-0.1.4a7.dist-info → coding_proxy-0.2.0a1.dist-info}/entry_points.txt +0 -0
- {coding_proxy-0.1.4a7.dist-info → coding_proxy-0.2.0a1.dist-info}/licenses/LICENSE +0 -0
coding/proxy/cli/__init__.py
CHANGED
|
@@ -150,7 +150,9 @@ def usage(
|
|
|
150
150
|
),
|
|
151
151
|
total: bool = typer.Option(False, "--total", "-t", help="统计全部历史记录"),
|
|
152
152
|
vendor: str | None = typer.Option(None, "--vendor", "-v", help="过滤供应商"),
|
|
153
|
-
model: str | None = typer.Option(
|
|
153
|
+
model: str | None = typer.Option(
|
|
154
|
+
None, "--model", help="过滤实际服务模型(model_served),逗号分隔可指定多个"
|
|
155
|
+
),
|
|
154
156
|
db_path: str | None = typer.Option(None, "--db", help="数据库路径"),
|
|
155
157
|
) -> None:
|
|
156
158
|
"""查看 Token 使用统计.
|
|
@@ -166,15 +168,27 @@ def usage(
|
|
|
166
168
|
period, count = _resolve_period(days=days, week=week, month=month, total=total)
|
|
167
169
|
cfg = load_config(Path(db_path) if db_path else None)
|
|
168
170
|
token_logger = TokenLogger(cfg.db_path)
|
|
169
|
-
|
|
171
|
+
# 解析逗号分隔的多 vendor(如 "anthropic,zhipu" → ["anthropic", "zhipu"])
|
|
172
|
+
vendor_filter: str | list[str] | None = None
|
|
173
|
+
if vendor:
|
|
174
|
+
parts = [v.strip() for v in vendor.split(",") if v.strip()]
|
|
175
|
+
vendor_filter = parts[0] if len(parts) == 1 else parts
|
|
176
|
+
# 解析逗号分隔的多 model(如 "glm-5,glm-5.1" → ["glm-5", "glm-5.1"])
|
|
177
|
+
model_filter: str | list[str] | None = None
|
|
178
|
+
if model:
|
|
179
|
+
parts = [m.strip() for m in model.split(",") if m.strip()]
|
|
180
|
+
model_filter = parts[0] if len(parts) == 1 else parts
|
|
181
|
+
asyncio.run(
|
|
182
|
+
_run_usage(token_logger, period, count, vendor_filter, model_filter, cfg)
|
|
183
|
+
)
|
|
170
184
|
|
|
171
185
|
|
|
172
186
|
async def _run_usage(
|
|
173
187
|
token_logger: TokenLogger,
|
|
174
188
|
period: TimePeriod,
|
|
175
189
|
count: int,
|
|
176
|
-
vendor: str | None,
|
|
177
|
-
model: str | None,
|
|
190
|
+
vendor: str | list[str] | None,
|
|
191
|
+
model: str | list[str] | None,
|
|
178
192
|
cfg: ProxyConfig,
|
|
179
193
|
) -> None:
|
|
180
194
|
from ..pricing import PricingTable
|
|
@@ -31,7 +31,7 @@ tiers: ["anthropic", "copilot", "antigravity", "zhipu"]
|
|
|
31
31
|
# === 供应商定义(vendors 列表) ===
|
|
32
32
|
#
|
|
33
33
|
# 每个 vendor 通过 vendor 字段指定供应商类型:
|
|
34
|
-
# anthropic | copilot | antigravity | zhipu
|
|
34
|
+
# anthropic | copilot | antigravity | zhipu | minimax | kimi | doubao | xiaomi | alibaba
|
|
35
35
|
#
|
|
36
36
|
# 优先级规则:
|
|
37
37
|
# - 若配置了 tiers,以其指定的顺序为准
|
|
@@ -116,6 +116,91 @@ vendors:
|
|
|
116
116
|
threshold_percent: 95.0
|
|
117
117
|
probe_interval_seconds: 300
|
|
118
118
|
|
|
119
|
+
# Vendor 4: MiniMax(默认禁用,需手动启用并添加到 tiers)
|
|
120
|
+
- vendor: minimax
|
|
121
|
+
enabled: false
|
|
122
|
+
base_url: "https://api.minimaxi.com/anthropic"
|
|
123
|
+
api_key: "${MINIMAX_API_KEY}"
|
|
124
|
+
timeout_ms: 3000000
|
|
125
|
+
circuit_breaker:
|
|
126
|
+
failure_threshold: 3
|
|
127
|
+
recovery_timeout_seconds: 300
|
|
128
|
+
success_threshold: 2
|
|
129
|
+
quota_guard:
|
|
130
|
+
enabled: true
|
|
131
|
+
token_budget: 1000000000
|
|
132
|
+
window_hours: 24.0
|
|
133
|
+
threshold_percent: 95.0
|
|
134
|
+
probe_interval_seconds: 300
|
|
135
|
+
|
|
136
|
+
# Vendor 5: Kimi(默认禁用)
|
|
137
|
+
- vendor: kimi
|
|
138
|
+
enabled: false
|
|
139
|
+
base_url: "https://api.kimi.com/coding/"
|
|
140
|
+
api_key: "${KIMI_API_KEY}"
|
|
141
|
+
timeout_ms: 3000000
|
|
142
|
+
circuit_breaker:
|
|
143
|
+
failure_threshold: 3
|
|
144
|
+
recovery_timeout_seconds: 300
|
|
145
|
+
success_threshold: 2
|
|
146
|
+
quota_guard:
|
|
147
|
+
enabled: true
|
|
148
|
+
token_budget: 1000000000
|
|
149
|
+
window_hours: 24.0
|
|
150
|
+
threshold_percent: 95.0
|
|
151
|
+
probe_interval_seconds: 300
|
|
152
|
+
|
|
153
|
+
# Vendor 6: 豆包 Doubao(默认禁用)
|
|
154
|
+
- vendor: doubao
|
|
155
|
+
enabled: false
|
|
156
|
+
base_url: "https://ark.cn-beijing.volces.com/api/coding"
|
|
157
|
+
api_key: "${ARK_API_KEY}"
|
|
158
|
+
timeout_ms: 3000000
|
|
159
|
+
circuit_breaker:
|
|
160
|
+
failure_threshold: 3
|
|
161
|
+
recovery_timeout_seconds: 300
|
|
162
|
+
success_threshold: 2
|
|
163
|
+
quota_guard:
|
|
164
|
+
enabled: true
|
|
165
|
+
token_budget: 1000000000
|
|
166
|
+
window_hours: 24.0
|
|
167
|
+
threshold_percent: 95.0
|
|
168
|
+
probe_interval_seconds: 300
|
|
169
|
+
|
|
170
|
+
# Vendor 7: 小米 MiMo(默认禁用)
|
|
171
|
+
- vendor: xiaomi
|
|
172
|
+
enabled: false
|
|
173
|
+
base_url: "https://token-plan-cn.xiaomimimo.com/anthropic"
|
|
174
|
+
api_key: "${XIAOMI_API_KEY}"
|
|
175
|
+
timeout_ms: 3000000
|
|
176
|
+
circuit_breaker:
|
|
177
|
+
failure_threshold: 3
|
|
178
|
+
recovery_timeout_seconds: 300
|
|
179
|
+
success_threshold: 2
|
|
180
|
+
quota_guard:
|
|
181
|
+
enabled: true
|
|
182
|
+
token_budget: 1000000000
|
|
183
|
+
window_hours: 24.0
|
|
184
|
+
threshold_percent: 95.0
|
|
185
|
+
probe_interval_seconds: 300
|
|
186
|
+
|
|
187
|
+
# Vendor 8: 阿里 Qwen(默认禁用)
|
|
188
|
+
- vendor: alibaba
|
|
189
|
+
enabled: false
|
|
190
|
+
base_url: "https://coding-intl.dashscope.aliyuncs.com/apps/anthropic"
|
|
191
|
+
api_key: "${ALIBABA_API_KEY}"
|
|
192
|
+
timeout_ms: 3000000
|
|
193
|
+
circuit_breaker:
|
|
194
|
+
failure_threshold: 3
|
|
195
|
+
recovery_timeout_seconds: 300
|
|
196
|
+
success_threshold: 2
|
|
197
|
+
quota_guard:
|
|
198
|
+
enabled: true
|
|
199
|
+
token_budget: 1000000000
|
|
200
|
+
window_hours: 24.0
|
|
201
|
+
threshold_percent: 95.0
|
|
202
|
+
probe_interval_seconds: 300
|
|
203
|
+
|
|
119
204
|
# === 故障转移触发条件 ===
|
|
120
205
|
failover:
|
|
121
206
|
status_codes: [429, 403, 503, 500, 529]
|
|
@@ -166,6 +251,71 @@ model_mapping:
|
|
|
166
251
|
vendors: ["zhipu"]
|
|
167
252
|
target: "glm-4.5-air"
|
|
168
253
|
is_regex: true
|
|
254
|
+
# MiniMax 模型映射(原生 Anthropic 兼容端点)
|
|
255
|
+
- pattern: "claude-sonnet-.*"
|
|
256
|
+
vendors: ["minimax"]
|
|
257
|
+
target: "minimax-m2.7"
|
|
258
|
+
is_regex: true
|
|
259
|
+
- pattern: "claude-opus-.*"
|
|
260
|
+
vendors: ["minimax"]
|
|
261
|
+
target: "minimax-m2.7"
|
|
262
|
+
is_regex: true
|
|
263
|
+
- pattern: "claude-haiku-.*"
|
|
264
|
+
vendors: ["minimax"]
|
|
265
|
+
target: "minimax-m2.7"
|
|
266
|
+
is_regex: true
|
|
267
|
+
# Kimi 模型映射(原生 Anthropic 兼容端点)
|
|
268
|
+
- pattern: "claude-sonnet-.*"
|
|
269
|
+
vendors: ["kimi"]
|
|
270
|
+
target: "kimi-k2.5"
|
|
271
|
+
is_regex: true
|
|
272
|
+
- pattern: "claude-opus-.*"
|
|
273
|
+
vendors: ["kimi"]
|
|
274
|
+
target: "kimi-k2.5"
|
|
275
|
+
is_regex: true
|
|
276
|
+
- pattern: "claude-haiku-.*"
|
|
277
|
+
vendors: ["kimi"]
|
|
278
|
+
target: "kimi-k2.5"
|
|
279
|
+
is_regex: true
|
|
280
|
+
# 豆包 Doubao 模型映射(三个不同模型对应不同 Claude 模型槽位)
|
|
281
|
+
- pattern: "claude-opus-.*"
|
|
282
|
+
vendors: ["doubao"]
|
|
283
|
+
target: "doubao-seed-2.0-code"
|
|
284
|
+
is_regex: true
|
|
285
|
+
- pattern: "claude-sonnet-.*"
|
|
286
|
+
vendors: ["doubao"]
|
|
287
|
+
target: "doubao-seed-2.0-pro"
|
|
288
|
+
is_regex: true
|
|
289
|
+
- pattern: "claude-haiku-.*"
|
|
290
|
+
vendors: ["doubao"]
|
|
291
|
+
target: "doubao-seed-2.0-lite"
|
|
292
|
+
is_regex: true
|
|
293
|
+
# 小米 MiMo 模型映射(原生 Anthropic 兼容端点)
|
|
294
|
+
- pattern: "claude-sonnet-.*"
|
|
295
|
+
vendors: ["xiaomi"]
|
|
296
|
+
target: "mimo-v2-pro"
|
|
297
|
+
is_regex: true
|
|
298
|
+
- pattern: "claude-opus-.*"
|
|
299
|
+
vendors: ["xiaomi"]
|
|
300
|
+
target: "mimo-v2-pro"
|
|
301
|
+
is_regex: true
|
|
302
|
+
- pattern: "claude-haiku-.*"
|
|
303
|
+
vendors: ["xiaomi"]
|
|
304
|
+
target: "mimo-v2-pro"
|
|
305
|
+
is_regex: true
|
|
306
|
+
# 阿里 Qwen 模型映射(原生 Anthropic 兼容端点)
|
|
307
|
+
- pattern: "claude-sonnet-.*"
|
|
308
|
+
vendors: ["alibaba"]
|
|
309
|
+
target: "qwen3.6-plus"
|
|
310
|
+
is_regex: true
|
|
311
|
+
- pattern: "claude-opus-.*"
|
|
312
|
+
vendors: ["alibaba"]
|
|
313
|
+
target: "qwen3.6-plus"
|
|
314
|
+
is_regex: true
|
|
315
|
+
- pattern: "claude-haiku-.*"
|
|
316
|
+
vendors: ["alibaba"]
|
|
317
|
+
target: "qwen3.6-plus"
|
|
318
|
+
is_regex: true
|
|
169
319
|
|
|
170
320
|
# === 模型定价(USD / 1M tokens) ===
|
|
171
321
|
# vendor: 供应商名称(对应 `usage` 统计表中的"供应商"列)
|
|
@@ -271,6 +421,64 @@ pricing:
|
|
|
271
421
|
input_cost_per_mtok: ¥4.00
|
|
272
422
|
output_cost_per_mtok: ¥18.00
|
|
273
423
|
cache_read_cost_per_mtok: ¥1.00
|
|
424
|
+
# ── MiniMax ──
|
|
425
|
+
- vendor: minimax
|
|
426
|
+
model: minimax-m2.7
|
|
427
|
+
input_cost_per_mtok: ¥2.10
|
|
428
|
+
output_cost_per_mtok: ¥8.40
|
|
429
|
+
cache_write_cost_per_mtok: ¥2.625
|
|
430
|
+
cache_read_cost_per_mtok: ¥0.42
|
|
431
|
+
- vendor: minimax
|
|
432
|
+
model: minimax-m2.5
|
|
433
|
+
input_cost_per_mtok: ¥2.10
|
|
434
|
+
output_cost_per_mtok: ¥8.40
|
|
435
|
+
cache_write_cost_per_mtok: ¥2.625
|
|
436
|
+
cache_read_cost_per_mtok: ¥0.21
|
|
437
|
+
# ── Kimi ──
|
|
438
|
+
- vendor: kimi
|
|
439
|
+
model: kimi-k2.5
|
|
440
|
+
input_cost_per_mtok: $0.60
|
|
441
|
+
output_cost_per_mtok: $3.00
|
|
442
|
+
# ── 豆包 Doubao ──
|
|
443
|
+
- vendor: doubao
|
|
444
|
+
model: doubao-seed-2.0-code
|
|
445
|
+
input_cost_per_mtok: ¥3.20
|
|
446
|
+
output_cost_per_mtok: ¥16.00
|
|
447
|
+
cache_write_cost_per_mtok: ¥0.64
|
|
448
|
+
cache_read_cost_per_mtok: ¥0.017
|
|
449
|
+
- vendor: doubao
|
|
450
|
+
model: doubao-seed-2.0-pro
|
|
451
|
+
input_cost_per_mtok: ¥3.20
|
|
452
|
+
output_cost_per_mtok: ¥16.00
|
|
453
|
+
cache_write_cost_per_mtok: ¥0.64
|
|
454
|
+
cache_read_cost_per_mtok: ¥0.017
|
|
455
|
+
- vendor: doubao
|
|
456
|
+
model: doubao-seed-2.0-lite
|
|
457
|
+
input_cost_per_mtok: ¥0.60
|
|
458
|
+
output_cost_per_mtok: ¥3.60
|
|
459
|
+
cache_write_cost_per_mtok: ¥0.12
|
|
460
|
+
cache_read_cost_per_mtok: ¥0.017
|
|
461
|
+
# ── 小米 MiMo ──
|
|
462
|
+
- vendor: xiaomi
|
|
463
|
+
model: mimo-v2-pro
|
|
464
|
+
input_cost_per_mtok: ¥7.00
|
|
465
|
+
output_cost_per_mtok: ¥21.00
|
|
466
|
+
cache_read_cost_per_mtok: ¥1.40
|
|
467
|
+
- vendor: xiaomi
|
|
468
|
+
model: mimo-v2-omni
|
|
469
|
+
input_cost_per_mtok: ¥2.80
|
|
470
|
+
output_cost_per_mtok: ¥14.00
|
|
471
|
+
cache_read_cost_per_mtok: ¥0.56
|
|
472
|
+
- vendor: xiaomi
|
|
473
|
+
model: mimo-v2-flash
|
|
474
|
+
input_cost_per_mtok: ¥0.70
|
|
475
|
+
output_cost_per_mtok: ¥2.10
|
|
476
|
+
cache_read_cost_per_mtok: ¥0.07
|
|
477
|
+
# ── 阿里 Qwen ──
|
|
478
|
+
- vendor: alibaba
|
|
479
|
+
model: qwen3.6-plus
|
|
480
|
+
input_cost_per_mtok: $0.276
|
|
481
|
+
output_cost_per_mtok: $1.651
|
|
274
482
|
|
|
275
483
|
database:
|
|
276
484
|
path: "~/.coding-proxy/usage.db"
|
coding/proxy/config/routing.py
CHANGED
|
@@ -59,19 +59,36 @@ _ANTIGRAVITY_FIELDS: frozenset[str] = frozenset(
|
|
|
59
59
|
"model_endpoint",
|
|
60
60
|
}
|
|
61
61
|
)
|
|
62
|
-
|
|
62
|
+
_NATIVE_ANTHROPIC_FIELDS: frozenset[str] = frozenset(
|
|
63
63
|
{
|
|
64
64
|
"api_key",
|
|
65
65
|
}
|
|
66
66
|
)
|
|
67
|
+
# 向后兼容别名
|
|
68
|
+
_ZHIPU_FIELDS = _NATIVE_ANTHROPIC_FIELDS
|
|
67
69
|
|
|
68
70
|
_VENDOR_EXCLUSIVE_FIELDS: dict[str, frozenset[str]] = {
|
|
69
71
|
"copilot": _COPILOT_FIELDS,
|
|
70
72
|
"antigravity": _ANTIGRAVITY_FIELDS,
|
|
71
|
-
"zhipu":
|
|
73
|
+
"zhipu": _NATIVE_ANTHROPIC_FIELDS,
|
|
74
|
+
"minimax": _NATIVE_ANTHROPIC_FIELDS,
|
|
75
|
+
"kimi": _NATIVE_ANTHROPIC_FIELDS,
|
|
76
|
+
"doubao": _NATIVE_ANTHROPIC_FIELDS,
|
|
77
|
+
"xiaomi": _NATIVE_ANTHROPIC_FIELDS,
|
|
78
|
+
"alibaba": _NATIVE_ANTHROPIC_FIELDS,
|
|
72
79
|
}
|
|
73
80
|
|
|
74
|
-
VendorType = Literal[
|
|
81
|
+
VendorType = Literal[
|
|
82
|
+
"anthropic",
|
|
83
|
+
"copilot",
|
|
84
|
+
"antigravity",
|
|
85
|
+
"zhipu",
|
|
86
|
+
"minimax",
|
|
87
|
+
"kimi",
|
|
88
|
+
"doubao",
|
|
89
|
+
"xiaomi",
|
|
90
|
+
"alibaba",
|
|
91
|
+
]
|
|
75
92
|
|
|
76
93
|
|
|
77
94
|
class ModelMappingRule(BaseModel):
|
|
@@ -253,10 +270,10 @@ class VendorConfig(BaseModel):
|
|
|
253
270
|
description="[antigravity] Antigravity 模型端点路径",
|
|
254
271
|
)
|
|
255
272
|
|
|
256
|
-
# ──
|
|
273
|
+
# ── 原生 Anthropic 兼容供应商共用字段 ────────────────────────────
|
|
257
274
|
api_key: str = Field(
|
|
258
275
|
default="",
|
|
259
|
-
description="[zhipu]
|
|
276
|
+
description="[zhipu/minimax/kimi/doubao/xiaomi/alibaba] 原生 Anthropic 兼容端点 API Key",
|
|
260
277
|
)
|
|
261
278
|
|
|
262
279
|
# ── 弹性配置 ──────────────────────────────────────────────
|
|
@@ -307,6 +324,7 @@ __all__ = [
|
|
|
307
324
|
"_COPILOT_FIELDS",
|
|
308
325
|
"_ANTIGRAVITY_FIELDS",
|
|
309
326
|
"_ZHIPU_FIELDS",
|
|
327
|
+
"_NATIVE_ANTHROPIC_FIELDS",
|
|
310
328
|
"_VENDOR_EXCLUSIVE_FIELDS",
|
|
311
329
|
"_BACKEND_EXCLUSIVE_FIELDS",
|
|
312
330
|
]
|
coding/proxy/config/schema.py
CHANGED
|
@@ -30,6 +30,7 @@ from .routing import ( # noqa: F401
|
|
|
30
30
|
_ANTIGRAVITY_FIELDS,
|
|
31
31
|
_BACKEND_EXCLUSIVE_FIELDS, # 向后兼容别名
|
|
32
32
|
_COPILOT_FIELDS,
|
|
33
|
+
_NATIVE_ANTHROPIC_FIELDS,
|
|
33
34
|
_VENDOR_EXCLUSIVE_FIELDS,
|
|
34
35
|
_ZHIPU_FIELDS,
|
|
35
36
|
BackendType, # 向后兼容别名
|
|
@@ -43,9 +44,14 @@ from .routing import ( # noqa: F401
|
|
|
43
44
|
# ── 子模块 re-export ────────────────────────────────────────────
|
|
44
45
|
from .server import DatabaseConfig, LoggingConfig, ServerConfig # noqa: F401
|
|
45
46
|
from .vendors import ( # noqa: F401
|
|
47
|
+
AlibabaConfig,
|
|
46
48
|
AnthropicConfig,
|
|
47
49
|
AntigravityConfig,
|
|
48
50
|
CopilotConfig,
|
|
51
|
+
DoubaoConfig,
|
|
52
|
+
KimiConfig,
|
|
53
|
+
MinimaxConfig,
|
|
54
|
+
XiaomiConfig,
|
|
49
55
|
ZhipuConfig,
|
|
50
56
|
)
|
|
51
57
|
|
|
@@ -303,8 +309,15 @@ __all__ = [
|
|
|
303
309
|
"_COPILOT_FIELDS",
|
|
304
310
|
"_ANTIGRAVITY_FIELDS",
|
|
305
311
|
"_ZHIPU_FIELDS",
|
|
312
|
+
"_NATIVE_ANTHROPIC_FIELDS",
|
|
306
313
|
"_VENDOR_EXCLUSIVE_FIELDS",
|
|
307
314
|
"_BACKEND_EXCLUSIVE_FIELDS",
|
|
308
315
|
# auth
|
|
309
316
|
"AuthConfig",
|
|
317
|
+
# new native anthropic vendor configs
|
|
318
|
+
"MinimaxConfig",
|
|
319
|
+
"KimiConfig",
|
|
320
|
+
"DoubaoConfig",
|
|
321
|
+
"XiaomiConfig",
|
|
322
|
+
"AlibabaConfig",
|
|
310
323
|
]
|
coding/proxy/config/vendors.py
CHANGED
|
@@ -49,9 +49,59 @@ class ZhipuConfig(BaseModel):
|
|
|
49
49
|
timeout_ms: int = 3000000
|
|
50
50
|
|
|
51
51
|
|
|
52
|
+
class MinimaxConfig(BaseModel):
|
|
53
|
+
"""MiniMax 供应商配置(原生 Anthropic 兼容端点)."""
|
|
54
|
+
|
|
55
|
+
enabled: bool = True
|
|
56
|
+
base_url: str = "https://api.minimaxi.com/anthropic"
|
|
57
|
+
api_key: str = ""
|
|
58
|
+
timeout_ms: int = 3000000
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class KimiConfig(BaseModel):
|
|
62
|
+
"""Kimi 供应商配置(原生 Anthropic 兼容端点)."""
|
|
63
|
+
|
|
64
|
+
enabled: bool = True
|
|
65
|
+
base_url: str = "https://api.kimi.com/coding/"
|
|
66
|
+
api_key: str = ""
|
|
67
|
+
timeout_ms: int = 3000000
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class DoubaoConfig(BaseModel):
|
|
71
|
+
"""豆包 Doubao 供应商配置(原生 Anthropic 兼容端点)."""
|
|
72
|
+
|
|
73
|
+
enabled: bool = True
|
|
74
|
+
base_url: str = "https://ark.cn-beijing.volces.com/api/coding"
|
|
75
|
+
api_key: str = ""
|
|
76
|
+
timeout_ms: int = 3000000
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class XiaomiConfig(BaseModel):
|
|
80
|
+
"""小米 MiMo 供应商配置(原生 Anthropic 兼容端点)."""
|
|
81
|
+
|
|
82
|
+
enabled: bool = True
|
|
83
|
+
base_url: str = "https://token-plan-cn.xiaomimimo.com/anthropic"
|
|
84
|
+
api_key: str = ""
|
|
85
|
+
timeout_ms: int = 3000000
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class AlibabaConfig(BaseModel):
|
|
89
|
+
"""阿里 Qwen 供应商配置(原生 Anthropic 兼容端点)."""
|
|
90
|
+
|
|
91
|
+
enabled: bool = True
|
|
92
|
+
base_url: str = "https://coding-intl.dashscope.aliyuncs.com/apps/anthropic"
|
|
93
|
+
api_key: str = ""
|
|
94
|
+
timeout_ms: int = 3000000
|
|
95
|
+
|
|
96
|
+
|
|
52
97
|
__all__ = [
|
|
53
98
|
"AnthropicConfig",
|
|
54
99
|
"CopilotConfig",
|
|
55
100
|
"AntigravityConfig",
|
|
56
101
|
"ZhipuConfig",
|
|
102
|
+
"MinimaxConfig",
|
|
103
|
+
"KimiConfig",
|
|
104
|
+
"DoubaoConfig",
|
|
105
|
+
"XiaomiConfig",
|
|
106
|
+
"AlibabaConfig",
|
|
57
107
|
]
|
coding/proxy/logging/db.py
CHANGED
|
@@ -374,8 +374,8 @@ class TokenLogger:
|
|
|
374
374
|
*,
|
|
375
375
|
period: TimePeriod = TimePeriod.DAY,
|
|
376
376
|
count: int = 7,
|
|
377
|
-
vendor: str | None = None,
|
|
378
|
-
model: str | None = None,
|
|
377
|
+
vendor: str | list[str] | None = None,
|
|
378
|
+
model: str | list[str] | None = None,
|
|
379
379
|
) -> list[dict]:
|
|
380
380
|
"""按指定时间维度聚合 Token 使用统计.
|
|
381
381
|
|
|
@@ -383,8 +383,8 @@ class TokenLogger:
|
|
|
383
383
|
period: 时间维度(日/周/月/全量)。
|
|
384
384
|
count: ``period`` 的数量。仅用于计算起始时间边界,
|
|
385
385
|
``TOTAL`` 维度下忽略此参数。
|
|
386
|
-
vendor:
|
|
387
|
-
model:
|
|
386
|
+
vendor: 过滤供应商,支持单个字符串或字符串列表(多 vendor 过滤)。
|
|
387
|
+
model: 过滤实际服务模型(model_served),支持单个字符串或字符串列表。
|
|
388
388
|
"""
|
|
389
389
|
if not self._db:
|
|
390
390
|
return []
|
|
@@ -411,11 +411,15 @@ class TokenLogger:
|
|
|
411
411
|
params.append(start_iso)
|
|
412
412
|
|
|
413
413
|
if vendor:
|
|
414
|
-
|
|
415
|
-
|
|
414
|
+
vendors = [vendor] if isinstance(vendor, str) else vendor
|
|
415
|
+
placeholders = ",".join("?" * len(vendors))
|
|
416
|
+
sql += f" AND vendor IN ({placeholders})"
|
|
417
|
+
params.extend(vendors)
|
|
416
418
|
if model:
|
|
417
|
-
|
|
418
|
-
|
|
419
|
+
models = [model] if isinstance(model, str) else model
|
|
420
|
+
placeholders = ",".join("?" * len(models))
|
|
421
|
+
sql += f" AND model_served IN ({placeholders})"
|
|
422
|
+
params.extend(models)
|
|
419
423
|
|
|
420
424
|
sql += f" GROUP BY {group_clause} ORDER BY {order_clause}"
|
|
421
425
|
|
coding/proxy/logging/stats.py
CHANGED
|
@@ -95,8 +95,8 @@ _PERIOD_DATE_LABELS: dict[TimePeriod, str] = {
|
|
|
95
95
|
async def show_usage(
|
|
96
96
|
logger: TokenLogger,
|
|
97
97
|
*,
|
|
98
|
-
vendor: str | None = None,
|
|
99
|
-
model: str | None = None,
|
|
98
|
+
vendor: str | list[str] | None = None,
|
|
99
|
+
model: str | list[str] | None = None,
|
|
100
100
|
pricing_table: PricingTable | None = None,
|
|
101
101
|
period: TimePeriod = TimePeriod.DAY,
|
|
102
102
|
count: int = 7,
|
|
@@ -126,6 +126,15 @@ async def show_usage(
|
|
|
126
126
|
table.add_column("Cost", justify="right", style="bold green")
|
|
127
127
|
table.add_column("平均耗时(ms)", justify="right")
|
|
128
128
|
|
|
129
|
+
# ── 汇总累计变量 ──────────────────────────────────────────
|
|
130
|
+
sum_requests = 0
|
|
131
|
+
sum_input = 0
|
|
132
|
+
sum_output = 0
|
|
133
|
+
sum_cache_creation = 0
|
|
134
|
+
sum_cache_read = 0
|
|
135
|
+
weighted_duration_sum = 0.0 # Σ(avg_duration_ms × total_requests)
|
|
136
|
+
cost_totals: dict = {} # currency → float
|
|
137
|
+
|
|
129
138
|
for row in rows:
|
|
130
139
|
total_input = row.get("total_input", 0) or 0
|
|
131
140
|
total_output = row.get("total_output", 0) or 0
|
|
@@ -137,6 +146,7 @@ async def show_usage(
|
|
|
137
146
|
|
|
138
147
|
vendor_name = str(row.get("vendor", ""))
|
|
139
148
|
model_served = str(row.get("model_served", ""))
|
|
149
|
+
cost_value = None
|
|
140
150
|
if pricing_table is not None:
|
|
141
151
|
cost_value = pricing_table.compute_cost(
|
|
142
152
|
vendor_name,
|
|
@@ -150,13 +160,27 @@ async def show_usage(
|
|
|
150
160
|
else:
|
|
151
161
|
cost_str = "-"
|
|
152
162
|
|
|
163
|
+
# 累加汇总
|
|
164
|
+
total_requests_row = row.get("total_requests", 0) or 0
|
|
165
|
+
sum_requests += total_requests_row
|
|
166
|
+
sum_input += total_input
|
|
167
|
+
sum_output += total_output
|
|
168
|
+
sum_cache_creation += total_cache_creation
|
|
169
|
+
sum_cache_read += total_cache_read
|
|
170
|
+
weighted_duration_sum += (
|
|
171
|
+
row.get("avg_duration_ms", 0) or 0
|
|
172
|
+
) * total_requests_row
|
|
173
|
+
if cost_value is not None:
|
|
174
|
+
cur = cost_value.currency
|
|
175
|
+
cost_totals[cur] = cost_totals.get(cur, 0.0) + cost_value.amount
|
|
176
|
+
|
|
153
177
|
date_value = row.get("date") or ""
|
|
154
178
|
table.add_row(
|
|
155
179
|
str(date_value),
|
|
156
180
|
vendor_name,
|
|
157
181
|
_format_model_display(row.get("model_requested")),
|
|
158
182
|
model_served,
|
|
159
|
-
str(
|
|
183
|
+
str(total_requests_row),
|
|
160
184
|
_format_tokens(total_input),
|
|
161
185
|
_format_tokens(total_output),
|
|
162
186
|
_format_tokens(total_cache_creation),
|
|
@@ -166,6 +190,34 @@ async def show_usage(
|
|
|
166
190
|
str(int(row.get("avg_duration_ms", 0) or 0)),
|
|
167
191
|
)
|
|
168
192
|
|
|
193
|
+
# ── 汇总行 ───────────────────────────────────────────────
|
|
194
|
+
table.add_section()
|
|
195
|
+
|
|
196
|
+
sum_tokens = sum_input + sum_output + sum_cache_creation + sum_cache_read
|
|
197
|
+
avg_duration = int(weighted_duration_sum / sum_requests) if sum_requests else 0
|
|
198
|
+
|
|
199
|
+
if cost_totals:
|
|
200
|
+
total_cost_str = " + ".join(
|
|
201
|
+
f"{cur.symbol}{amt:.4f}" for cur, amt in cost_totals.items()
|
|
202
|
+
)
|
|
203
|
+
else:
|
|
204
|
+
total_cost_str = "-"
|
|
205
|
+
|
|
206
|
+
table.add_row(
|
|
207
|
+
"[bold]总计[/bold]",
|
|
208
|
+
"",
|
|
209
|
+
"",
|
|
210
|
+
"",
|
|
211
|
+
f"[bold]{sum_requests}[/bold]",
|
|
212
|
+
f"[bold]{_format_tokens(sum_input)}[/bold]",
|
|
213
|
+
f"[bold]{_format_tokens(sum_output)}[/bold]",
|
|
214
|
+
f"[bold]{_format_tokens(sum_cache_creation)}[/bold]",
|
|
215
|
+
f"[bold]{_format_tokens(sum_cache_read)}[/bold]",
|
|
216
|
+
f"[bold]{_format_tokens(sum_tokens)}[/bold]",
|
|
217
|
+
f"[bold]{total_cost_str}[/bold]",
|
|
218
|
+
f"[bold]{avg_duration}[/bold]",
|
|
219
|
+
)
|
|
220
|
+
|
|
169
221
|
console.print(table)
|
|
170
222
|
|
|
171
223
|
# 故障转移来源汇总(使用与主查询相同的时间范围)
|
coding/proxy/routing/executor.py
CHANGED
|
@@ -168,6 +168,11 @@ def _log_vendor_response_error(
|
|
|
168
168
|
_VENDOR_PROTOCOL_LABEL_MAP: dict[str, str] = {
|
|
169
169
|
"anthropic": "Anthropic",
|
|
170
170
|
"zhipu": "Anthropic",
|
|
171
|
+
"minimax": "Anthropic",
|
|
172
|
+
"kimi": "Anthropic",
|
|
173
|
+
"doubao": "Anthropic",
|
|
174
|
+
"xiaomi": "Anthropic",
|
|
175
|
+
"alibaba": "Anthropic",
|
|
171
176
|
"copilot": "OpenAI",
|
|
172
177
|
"antigravity": "Gemini",
|
|
173
178
|
}
|
|
@@ -39,6 +39,11 @@ class RouteSessionManager:
|
|
|
39
39
|
"copilot": "openai_chat_completions",
|
|
40
40
|
"antigravity": "gemini_generate_content",
|
|
41
41
|
"zhipu": "anthropic_messages",
|
|
42
|
+
"minimax": "anthropic_messages",
|
|
43
|
+
"kimi": "anthropic_messages",
|
|
44
|
+
"doubao": "anthropic_messages",
|
|
45
|
+
"xiaomi": "anthropic_messages",
|
|
46
|
+
"alibaba": "anthropic_messages",
|
|
42
47
|
"anthropic": "anthropic_messages",
|
|
43
48
|
}.get(tier.name, "unknown")
|
|
44
49
|
compat_trace = CompatibilityTrace(
|