new-api icon indicating copy to clipboard operation
new-api copied to clipboard

复杂动态计费表达式已经正确结算,但前端列表页会显示“无匹配结果”,容易误导管理员。

Open vippyong opened this issue 1 month ago • 1 comments

Read This First

  • Docs: https://docs.newapi.ai/
  • Usage questions first: https://deepwiki.com/QuantumNous/new-api
  • Do not report issues when pass-through is enabled; pass-through sends content as-is and does not go through new-api processing logic.
  • State facts and evidence concisely. Do not paste unfiltered AI-generated text in the issue body or in later comments.
  • Relay reports must first establish that the issue occurs in the new-api layer. Use equivalent redacted requests to compare the direct upstream result with the result through new-api, including response status, error body, and server logs. Reports that skip this comparison or only show an upstream error are not accepted.
  • Reports about Coding Plan services, reverse-engineered channels, third-party API wrappers, or compatibility issues caused by exposing a Codex endpoint through a reverse proxy as a general-purpose API are not accepted. Protocols or behavior specific to the Codex API should not be treated as standard OpenAI API behavior; confirm such issues with the channel or API provider first.
  • This project does not operate an official hosted service or provide technical support for third-party hosting sites, relay services, or API services. Contact the relevant operator for those issues.
  • Warning: issues with this template removed, section headings deleted, or content cleared may be closed directly. Repeated submissions of unfiltered AI-generated text, or repeated abusive submissions, may result in a block.

Deployment source

Repository release / official image (self-hosted)

Your current newapi version

v1.0.0-rc.40

Submission Checks

  • [x] Non-duplicate issue: I have searched existing Issues and confirmed there are no similar issues.
  • [x] Read this first: I have fully read the section above, reviewed the docs at https://docs.newapi.ai/ and the project README, and asked AI first, confirming this is not a usage, configuration, or integration question.
  • [x] Supported version: I have provided an exact version, commit, or image tag (not latest or unknown) and confirmed that the issue reproduces on an unmodified, supported version from this repository.
  • [x] Not a third-party service: I confirm that this issue is not exclusive to a third-party hosting site, relay, API service, or fork that has not been verified against the unmodified repository. Third-party instance issues must be reported to their operator.
  • [x] Not pass-through: I confirm that pass-through is not enabled on the relevant channel. Pass-through sends content as-is and does not go through new-api processing logic; such reports are not accepted.
  • [x] Issue attribution: I have provided evidence that distinguishes the client, new-api, and upstream layers. For relay issues, I compared equivalent redacted requests sent directly upstream and through new-api, confirming that new-api introduces or changes the error rather than merely forwarding the upstream error unchanged.
  • [x] Channel and protocol boundary: I confirm that the issue is not caused by a Coding Plan service, reverse-engineered channel, third-party API wrapper, Codex reverse-proxy endpoint, or behavior specific to the Codex API. If first observed through such an interface, I have reproduced it using a standard API protocol supported by this repository.
  • [x] Maintainer time: I understand that maintainers have limited time. Do not paste unfiltered AI-generated text in the issue body or in later comments; extract the points needed for review first. Submissions that do not follow this template, or that omit the necessary points and cannot be reviewed, may be ignored or closed. Repeated submissions of this kind may result in a block.

Issue Description

使用动态计费表达式,并根据最终输出 token c 增加计费分支后,后端实际结算正常,日志详情中也能正确显示命中的阶梯和最终费用,但日志列表页会显示:

动态计费 · 无匹配结果

容易让管理员误以为该请求没有正确命中计费规则。

当前使用的表达式类似:

len <= 272000
? (
    c > 5
    ? tier("standard", p * 2 + c * 10 + cr * 0.1 + cc * 2.5)
    : tier("free_small_output", fixed(0))
  )
: (
    c > 5
    ? tier("long_context", p * 5 + c * 22.5 + cr * 0.5)
    : tier("free_small_output", fixed(0))
  )

主要用途是:

输出 token > 5
→ 正常计费

输出 token <= 5
→ free_small_output
→ fixed(0)

实际测试中计费结果正常。

例如正常请求:

输入 Token: 182700
输出 Token: 155
缓存读取: 182016

命中阶梯: standard
总费用: $0.02112

日志详情中显示:

计费模式:动态计费
命中阶梯:standard
计费路径:上游返回
总费用:$0.02112

实际费用计算也正确。

但日志列表页却显示:

动态计费 · 无匹配结果

另一种请求:

输入 Token: 20678
输出 Token: 0

能正确命中:

free_small_output

并结算:

$0

所以从后端 Settlement 结果来看,表达式本身工作正常,问题更像是日志列表页没有使用最终实际结算出来的 tier 信息,而是在尝试重新静态解析复杂表达式。

Steps to Reproduce

1. 在 New API v1.0.0-rc.40 中,为模型配置动态计费表达式,例如:

```text
len <= 272000
? (
    c > 5
    ? tier("standard", p * 2 + c * 10 + cr * 0.1 + cc * 2.5)
    : tier("free_small_output", fixed(0))
  )
: (
    c > 5
    ? tier("long_context", p * 5 + c * 22.5 + cr * 0.5)
    : tier("free_small_output", fixed(0))
  )
  1. 保存配置后,通过 /v1/responses 发起正常请求,并确保最终输出 token 大于 5。

  2. 请求完成后,在“日志详情”中可以看到:

    • 计费模式:动态计费
    • 命中阶梯:standard
    • 计费路径:上游返回
    • 最终费用计算正确
  3. 返回日志列表页查看同一条请求。

  4. 此时列表页“详情”列会显示:

动态计费 · 无匹配结果

但该请求实际上已经在后端 Settlement 阶段正确命中了 standard tier,并完成正常计费。

  1. 再发起一条输出 token <= 5 的请求,可以正确命中:
free_small_output

并按:

fixed(0)

结算为 $0。

因此可以确认动态计费表达式和最终结算本身正常,异常仅出现在日志列表页的 tier 展示。


“预期结果”建议写:

```markdown
日志列表页应优先展示该请求最终 Settlement 阶段实际命中的 tier。

例如:

- `动态计费 · standard`
- `动态计费 · long_context`
- `动态计费 · free_small_output`

如果前端无法静态解析复杂动态表达式,也建议显示:

`动态计费 · 特殊表达式`

而不是显示:

`动态计费 · 无匹配结果`

因为“无匹配结果”会让管理员误以为本次请求没有正确计费,但实际上后端已经成功完成 Settlement 并得出了正确 tier 和费用。

Expected Result

期望行为

如果请求已经完成结算,并且日志中已经保存了实际命中的 tier,希望列表页优先展示最终结算结果。

例如:

动态计费 · standard

或:

动态计费 · long_context

或:

动态计费 · free_small_output

而不是:

动态计费 · 无匹配结果

建议实现方式

建议日志列表页不要重新根据原始表达式推导 tier,而是优先读取请求最终结算阶段产生的:

matched_tier
billing_tier
pricing_tier

或当前后端实际保存的对应字段。

逻辑可以类似:

if settlement_matched_tier exists:
    显示 settlement_matched_tier
else if expression can be statically resolved:
    显示静态解析结果
else:
    显示“特殊动态计费”

这样对于依赖最终 usage 的表达式,例如:

c
p
cr
cc

就不会因为请求结束前无法确定 c 而错误显示“无匹配结果”。

UI 文案建议

当前:

动态计费 · 无匹配结果

建议改为优先显示:

动态计费 · standard
动态计费 · long_context
动态计费 · free_small_output

如果确实无法取得最终 tier,可以显示:

动态计费 · 特殊表达式

也比“无匹配结果”更准确。

补充建议

模型广场中的复杂表达式目前会显示:

特殊计费表达式
此表达式暂不支持展开为价格表,可查看下方原始表达式。

这个提示是合理的。

建议日志列表也采用类似思路:

对无法静态展开的表达式,不应等同于“没有匹配”,而应区分“无法静态解析”和“实际未匹配”。

这样可以避免管理员误判计费异常。


Related Screenshots

Image Image Image Image

vippyong avatar Oct 05 '26 11:10 vippyong

Подтверждаем потребность в этом контракте и для native Task Plugins: корректный settlement не должен выглядеть как «No matching results» в списке журнала. Сохранённый self-hosted official rc41 readback показал такой task-log fallback; новых runtime/paid проверок для этого комментария не выполняли.

Просим использовать сохранённый matched tier/settlement facts, отделяя «не удалось статически разобрать выражение» от «backend не нашёл тариф». Отдельная проблема локализованных usage labels и raw-key display описана в #7743; она не подменяет данный parser issue. Открытый PR #7446 исправляет is_task у settlement logs, его наличие ещё не доказывает исправление обоих UI-контрактов.

iamluxe77 avatar Oct 11 '26 05:10 iamluxe77