From e33d5b952cd3533383cc7aa351be7d313ed7aef1 Mon Sep 17 00:00:00 2001 From: fawney19 Date: Wed, 7 Jan 2026 20:15:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=80=E6=9C=89=E8=AE=A1=E8=B4=B9?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=94=AF=E6=8C=81=E6=8C=89=E6=AC=A1=E8=AE=A1?= =?UTF-8?q?=E8=B4=B9=EF=BC=8C=E8=B0=83=E6=95=B4=E7=AB=AF=E7=82=B9=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E9=87=8D=E8=AF=95=E6=AC=A1=E6=95=B0=E4=B8=BA=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为 Claude、OpenAI、豆包、Gemini 计费模板添加 request 维度 - 支持通过 price_per_request 配置按次计费(如图片生成模型) - 将端点 max_retries 默认值从 3 改为 2(请求一次 + 重试一次) --- src/models/database.py | 2 +- src/models/endpoint_models.py | 2 +- src/services/billing/templates.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/models/database.py b/src/models/database.py index 35df330..bcfb550 100644 --- a/src/models/database.py +++ b/src/models/database.py @@ -597,7 +597,7 @@ class ProviderEndpoint(Base): # 请求配置 headers = Column(JSON, nullable=True) # 额外请求头 timeout = Column(Integer, default=300) # 超时(秒) - max_retries = Column(Integer, default=3) # 最大重试次数 + max_retries = Column(Integer, default=2) # 最大重试次数 # 限制 max_concurrent = Column( diff --git a/src/models/endpoint_models.py b/src/models/endpoint_models.py index 89caa74..af3124c 100644 --- a/src/models/endpoint_models.py +++ b/src/models/endpoint_models.py @@ -24,7 +24,7 @@ class ProviderEndpointCreate(BaseModel): # 请求配置 headers: Optional[Dict[str, str]] = Field(default=None, description="自定义请求头") timeout: int = Field(default=300, ge=10, le=600, description="超时时间(秒)") - max_retries: int = Field(default=3, ge=0, le=10, description="最大重试次数") + max_retries: int = Field(default=2, ge=0, le=10, description="最大重试次数") # 限制 max_concurrent: Optional[int] = Field(default=None, ge=1, description="最大并发数") diff --git a/src/services/billing/templates.py b/src/services/billing/templates.py index 4021b55..3590f2f 100644 --- a/src/services/billing/templates.py +++ b/src/services/billing/templates.py @@ -23,6 +23,7 @@ class BillingTemplates: # - 输出 token # - 缓存创建(创建时收费,约 1.25x 输入价格) # - 缓存读取(约 0.1x 输入价格) + # - 按次计费(可选,配置 price_per_request 时生效) # ========================================================================= CLAUDE_STANDARD: List[BillingDimension] = [ BillingDimension( @@ -45,6 +46,12 @@ class BillingTemplates: usage_field="cache_read_tokens", price_field="cache_read_price_per_1m", ), + BillingDimension( + name="request", + usage_field="request_count", + price_field="price_per_request", + unit=BillingUnit.PER_REQUEST, + ), ] # ========================================================================= @@ -52,6 +59,7 @@ class BillingTemplates: # - 输入 token # - 输出 token # - 缓存读取(部分模型支持,无缓存创建费用) + # - 按次计费(可选,配置 price_per_request 时生效) # ========================================================================= OPENAI_STANDARD: List[BillingDimension] = [ BillingDimension( @@ -69,6 +77,12 @@ class BillingTemplates: usage_field="cache_read_tokens", price_field="cache_read_price_per_1m", ), + BillingDimension( + name="request", + usage_field="request_count", + price_field="price_per_request", + unit=BillingUnit.PER_REQUEST, + ), ] # ========================================================================= @@ -77,6 +91,7 @@ class BillingTemplates: # - 推理输出 (output_tokens) # - 缓存命中 (cache_read_tokens) - 类似 Claude 的缓存读取 # - 缓存存储 (cache_storage_token_hours) - 按 token 数 * 存储时长计费 + # - 按次计费(可选,配置 price_per_request 时生效) # # 注意:豆包的缓存创建是免费的,但存储需要按时付费 # ========================================================================= @@ -102,6 +117,12 @@ class BillingTemplates: price_field="cache_storage_price_per_1m_hour", unit=BillingUnit.PER_1M_TOKENS_HOUR, ), + BillingDimension( + name="request", + usage_field="request_count", + price_field="price_per_request", + unit=BillingUnit.PER_REQUEST, + ), ] # ========================================================================= @@ -109,6 +130,7 @@ class BillingTemplates: # - 输入 token # - 输出 token # - 缓存读取 + # - 按次计费(用于图片生成等模型,需配置 price_per_request) # ========================================================================= GEMINI_STANDARD: List[BillingDimension] = [ BillingDimension( @@ -126,6 +148,12 @@ class BillingTemplates: usage_field="cache_read_tokens", price_field="cache_read_price_per_1m", ), + BillingDimension( + name="request", + usage_field="request_count", + price_field="price_per_request", + unit=BillingUnit.PER_REQUEST, + ), ] # =========================================================================