coding-proxy 0.1.4a8__py3-none-any.whl → 0.2.0a2__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.

@@ -26,12 +26,12 @@ logging:
26
26
  # 示例 3:将 zhipu 提升为首选,anthropic 作为后备
27
27
  # tiers: ["zhipu", "anthropic"]
28
28
 
29
- tiers: ["anthropic", "copilot", "antigravity", "zhipu"]
29
+ tiers: ["zhipu", "anthropic", "copilot", "antigravity"]
30
30
 
31
31
  # === 供应商定义(vendors 列表) ===
32
32
  #
33
33
  # 每个 vendor 通过 vendor 字段指定供应商类型:
34
- # anthropic | copilot | antigravity | zhipu
34
+ # anthropic | zhipu | minimax | alibaba | xiaomi | kimi | doubao | copilot | antigravity
35
35
  #
36
36
  # 优先级规则:
37
37
  # - 若配置了 tiers,以其指定的顺序为准
@@ -101,6 +101,7 @@ vendors:
101
101
 
102
102
  # Vendor 3: 智谱 GLM(终端兜底,无 circuit_breaker)
103
103
  - vendor: zhipu
104
+ enabled: true
104
105
  base_url: "https://open.bigmodel.cn/api/anthropic"
105
106
  api_key: "${ZHIPU_API_KEY}"
106
107
  timeout_ms: 3000000
@@ -116,6 +117,91 @@ vendors:
116
117
  threshold_percent: 95.0
117
118
  probe_interval_seconds: 300
118
119
 
120
+ # Vendor 4: MiniMax(默认禁用,需手动启用并添加到 tiers)
121
+ - vendor: minimax
122
+ enabled: false
123
+ base_url: "https://api.minimaxi.com/anthropic"
124
+ api_key: "${MINIMAX_API_KEY}"
125
+ timeout_ms: 3000000
126
+ circuit_breaker:
127
+ failure_threshold: 3
128
+ recovery_timeout_seconds: 300
129
+ success_threshold: 2
130
+ quota_guard:
131
+ enabled: false
132
+ token_budget: 1000000000
133
+ window_hours: 24.0
134
+ threshold_percent: 95.0
135
+ probe_interval_seconds: 300
136
+
137
+ # Vendor 5: 阿里 Qwen(默认禁用)
138
+ - vendor: alibaba
139
+ enabled: false
140
+ base_url: "https://coding-intl.dashscope.aliyuncs.com/apps/anthropic"
141
+ api_key: "${ALIBABA_API_KEY}"
142
+ timeout_ms: 3000000
143
+ circuit_breaker:
144
+ failure_threshold: 3
145
+ recovery_timeout_seconds: 300
146
+ success_threshold: 2
147
+ quota_guard:
148
+ enabled: false
149
+ token_budget: 1000000000
150
+ window_hours: 24.0
151
+ threshold_percent: 95.0
152
+ probe_interval_seconds: 300
153
+
154
+ # Vendor 6: 小米 MiMo(默认禁用)
155
+ - vendor: xiaomi
156
+ enabled: false
157
+ base_url: "https://token-plan-cn.xiaomimimo.com/anthropic"
158
+ api_key: "${XIAOMI_API_KEY}"
159
+ timeout_ms: 3000000
160
+ circuit_breaker:
161
+ failure_threshold: 3
162
+ recovery_timeout_seconds: 300
163
+ success_threshold: 2
164
+ quota_guard:
165
+ enabled: false
166
+ token_budget: 1000000000
167
+ window_hours: 24.0
168
+ threshold_percent: 95.0
169
+ probe_interval_seconds: 300
170
+
171
+ # Vendor 7: Kimi(默认禁用)
172
+ - vendor: kimi
173
+ enabled: false
174
+ base_url: "https://api.kimi.com/coding/"
175
+ api_key: "${KIMI_API_KEY}"
176
+ timeout_ms: 3000000
177
+ circuit_breaker:
178
+ failure_threshold: 3
179
+ recovery_timeout_seconds: 300
180
+ success_threshold: 2
181
+ quota_guard:
182
+ enabled: false
183
+ token_budget: 1000000000
184
+ window_hours: 24.0
185
+ threshold_percent: 95.0
186
+ probe_interval_seconds: 300
187
+
188
+ # Vendor 8: 豆包 Doubao(默认禁用)
189
+ - vendor: doubao
190
+ enabled: false
191
+ base_url: "https://ark.cn-beijing.volces.com/api/coding"
192
+ api_key: "${ARK_API_KEY}"
193
+ timeout_ms: 3000000
194
+ circuit_breaker:
195
+ failure_threshold: 3
196
+ recovery_timeout_seconds: 300
197
+ success_threshold: 2
198
+ quota_guard:
199
+ enabled: false
200
+ token_budget: 1000000000
201
+ window_hours: 24.0
202
+ threshold_percent: 95.0
203
+ probe_interval_seconds: 300
204
+
119
205
  # === 故障转移触发条件 ===
120
206
  failover:
121
207
  status_codes: [429, 403, 503, 500, 529]
@@ -166,6 +252,71 @@ model_mapping:
166
252
  vendors: ["zhipu"]
167
253
  target: "glm-4.5-air"
168
254
  is_regex: true
255
+ # MiniMax 模型映射(原生 Anthropic 兼容端点)
256
+ - pattern: "claude-sonnet-.*"
257
+ vendors: ["minimax"]
258
+ target: "minimax-m2.7"
259
+ is_regex: true
260
+ - pattern: "claude-opus-.*"
261
+ vendors: ["minimax"]
262
+ target: "minimax-m2.7"
263
+ is_regex: true
264
+ - pattern: "claude-haiku-.*"
265
+ vendors: ["minimax"]
266
+ target: "minimax-m2.7"
267
+ is_regex: true
268
+ # 阿里 Qwen 模型映射(原生 Anthropic 兼容端点)
269
+ - pattern: "claude-sonnet-.*"
270
+ vendors: ["alibaba"]
271
+ target: "qwen3.6-plus"
272
+ is_regex: true
273
+ - pattern: "claude-opus-.*"
274
+ vendors: ["alibaba"]
275
+ target: "qwen3.6-plus"
276
+ is_regex: true
277
+ - pattern: "claude-haiku-.*"
278
+ vendors: ["alibaba"]
279
+ target: "qwen3.6-plus"
280
+ is_regex: true
281
+ # 小米 MiMo 模型映射(原生 Anthropic 兼容端点)
282
+ - pattern: "claude-sonnet-.*"
283
+ vendors: ["xiaomi"]
284
+ target: "mimo-v2-pro"
285
+ is_regex: true
286
+ - pattern: "claude-opus-.*"
287
+ vendors: ["xiaomi"]
288
+ target: "mimo-v2-pro"
289
+ is_regex: true
290
+ - pattern: "claude-haiku-.*"
291
+ vendors: ["xiaomi"]
292
+ target: "mimo-v2-pro"
293
+ is_regex: true
294
+ # Kimi 模型映射(原生 Anthropic 兼容端点)
295
+ - pattern: "claude-sonnet-.*"
296
+ vendors: ["kimi"]
297
+ target: "kimi-k2.5"
298
+ is_regex: true
299
+ - pattern: "claude-opus-.*"
300
+ vendors: ["kimi"]
301
+ target: "kimi-k2.5"
302
+ is_regex: true
303
+ - pattern: "claude-haiku-.*"
304
+ vendors: ["kimi"]
305
+ target: "kimi-k2.5"
306
+ is_regex: true
307
+ # 豆包 Doubao 模型映射(三个不同模型对应不同 Claude 模型槽位)
308
+ - pattern: "claude-opus-.*"
309
+ vendors: ["doubao"]
310
+ target: "doubao-seed-2.0-code"
311
+ is_regex: true
312
+ - pattern: "claude-sonnet-.*"
313
+ vendors: ["doubao"]
314
+ target: "doubao-seed-2.0-pro"
315
+ is_regex: true
316
+ - pattern: "claude-haiku-.*"
317
+ vendors: ["doubao"]
318
+ target: "doubao-seed-2.0-lite"
319
+ is_regex: true
169
320
 
170
321
  # === 模型定价(USD / 1M tokens) ===
171
322
  # vendor: 供应商名称(对应 `usage` 统计表中的"供应商"列)
@@ -271,6 +422,64 @@ pricing:
271
422
  input_cost_per_mtok: ¥4.00
272
423
  output_cost_per_mtok: ¥18.00
273
424
  cache_read_cost_per_mtok: ¥1.00
425
+ # ── MiniMax ──
426
+ - vendor: minimax
427
+ model: minimax-m2.7
428
+ input_cost_per_mtok: ¥2.10
429
+ output_cost_per_mtok: ¥8.40
430
+ cache_write_cost_per_mtok: ¥2.625
431
+ cache_read_cost_per_mtok: ¥0.42
432
+ - vendor: minimax
433
+ model: minimax-m2.5
434
+ input_cost_per_mtok: ¥2.10
435
+ output_cost_per_mtok: ¥8.40
436
+ cache_write_cost_per_mtok: ¥2.625
437
+ cache_read_cost_per_mtok: ¥0.21
438
+ # ── 阿里 Qwen ──
439
+ - vendor: alibaba
440
+ model: qwen3.6-plus
441
+ input_cost_per_mtok: $0.276
442
+ output_cost_per_mtok: $1.651
443
+ # ── 小米 MiMo ──
444
+ - vendor: xiaomi
445
+ model: mimo-v2-pro
446
+ input_cost_per_mtok: ¥7.00
447
+ output_cost_per_mtok: ¥21.00
448
+ cache_read_cost_per_mtok: ¥1.40
449
+ - vendor: xiaomi
450
+ model: mimo-v2-omni
451
+ input_cost_per_mtok: ¥2.80
452
+ output_cost_per_mtok: ¥14.00
453
+ cache_read_cost_per_mtok: ¥0.56
454
+ - vendor: xiaomi
455
+ model: mimo-v2-flash
456
+ input_cost_per_mtok: ¥0.70
457
+ output_cost_per_mtok: ¥2.10
458
+ cache_read_cost_per_mtok: ¥0.07
459
+ # ── Kimi ──
460
+ - vendor: kimi
461
+ model: kimi-k2.5
462
+ input_cost_per_mtok: $0.60
463
+ output_cost_per_mtok: $3.00
464
+ # ── 豆包 Doubao ──
465
+ - vendor: doubao
466
+ model: doubao-seed-2.0-code
467
+ input_cost_per_mtok: ¥3.20
468
+ output_cost_per_mtok: ¥16.00
469
+ cache_write_cost_per_mtok: ¥0.64
470
+ cache_read_cost_per_mtok: ¥0.017
471
+ - vendor: doubao
472
+ model: doubao-seed-2.0-pro
473
+ input_cost_per_mtok: ¥3.20
474
+ output_cost_per_mtok: ¥16.00
475
+ cache_write_cost_per_mtok: ¥0.64
476
+ cache_read_cost_per_mtok: ¥0.017
477
+ - vendor: doubao
478
+ model: doubao-seed-2.0-lite
479
+ input_cost_per_mtok: ¥0.60
480
+ output_cost_per_mtok: ¥3.60
481
+ cache_write_cost_per_mtok: ¥0.12
482
+ cache_read_cost_per_mtok: ¥0.017
274
483
 
275
484
  database:
276
485
  path: "~/.coding-proxy/usage.db"
@@ -59,19 +59,36 @@ _ANTIGRAVITY_FIELDS: frozenset[str] = frozenset(
59
59
  "model_endpoint",
60
60
  }
61
61
  )
62
- _ZHIPU_FIELDS: frozenset[str] = frozenset(
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": _ZHIPU_FIELDS,
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["anthropic", "copilot", "antigravity", "zhipu"]
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
- # ── Zhipu 专属字段 ────────────────────────────────────────────
273
+ # ── 原生 Anthropic 兼容供应商共用字段 ────────────────────────────
257
274
  api_key: str = Field(
258
275
  default="",
259
- description="[zhipu] 智谱 GLM API Key",
276
+ description="[zhipu/minimax/kimi/doubao/xiaomi/alibaba] 原生 Anthropic 兼容端点 API Key",
260
277
  )
261
278
 
262
279
  # ── 弹性配置 ──────────────────────────────────────────────
@@ -278,6 +295,8 @@ class VendorConfig(BaseModel):
278
295
  if vendor_type == self.vendor:
279
296
  continue
280
297
  for field_name in fields:
298
+ if field_name in exclusive:
299
+ continue
281
300
  value = getattr(self, field_name, None)
282
301
  if value and value != getattr(
283
302
  VendorConfig.model_fields[field_name], "default", None
@@ -307,6 +326,7 @@ __all__ = [
307
326
  "_COPILOT_FIELDS",
308
327
  "_ANTIGRAVITY_FIELDS",
309
328
  "_ZHIPU_FIELDS",
329
+ "_NATIVE_ANTHROPIC_FIELDS",
310
330
  "_VENDOR_EXCLUSIVE_FIELDS",
311
331
  "_BACKEND_EXCLUSIVE_FIELDS",
312
332
  ]
@@ -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
  ]
@@ -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
  ]
@@ -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
  }
@@ -16,6 +16,11 @@ _VENDOR_ALIASES = {
16
16
  "fallback": "fallback",
17
17
  "antigravity": "antigravity",
18
18
  "copilot": "copilot",
19
+ "minimax": "minimax",
20
+ "kimi": "kimi",
21
+ "doubao": "doubao",
22
+ "xiaomi": "xiaomi",
23
+ "alibaba": "alibaba",
19
24
  }
20
25
 
21
26
 
@@ -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(
@@ -19,23 +19,33 @@ from ..auth.providers.google import (
19
19
  )
20
20
  from ..auth.store import TokenStoreManager
21
21
  from ..config.schema import (
22
+ AlibabaConfig,
22
23
  AnthropicConfig,
23
24
  AntigravityConfig,
24
25
  CircuitBreakerConfig,
25
26
  CopilotConfig,
27
+ DoubaoConfig,
26
28
  FailoverConfig,
29
+ KimiConfig,
30
+ MinimaxConfig,
27
31
  QuotaGuardConfig,
28
32
  TierConfig,
33
+ XiaomiConfig,
29
34
  ZhipuConfig,
30
35
  )
31
36
  from ..routing.circuit_breaker import CircuitBreaker
32
37
  from ..routing.model_mapper import ModelMapper
33
38
  from ..routing.quota_guard import QuotaGuard
34
39
  from ..routing.tier import VendorTier
40
+ from ..vendors.alibaba import AlibabaVendor
35
41
  from ..vendors.anthropic import AnthropicVendor
36
42
  from ..vendors.antigravity import AntigravityVendor
37
43
  from ..vendors.base import BaseVendor
38
44
  from ..vendors.copilot import CopilotVendor
45
+ from ..vendors.doubao import DoubaoVendor
46
+ from ..vendors.kimi import KimiVendor
47
+ from ..vendors.minimax import MinimaxVendor
48
+ from ..vendors.xiaomi import XiaomiVendor
39
49
  from ..vendors.zhipu import ZhipuVendor
40
50
 
41
51
  # 向后兼容别名
@@ -151,6 +161,49 @@ def _create_vendor_from_config(
151
161
  timeout_ms=vendor_cfg.timeout_ms,
152
162
  )
153
163
  return ZhipuVendor(cfg, mapper, failover_cfg)
164
+ case "minimax":
165
+ cfg = MinimaxConfig(
166
+ enabled=vendor_cfg.enabled,
167
+ base_url=vendor_cfg.base_url or "https://api.minimaxi.com/anthropic",
168
+ api_key=vendor_cfg.api_key,
169
+ timeout_ms=vendor_cfg.timeout_ms,
170
+ )
171
+ return MinimaxVendor(cfg, mapper, failover_cfg)
172
+ case "kimi":
173
+ cfg = KimiConfig(
174
+ enabled=vendor_cfg.enabled,
175
+ base_url=vendor_cfg.base_url or "https://api.kimi.com/coding/",
176
+ api_key=vendor_cfg.api_key,
177
+ timeout_ms=vendor_cfg.timeout_ms,
178
+ )
179
+ return KimiVendor(cfg, mapper, failover_cfg)
180
+ case "doubao":
181
+ cfg = DoubaoConfig(
182
+ enabled=vendor_cfg.enabled,
183
+ base_url=vendor_cfg.base_url
184
+ or "https://ark.cn-beijing.volces.com/api/coding",
185
+ api_key=vendor_cfg.api_key,
186
+ timeout_ms=vendor_cfg.timeout_ms,
187
+ )
188
+ return DoubaoVendor(cfg, mapper, failover_cfg)
189
+ case "xiaomi":
190
+ cfg = XiaomiConfig(
191
+ enabled=vendor_cfg.enabled,
192
+ base_url=vendor_cfg.base_url
193
+ or "https://token-plan-cn.xiaomimimo.com/anthropic",
194
+ api_key=vendor_cfg.api_key,
195
+ timeout_ms=vendor_cfg.timeout_ms,
196
+ )
197
+ return XiaomiVendor(cfg, mapper, failover_cfg)
198
+ case "alibaba":
199
+ cfg = AlibabaConfig(
200
+ enabled=vendor_cfg.enabled,
201
+ base_url=vendor_cfg.base_url
202
+ or "https://coding-intl.dashscope.aliyuncs.com/apps/anthropic",
203
+ api_key=vendor_cfg.api_key,
204
+ timeout_ms=vendor_cfg.timeout_ms,
205
+ )
206
+ return AlibabaVendor(cfg, mapper, failover_cfg)
154
207
  case _:
155
208
  raise ValueError(f"未知的 vendor 类型: {vendor_cfg.vendor!r}")
156
209
 
@@ -0,0 +1,27 @@
1
+ """阿里 Qwen 供应商 — 原生 Anthropic 兼容端点薄透传代理.
2
+
3
+ 端点 (https://coding-intl.dashscope.aliyuncs.com/apps/anthropic) 已完整支持
4
+ Anthropic Messages API 协议,仅做模型名映射和认证头替换。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from ..config.schema import FailoverConfig
10
+ from ..config.vendors import AlibabaConfig
11
+ from ..routing.model_mapper import ModelMapper
12
+ from .native_anthropic import NativeAnthropicVendor
13
+
14
+
15
+ class AlibabaVendor(NativeAnthropicVendor):
16
+ """阿里 Qwen 原生 Anthropic 兼容端点供应商(薄透传)."""
17
+
18
+ _vendor_name = "alibaba"
19
+ _display_name = "Alibaba"
20
+
21
+ def __init__(
22
+ self,
23
+ config: AlibabaConfig,
24
+ model_mapper: ModelMapper,
25
+ failover_config: FailoverConfig | None = None,
26
+ ) -> None:
27
+ super().__init__(config, model_mapper, failover_config)
@@ -0,0 +1,27 @@
1
+ """豆包 Doubao 供应商 — 原生 Anthropic 兼容端点薄透传代理.
2
+
3
+ 端点 (https://ark.cn-beijing.volces.com/api/coding) 已完整支持
4
+ Anthropic Messages API 协议,仅做模型名映射和认证头替换。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from ..config.schema import FailoverConfig
10
+ from ..config.vendors import DoubaoConfig
11
+ from ..routing.model_mapper import ModelMapper
12
+ from .native_anthropic import NativeAnthropicVendor
13
+
14
+
15
+ class DoubaoVendor(NativeAnthropicVendor):
16
+ """豆包 Doubao 原生 Anthropic 兼容端点供应商(薄透传)."""
17
+
18
+ _vendor_name = "doubao"
19
+ _display_name = "Doubao"
20
+
21
+ def __init__(
22
+ self,
23
+ config: DoubaoConfig,
24
+ model_mapper: ModelMapper,
25
+ failover_config: FailoverConfig | None = None,
26
+ ) -> None:
27
+ super().__init__(config, model_mapper, failover_config)
@@ -0,0 +1,27 @@
1
+ """Kimi 供应商 — 原生 Anthropic 兼容端点薄透传代理.
2
+
3
+ 端点 (https://api.kimi.com/coding/) 已完整支持
4
+ Anthropic Messages API 协议,仅做模型名映射和认证头替换。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from ..config.schema import FailoverConfig
10
+ from ..config.vendors import KimiConfig
11
+ from ..routing.model_mapper import ModelMapper
12
+ from .native_anthropic import NativeAnthropicVendor
13
+
14
+
15
+ class KimiVendor(NativeAnthropicVendor):
16
+ """Kimi 原生 Anthropic 兼容端点供应商(薄透传)."""
17
+
18
+ _vendor_name = "kimi"
19
+ _display_name = "Kimi"
20
+
21
+ def __init__(
22
+ self,
23
+ config: KimiConfig,
24
+ model_mapper: ModelMapper,
25
+ failover_config: FailoverConfig | None = None,
26
+ ) -> None:
27
+ super().__init__(config, model_mapper, failover_config)
@@ -0,0 +1,27 @@
1
+ """MiniMax 供应商 — 原生 Anthropic 兼容端点薄透传代理.
2
+
3
+ 端点 (https://api.minimaxi.com/anthropic) 已完整支持
4
+ Anthropic Messages API 协议,仅做模型名映射和认证头替换。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from ..config.schema import FailoverConfig
10
+ from ..config.vendors import MinimaxConfig
11
+ from ..routing.model_mapper import ModelMapper
12
+ from .native_anthropic import NativeAnthropicVendor
13
+
14
+
15
+ class MinimaxVendor(NativeAnthropicVendor):
16
+ """MiniMax 原生 Anthropic 兼容端点供应商(薄透传)."""
17
+
18
+ _vendor_name = "minimax"
19
+ _display_name = "MiniMax"
20
+
21
+ def __init__(
22
+ self,
23
+ config: MinimaxConfig,
24
+ model_mapper: ModelMapper,
25
+ failover_config: FailoverConfig | None = None,
26
+ ) -> None:
27
+ super().__init__(config, model_mapper, failover_config)
@@ -0,0 +1,270 @@
1
+ """原生 Anthropic 兼容端点薄透传代理 — 公共基类.
2
+
3
+ 适用于所有仅需 模型名映射 + x-api-key 认证头替换 的供应商
4
+ (如智谱、MiniMax、Kimi、Doubao、Xiaomi、Alibaba 等)。
5
+
6
+ 端点已完整支持 Anthropic Messages API 协议,本模块仅做两项最小适配:
7
+ 1. 模型名映射(Claude -> 供应商模型)
8
+ 2. 认证头替换(x-api-key)
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import copy
14
+ import json
15
+ import logging
16
+ from collections.abc import AsyncIterator
17
+ from typing import Any
18
+
19
+ import httpx
20
+
21
+ from ..config.schema import FailoverConfig
22
+ from ..routing.model_mapper import ModelMapper
23
+ from .base import (
24
+ PROXY_SKIP_HEADERS,
25
+ BaseVendor,
26
+ VendorCapabilities,
27
+ VendorResponse,
28
+ )
29
+
30
+ logger = logging.getLogger(__name__)
31
+
32
+
33
+ class NativeAnthropicVendor(BaseVendor):
34
+ """原生 Anthropic 兼容端点薄透传代理基类.
35
+
36
+ 所有子类行为一致:
37
+ 1. 模型名映射(Claude → 供应商模型)
38
+ 2. 认证头替换(x-api-key)
39
+ 3. 401 错误归一化
40
+ 4. 能力声明全部为 NATIVE
41
+
42
+ 子类需覆写 ``_vendor_name`` 和 ``_display_name`` 类属性。
43
+ """
44
+
45
+ # ── 子类需覆写的类属性 ──────────────────────────────────
46
+ _vendor_name: str = "" # get_name() 返回值 & ModelMapper vendor 参数
47
+ _display_name: str = "" # 错误消息中的显示名(如 "Zhipu"、"MiniMax")
48
+
49
+ def __init__(
50
+ self,
51
+ config: Any,
52
+ model_mapper: ModelMapper,
53
+ failover_config: FailoverConfig | None = None,
54
+ ) -> None:
55
+ super().__init__(
56
+ config.base_url, config.timeout_ms, failover_config=failover_config
57
+ )
58
+ self._api_key = config.api_key
59
+ self._model_mapper = model_mapper
60
+
61
+ def get_name(self) -> str:
62
+ return self._vendor_name
63
+
64
+ def get_capabilities(self) -> VendorCapabilities:
65
+ return VendorCapabilities(
66
+ supports_tools=True,
67
+ supports_thinking=True,
68
+ supports_images=True,
69
+ emits_vendor_tool_events=False,
70
+ supports_metadata=True,
71
+ )
72
+
73
+ def get_compatibility_profile(self):
74
+ from ..compat.canonical import CompatibilityProfile, CompatibilityStatus
75
+
76
+ return CompatibilityProfile(
77
+ thinking=CompatibilityStatus.NATIVE,
78
+ tool_calling=CompatibilityStatus.NATIVE,
79
+ tool_streaming=CompatibilityStatus.NATIVE,
80
+ mcp_tools=CompatibilityStatus.NATIVE,
81
+ images=CompatibilityStatus.NATIVE,
82
+ metadata=CompatibilityStatus.NATIVE,
83
+ json_output=CompatibilityStatus.NATIVE,
84
+ usage_tokens=CompatibilityStatus.NATIVE,
85
+ )
86
+
87
+ def map_model(self, model: str) -> str:
88
+ """将 Claude 模型名映射为供应商模型名,完全委托 ModelMapper."""
89
+ return self._model_mapper.map(model, vendor=self._vendor_name)
90
+
91
+ async def _prepare_request(
92
+ self,
93
+ request_body: dict[str, Any],
94
+ headers: dict[str, str],
95
+ ) -> tuple[dict[str, Any], dict[str, str]]:
96
+ """深拷贝请求体、映射模型名、替换认证头.
97
+
98
+ 其余字段(tools, thinking, metadata, system 等)原样透传。
99
+ """
100
+ body = copy.deepcopy(request_body)
101
+
102
+ if "model" in body:
103
+ body["model"] = self.map_model(body["model"])
104
+
105
+ # 剥离原始认证头(authorization / x-api-key),由下方 new_headers 重建
106
+ filtered = {
107
+ k: v
108
+ for k, v in headers.items()
109
+ if k.lower() not in PROXY_SKIP_HEADERS
110
+ and k.lower() not in ("x-api-key", "authorization")
111
+ }
112
+ new_headers = {
113
+ "content-type": "application/json",
114
+ "x-api-key": self._api_key,
115
+ "anthropic-version": headers.get("anthropic-version", "2023-06-01"),
116
+ }
117
+ for key, value in filtered.items():
118
+ if key.lower() not in {item.lower() for item in new_headers}:
119
+ new_headers[key] = value
120
+ return body, new_headers
121
+
122
+ # ── 响应处理钩子 ──────────────────────────────────────
123
+
124
+ async def send_message(
125
+ self,
126
+ request_body: dict[str, Any],
127
+ headers: dict[str, str],
128
+ ) -> VendorResponse:
129
+ """最小化覆写:API key 缺失时快速返回 401 响应,其余委托基类(含 _normalize_error_response 钩子)."""
130
+ if not self._api_key:
131
+ raw = json.dumps(
132
+ self._missing_api_key_payload(), ensure_ascii=False
133
+ ).encode()
134
+ return VendorResponse(
135
+ status_code=401,
136
+ raw_body=raw,
137
+ error_type="authentication_error",
138
+ error_message=f"{self._display_name} API key 未配置,无法访问 Claude 兼容端点",
139
+ response_headers={"content-type": "application/json"},
140
+ )
141
+ return await super().send_message(request_body, headers)
142
+
143
+ def _normalize_error_response(
144
+ self,
145
+ status_code: int,
146
+ response: httpx.Response,
147
+ backend_resp: VendorResponse,
148
+ ) -> VendorResponse:
149
+ """仅对 401 错误执行归一化,其余状态码透传."""
150
+ if status_code != 401:
151
+ return backend_resp
152
+ raw_body, payload = self._normalize_backend_error(
153
+ status_code,
154
+ response.content if response else backend_resp.raw_body,
155
+ )
156
+ error = payload.get("error", {}) if isinstance(payload, dict) else {}
157
+ return VendorResponse(
158
+ status_code=status_code,
159
+ raw_body=raw_body,
160
+ error_type=error.get("type")
161
+ if isinstance(error, dict)
162
+ else "authentication_error",
163
+ error_message=error.get("message")
164
+ if isinstance(error, dict)
165
+ else f"{self._display_name} API 认证失败",
166
+ response_headers=backend_resp.response_headers,
167
+ usage=backend_resp.usage,
168
+ model_served=backend_resp.model_served,
169
+ )
170
+
171
+ # ── 流式 401 归一化包装 ───────────────────────────────
172
+
173
+ async def send_message_stream(
174
+ self,
175
+ request_body: dict[str, Any],
176
+ headers: dict[str, str],
177
+ ) -> AsyncIterator[bytes]:
178
+ """轻量包装:API key 缺失时快速失败,否则委托基类流式发送并捕获 401 归一化."""
179
+ if not self._api_key:
180
+ payload = self._missing_api_key_payload()
181
+ raw = json.dumps(payload, ensure_ascii=False).encode()
182
+ request = httpx.Request("POST", f"{self._base_url}{self._get_endpoint()}")
183
+ raise httpx.HTTPStatusError(
184
+ f"{self._vendor_name} API error: 401",
185
+ request=request,
186
+ response=httpx.Response(
187
+ 401,
188
+ content=raw,
189
+ headers={"content-type": "application/json"},
190
+ request=request,
191
+ ),
192
+ )
193
+ try:
194
+ async for chunk in super().send_message_stream(request_body, headers):
195
+ yield chunk
196
+ except httpx.HTTPStatusError as exc:
197
+ response = exc.response
198
+ if response is not None and response.status_code == 401:
199
+ raw_body = response.content or b"{}"
200
+ normalized_raw, _ = self._normalize_backend_error(
201
+ response.status_code,
202
+ raw_body,
203
+ )
204
+ raise httpx.HTTPStatusError(
205
+ str(exc),
206
+ request=exc.request,
207
+ response=httpx.Response(
208
+ response.status_code,
209
+ content=normalized_raw,
210
+ headers=dict(response.headers),
211
+ request=exc.request,
212
+ ),
213
+ ) from exc
214
+ raise
215
+
216
+ # ── 401 错误归一化工具方法 ────────────────────────────
217
+
218
+ def _normalize_auth_error_payload(
219
+ self, payload: dict[str, Any] | None
220
+ ) -> dict[str, Any]:
221
+ default_msg = (
222
+ f"{self._display_name} API 认证失败,请检查 api_key 或兼容端点权限"
223
+ )
224
+ if not isinstance(payload, dict):
225
+ return {
226
+ "error": {
227
+ "type": "authentication_error",
228
+ "message": default_msg,
229
+ }
230
+ }
231
+ error = payload.get("error")
232
+ if not isinstance(error, dict):
233
+ payload["error"] = {
234
+ "type": "authentication_error",
235
+ "message": default_msg,
236
+ }
237
+ return payload
238
+ payload["error"] = {
239
+ **error,
240
+ "type": "authentication_error",
241
+ "message": str(error.get("message") or default_msg),
242
+ }
243
+ return payload
244
+
245
+ def _missing_api_key_payload(self) -> dict[str, Any]:
246
+ return {
247
+ "error": {
248
+ "type": "authentication_error",
249
+ "message": f"{self._display_name} API key 未配置,无法访问 Claude 兼容端点",
250
+ }
251
+ }
252
+
253
+ def _normalize_backend_error(
254
+ self,
255
+ status_code: int,
256
+ raw_body: bytes,
257
+ ) -> tuple[bytes, dict[str, Any] | None]:
258
+ payload: dict[str, Any] | None = None
259
+ if raw_body:
260
+ try:
261
+ decoded = json.loads(raw_body)
262
+ if isinstance(decoded, dict):
263
+ payload = decoded
264
+ except (json.JSONDecodeError, UnicodeDecodeError, TypeError):
265
+ payload = None
266
+ if status_code != 401:
267
+ return raw_body, payload
268
+ payload = self._normalize_auth_error_payload(payload)
269
+ body = copy.deepcopy(payload)
270
+ return json.dumps(body, ensure_ascii=False).encode(), body
@@ -0,0 +1,27 @@
1
+ """小米 MiMo 供应商 — 原生 Anthropic 兼容端点薄透传代理.
2
+
3
+ 端点 (https://token-plan-cn.xiaomimimo.com/anthropic) 已完整支持
4
+ Anthropic Messages API 协议,仅做模型名映射和认证头替换。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from ..config.schema import FailoverConfig
10
+ from ..config.vendors import XiaomiConfig
11
+ from ..routing.model_mapper import ModelMapper
12
+ from .native_anthropic import NativeAnthropicVendor
13
+
14
+
15
+ class XiaomiVendor(NativeAnthropicVendor):
16
+ """小米 MiMo 原生 Anthropic 兼容端点供应商(薄透传)."""
17
+
18
+ _vendor_name = "xiaomi"
19
+ _display_name = "Xiaomi"
20
+
21
+ def __init__(
22
+ self,
23
+ config: XiaomiConfig,
24
+ model_mapper: ModelMapper,
25
+ failover_config: FailoverConfig | None = None,
26
+ ) -> None:
27
+ super().__init__(config, model_mapper, failover_config)
@@ -8,258 +8,28 @@ Anthropic Messages API 协议,本模块仅做两项最小适配:
8
8
 
9
9
  from __future__ import annotations
10
10
 
11
- import copy
12
- import json
13
- import logging
14
- from collections.abc import AsyncIterator
15
- from typing import Any
16
-
17
- import httpx
18
-
19
11
  from ..config.schema import FailoverConfig, ZhipuConfig
20
12
  from ..routing.model_mapper import ModelMapper
21
- from .base import (
22
- PROXY_SKIP_HEADERS,
23
- BaseVendor,
24
- VendorCapabilities,
25
- VendorResponse,
26
- )
13
+ from .native_anthropic import NativeAnthropicVendor
27
14
 
28
- logger = logging.getLogger(__name__)
29
15
 
30
-
31
- class ZhipuVendor(BaseVendor):
16
+ class ZhipuVendor(NativeAnthropicVendor):
32
17
  """智谱 GLM 原生 Anthropic 兼容端点供应商(薄透传).
33
18
 
34
19
  通过官方 /api/anthropic 端点转发请求,
35
20
  仅替换模型名和认证头,其余原样透传。
36
-
37
- 401 错误归一化通过基类响应处理钩子(_normalize_error_response)实现,
38
- 无需完整覆写 send_message / send_message_stream。
39
21
  """
40
22
 
23
+ _vendor_name = "zhipu"
24
+ _display_name = "Zhipu"
25
+
41
26
  def __init__(
42
27
  self,
43
28
  config: ZhipuConfig,
44
29
  model_mapper: ModelMapper,
45
30
  failover_config: FailoverConfig | None = None,
46
31
  ) -> None:
47
- super().__init__(
48
- config.base_url, config.timeout_ms, failover_config=failover_config
49
- )
50
- self._api_key = config.api_key
51
- self._model_mapper = model_mapper
52
-
53
- def get_name(self) -> str:
54
- return "zhipu"
55
-
56
- def get_capabilities(self) -> VendorCapabilities:
57
- return VendorCapabilities(
58
- supports_tools=True,
59
- supports_thinking=True,
60
- supports_images=True,
61
- emits_vendor_tool_events=False,
62
- supports_metadata=True,
63
- )
64
-
65
- def get_compatibility_profile(self):
66
- from ..compat.canonical import CompatibilityProfile, CompatibilityStatus
67
-
68
- return CompatibilityProfile(
69
- thinking=CompatibilityStatus.NATIVE,
70
- tool_calling=CompatibilityStatus.NATIVE,
71
- tool_streaming=CompatibilityStatus.NATIVE,
72
- mcp_tools=CompatibilityStatus.NATIVE,
73
- images=CompatibilityStatus.NATIVE,
74
- metadata=CompatibilityStatus.NATIVE,
75
- json_output=CompatibilityStatus.NATIVE,
76
- usage_tokens=CompatibilityStatus.NATIVE,
77
- )
78
-
79
- def map_model(self, model: str) -> str:
80
- """将 Claude 模型名映射为智谱模型名,完全委托 ModelMapper."""
81
- return self._model_mapper.map(model, vendor="zhipu")
82
-
83
- async def _prepare_request(
84
- self,
85
- request_body: dict[str, Any],
86
- headers: dict[str, str],
87
- ) -> tuple[dict[str, Any], dict[str, str]]:
88
- """深拷贝请求体、映射模型名、替换认证头.
89
-
90
- 其余字段(tools, thinking, metadata, system 等)原样透传。
91
- """
92
- body = copy.deepcopy(request_body)
93
-
94
- if "model" in body:
95
- body["model"] = self.map_model(body["model"])
96
-
97
- # 剥离原始认证头(authorization / x-api-key),由下方 new_headers 重建
98
- filtered = {
99
- k: v
100
- for k, v in headers.items()
101
- if k.lower() not in PROXY_SKIP_HEADERS
102
- and k.lower() not in ("x-api-key", "authorization")
103
- }
104
- new_headers = {
105
- "content-type": "application/json",
106
- "x-api-key": self._api_key,
107
- "anthropic-version": headers.get("anthropic-version", "2023-06-01"),
108
- }
109
- for key, value in filtered.items():
110
- if key.lower() not in {item.lower() for item in new_headers}:
111
- new_headers[key] = value
112
- return body, new_headers
113
-
114
- # ── 响应处理钩子 ──────────────────────────────────────
115
-
116
- async def send_message(
117
- self,
118
- request_body: dict[str, Any],
119
- headers: dict[str, str],
120
- ) -> VendorResponse:
121
- """最小化覆写:API key 缺失时快速返回 401 响应,其余委托基类(含 _normalize_error_response 钩子)."""
122
- if not self._api_key:
123
- raw = json.dumps(
124
- self._missing_api_key_payload(), ensure_ascii=False
125
- ).encode()
126
- return VendorResponse(
127
- status_code=401,
128
- raw_body=raw,
129
- error_type="authentication_error",
130
- error_message="Zhipu API key 未配置,无法访问 Claude 兼容端点",
131
- response_headers={"content-type": "application/json"},
132
- )
133
- return await super().send_message(request_body, headers)
134
-
135
- def _normalize_error_response(
136
- self,
137
- status_code: int,
138
- response: httpx.Response,
139
- backend_resp: VendorResponse,
140
- ) -> VendorResponse:
141
- """仅对 401 错误执行归一化,其余状态码透传."""
142
- if status_code != 401:
143
- return backend_resp
144
- raw_body, payload = self._normalize_backend_error(
145
- status_code,
146
- response.content if response else backend_resp.raw_body,
147
- )
148
- error = payload.get("error", {}) if isinstance(payload, dict) else {}
149
- return VendorResponse(
150
- status_code=status_code,
151
- raw_body=raw_body,
152
- error_type=error.get("type")
153
- if isinstance(error, dict)
154
- else "authentication_error",
155
- error_message=error.get("message")
156
- if isinstance(error, dict)
157
- else "Zhipu API 认证失败",
158
- response_headers=backend_resp.response_headers,
159
- usage=backend_resp.usage,
160
- model_served=backend_resp.model_served,
161
- )
162
-
163
- # ── 流式 401 归一化包装 ───────────────────────────────
164
-
165
- async def send_message_stream(
166
- self,
167
- request_body: dict[str, Any],
168
- headers: dict[str, str],
169
- ) -> AsyncIterator[bytes]:
170
- """轻量包装:API key 缺失时快速失败,否则委托基类流式发送并捕获 401 归一化."""
171
- if not self._api_key:
172
- payload = self._missing_api_key_payload()
173
- raw = json.dumps(payload, ensure_ascii=False).encode()
174
- request = httpx.Request("POST", f"{self._base_url}{self._get_endpoint()}")
175
- raise httpx.HTTPStatusError(
176
- "zhipu API error: 401",
177
- request=request,
178
- response=httpx.Response(
179
- 401,
180
- content=raw,
181
- headers={"content-type": "application/json"},
182
- request=request,
183
- ),
184
- )
185
- try:
186
- async for chunk in super().send_message_stream(request_body, headers):
187
- yield chunk
188
- except httpx.HTTPStatusError as exc:
189
- response = exc.response
190
- if response is not None and response.status_code == 401:
191
- raw_body = response.content or b"{}"
192
- normalized_raw, _ = self._normalize_backend_error(
193
- response.status_code,
194
- raw_body,
195
- )
196
- raise httpx.HTTPStatusError(
197
- str(exc),
198
- request=exc.request,
199
- response=httpx.Response(
200
- response.status_code,
201
- content=normalized_raw,
202
- headers=dict(response.headers),
203
- request=exc.request,
204
- ),
205
- ) from exc
206
- raise
207
-
208
- # ── 401 错误归一化工具方法 ────────────────────────────
209
-
210
- @staticmethod
211
- def _normalize_auth_error_payload(payload: dict[str, Any] | None) -> dict[str, Any]:
212
- if not isinstance(payload, dict):
213
- return {
214
- "error": {
215
- "type": "authentication_error",
216
- "message": "Zhipu API 认证失败,请检查 api_key 或兼容端点权限",
217
- }
218
- }
219
- error = payload.get("error")
220
- if not isinstance(error, dict):
221
- payload["error"] = {
222
- "type": "authentication_error",
223
- "message": "Zhipu API 认证失败,请检查 api_key 或兼容端点权限",
224
- }
225
- return payload
226
- payload["error"] = {
227
- **error,
228
- "type": "authentication_error",
229
- "message": str(
230
- error.get("message")
231
- or "Zhipu API 认证失败,请检查 api_key 或兼容端点权限"
232
- ),
233
- }
234
- return payload
235
-
236
- @staticmethod
237
- def _missing_api_key_payload() -> dict[str, Any]:
238
- return {
239
- "error": {
240
- "type": "authentication_error",
241
- "message": "Zhipu API key 未配置,无法访问 Claude 兼容端点",
242
- }
243
- }
244
-
245
- def _normalize_backend_error(
246
- self,
247
- status_code: int,
248
- raw_body: bytes,
249
- ) -> tuple[bytes, dict[str, Any] | None]:
250
- payload: dict[str, Any] | None = None
251
- if raw_body:
252
- try:
253
- decoded = json.loads(raw_body)
254
- if isinstance(decoded, dict):
255
- payload = decoded
256
- except (json.JSONDecodeError, UnicodeDecodeError, TypeError):
257
- payload = None
258
- if status_code != 401:
259
- return raw_body, payload
260
- payload = self._normalize_auth_error_payload(payload)
261
- body = copy.deepcopy(payload)
262
- return json.dumps(body, ensure_ascii=False).encode(), body
32
+ super().__init__(config, model_mapper, failover_config)
263
33
 
264
34
 
265
35
  # 向后兼容别名
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: coding-proxy
3
- Version: 0.1.4a8
3
+ Version: 0.2.0a2
4
4
  Summary: A High-Availability, Transparent, and Smart Multi-Vendor Proxy for Claude Code. Support Claude Plans, GitHub Copilot, Google Antigravity, ZAI/GLM.
5
5
  Project-URL: Source Code, https://github.com/ThreeFish-AI/coding-proxy
6
6
  Project-URL: User Guide, https://github.com/ThreeFish-AI/coding-proxy/blob/master/docs/user-guide.md
@@ -17,13 +17,13 @@ coding/proxy/compat/canonical.py,sha256=-zcuEwZ402xeH3C545RmuYRkT2HDuvFloyFydDv8
17
17
  coding/proxy/compat/session_store.py,sha256=B9IFjjQJnHMg1244m__jG9gnqGWi26-JyEtwopEri6Q,5244
18
18
  coding/proxy/config/__init__.py,sha256=hzgU5noJGecjj13UY38cC_p6jpWO3GO7okSW-A2XkJ0,127
19
19
  coding/proxy/config/auth_schema.py,sha256=LYrJQU_fgW-6AoQdjXt4-MgPJjXjv9HrghlCcZwotnA,696
20
- coding/proxy/config/config.default.yaml,sha256=nlJW2E1RjwoRRRmrjZuVXV-OzO5Gef3a7-oXQroaG3o,9676
20
+ coding/proxy/config/config.default.yaml,sha256=oVs8vDylKW9MflEZWgroFZlHV1IrqS2UdhyZu2OMtDY,15695
21
21
  coding/proxy/config/loader.py,sha256=1J_RBJgjuC8RwB2mwewLMS7vy9WEhUqttZG2igeDm-w,8984
22
22
  coding/proxy/config/resiliency.py,sha256=GnzY-LoyfFqXFM1l6xEru418v-cKlv97-HM0noGPdks,1308
23
- coding/proxy/config/routing.py,sha256=1jX96Uhs15PogZF67kIvKrgpWb01m7EP85XKzz7Ov38,11255
24
- coding/proxy/config/schema.py,sha256=p-l1iQSbeZBNtHWnIRBo6PkWP7FajPI84zacUxMqpFg,11911
23
+ coding/proxy/config/routing.py,sha256=aJMhfCRyoZIvemM3Q2_KV9rpWxUsFnoY0ZdCr4TwSs8,11765
24
+ coding/proxy/config/schema.py,sha256=yDPQfxUzJToAfXH-fJxoujXoYAb6WMeq7VyySbvMYC8,12205
25
25
  coding/proxy/config/server.py,sha256=um6SJHat9Z_DPjE0AzpdbmbA0fTB0KovUlkNl_eJX-k,509
26
- coding/proxy/config/vendors.py,sha256=mHqd-gHd2yE-m8tto6v9haOfk-klQhLQkNpx4KGtLLo,1456
26
+ coding/proxy/config/vendors.py,sha256=Kw4IctoZBgB4yd7GlnoubWHRrKqmqSC6zY87oH3EPTQ,2796
27
27
  coding/proxy/convert/__init__.py,sha256=0D3Q9TdY_AWCaMMf9f_i3jn0RIiWmqlcIAA79Ki8uJc,458
28
28
  coding/proxy/convert/anthropic_to_gemini.py,sha256=9mRQ0CRAGJyWQADNlfMqoCJ_vY8ZZBGWaS_R8Vbe_l0,13201
29
29
  coding/proxy/convert/anthropic_to_openai.py,sha256=crE8gi780Tr-dI58hce75BiaKzlh_dEyzvMxwLgAa8A,13435
@@ -43,25 +43,26 @@ coding/proxy/model/vendor.py,sha256=Yg4AYN7tgjHaGWRGEccCs3AdO8vBc-KxIelnqRowpyo,
43
43
  coding/proxy/routing/__init__.py,sha256=2Tpc6MQ5Oy_w-YlEWQVDSgcSgiHp3OwKOABIjj5kfHA,1595
44
44
  coding/proxy/routing/circuit_breaker.py,sha256=fKodIYxJ-3hhil2rEjsGqvyHTspliN_eS8QyL3BFI8s,7189
45
45
  coding/proxy/routing/error_classifier.py,sha256=oDxp69sCb-pdfe1hWce29A9tsN3jAbhqfl2fRECBtCo,3747
46
- coding/proxy/routing/executor.py,sha256=uXpEkNoG5rN9JZhbz_gZeDHFzHpmhmwPJzow9ZA5OtA,28071
47
- coding/proxy/routing/model_mapper.py,sha256=PPyZ8ZvLSG8ujGmZL3bMPAzdTNu-z8woNTg6cXSZ-Js,3454
46
+ coding/proxy/routing/executor.py,sha256=xQw3rtHd00n3BBgUHzqAli1GUoFNOxc0odKEaq-Dw7A,28206
47
+ coding/proxy/routing/model_mapper.py,sha256=b72CGRdusLAwoq7p8-8TWAv9-Zv8BozssiZC8XnNTx4,3574
48
48
  coding/proxy/routing/quota_guard.py,sha256=VBJSgS1Wjw8RBwyfCdegWrBXGTbVmmU3bA3Tf81O8ns,6558
49
49
  coding/proxy/routing/rate_limit.py,sha256=i2cCqtbmXrP6wjRUTWXLP4DdYwVj0C4o59QdYGkPQj0,5122
50
50
  coding/proxy/routing/retry.py,sha256=KEYVToBkBOtXdqY7He70RrtVWFqIpnOQf2VVksdLrlk,2386
51
51
  coding/proxy/routing/router.py,sha256=bXaglxuT-5qYzrSMk7ZE4mpQynP4Z6F2pm9hnCbdG90,3440
52
- coding/proxy/routing/session_manager.py,sha256=r3ach8ZxnuZEWWikPB0wl-oYzT__MkAvK3Frh4j_xr4,2730
52
+ coding/proxy/routing/session_manager.py,sha256=kpEPCo67CdsELX71hoe6G7sb2dcda7gTNL0FtpgRK7I,2950
53
53
  coding/proxy/routing/tier.py,sha256=U12Mw0eTE1AO5RuHNpoOuXDdujz_Hkx_iyIrqkZbtyA,7024
54
54
  coding/proxy/routing/usage_parser.py,sha256=j4G0ArFduQ2D4Yeuad94DVlwdc-JvSh7SJLVzc-hLcs,8480
55
55
  coding/proxy/routing/usage_recorder.py,sha256=pSs2r79fOrrq2cWJP-P5KKFnnXf62-3gYLaxAwndFi0,6272
56
56
  coding/proxy/server/__init__.py,sha256=KeH7mEu36v9v27m3VgeSxSeFz9sLTJrxS_EVATJ7Vks,20
57
57
  coding/proxy/server/app.py,sha256=hxCKb8FVEOYCvC84agUtwECajtqLqNgkTIEpEySJaGs,5613
58
- coding/proxy/server/factory.py,sha256=jQZ1Wv8H__S96p4anTW90b57ZOSXbiHNz2rp09ud5mk,7773
58
+ coding/proxy/server/factory.py,sha256=I4asjFw_1ET49DC-xkCpfV7oyfSv4G6xUB_Z5N_SHY8,9920
59
59
  coding/proxy/server/request_normalizer.py,sha256=o0N27hnrBjWxsDQ_c8i7ooNcyv1NVVQFmdQLZO0BQxY,14648
60
60
  coding/proxy/server/responses.py,sha256=i0ugnLRNOdRYGHEWxkwsxR35ChmdMQsSaD8AjRluTn4,2167
61
61
  coding/proxy/server/routes.py,sha256=QeEsYczjvPfVhOrED2qe1V6CpwVBZbQHs8dP0OGdGXQ,11734
62
62
  coding/proxy/streaming/__init__.py,sha256=0al5TC-zJt8Bz0CibTmd8WPza-Cs-qcuZWvT2fKPqHI,23
63
63
  coding/proxy/streaming/anthropic_compat.py,sha256=cycYiJ-glN88OmfLTR7FroHRethONlEcK0PT78KqGbA,21202
64
64
  coding/proxy/vendors/__init__.py,sha256=fehSpQ2-kUlZY6N8cNMGVJYMXspQmi3V4e0FgC4Ay4k,1011
65
+ coding/proxy/vendors/alibaba.py,sha256=vYhvk8hZEeOpqUrtGT-uaK89y6uolrDUAT2BvTD_IQY,876
65
66
  coding/proxy/vendors/anthropic.py,sha256=KA_fvOxagGBggH2pc3l9Zoyl_XYUyRdfR8bI-eVj_e4,6328
66
67
  coding/proxy/vendors/antigravity.py,sha256=zVl2fguxyIy3OjkosZYr2n5tR8dEEIjxazBEXY7v6BQ,13300
67
68
  coding/proxy/vendors/base.py,sha256=vrAaI_4uLtzaFcPWtBStVMHU5AgkCWTNLEgVeoHHgLE,14781
@@ -69,11 +70,16 @@ coding/proxy/vendors/copilot.py,sha256=qAFTO2xMqnawaFlvZS2a9-7f_UEkfODIFfDlgOBiQ
69
70
  coding/proxy/vendors/copilot_models.py,sha256=UckIQYA4qLyNwEA09koQGBOZ65Nxhuo3ytUuDNqtzRU,15514
70
71
  coding/proxy/vendors/copilot_token_manager.py,sha256=_sZBSFr4sFF2BuP-ZWexQxbN3R8TZs9CJ_d62LvyeBw,6710
71
72
  coding/proxy/vendors/copilot_urls.py,sha256=YxaR6zmPdrySzsotJx6PjNIu2JIGG6N1D8kZs77oUCM,404
73
+ coding/proxy/vendors/doubao.py,sha256=33vRq2MzOU5Yz3KEMTVPUBcjbo1cGGaEecmUR_kpMQA,862
74
+ coding/proxy/vendors/kimi.py,sha256=T-Hy3Nyv_8PSP0GrrYE64TTaJrc_lWrw7TJHtWmHO2U,818
75
+ coding/proxy/vendors/minimax.py,sha256=HoaZARuCYKfdOXud_SaUQhQ9LuJPKU7cQV4sN8rsopU,845
72
76
  coding/proxy/vendors/mixins.py,sha256=eZd_vlsPCKUNOEWSxWTDDb5i24GUIE3_JZDsj5LMr08,2583
77
+ coding/proxy/vendors/native_anthropic.py,sha256=SxtM71PDci0gqLqiwCrFnT410SnSoD7FhLwcZuGB8tU,10074
73
78
  coding/proxy/vendors/token_manager.py,sha256=s10t4Com0jNnKGkPyJ_HpG5SjHrCEJvfArEOAaPKA_k,4189
74
- coding/proxy/vendors/zhipu.py,sha256=7xynP_1OYpkaY3Ngi-NDYmgCDnKgk6ECMXvcwGRq668,9749
75
- coding_proxy-0.1.4a8.dist-info/METADATA,sha256=C4GXIBuOeslCAeWU_RePixNwlnJODTrNExiHiRWb6lY,10782
76
- coding_proxy-0.1.4a8.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
77
- coding_proxy-0.1.4a8.dist-info/entry_points.txt,sha256=moIVzt5ho0Wk9B47LOo2SEAbhzuDDHWi-EfM30U0XBg,54
78
- coding_proxy-0.1.4a8.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
79
- coding_proxy-0.1.4a8.dist-info/RECORD,,
79
+ coding/proxy/vendors/xiaomi.py,sha256=E-GcmJBZh7GOtDFonxZmlf0hKRhrlrXzL0IxHFRYcRo,860
80
+ coding/proxy/vendors/zhipu.py,sha256=3j_rqNFu1CX-B5ugtrL6Y1OeWSy9yiqsVa9Bi1ssaAA,1062
81
+ coding_proxy-0.2.0a2.dist-info/METADATA,sha256=XoO6Pxu5OOCNg8X8Rya0rvx85IJfkA9bmUZVZXYjGxc,10782
82
+ coding_proxy-0.2.0a2.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
83
+ coding_proxy-0.2.0a2.dist-info/entry_points.txt,sha256=moIVzt5ho0Wk9B47LOo2SEAbhzuDDHWi-EfM30U0XBg,54
84
+ coding_proxy-0.2.0a2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
85
+ coding_proxy-0.2.0a2.dist-info/RECORD,,