Skip to content

fix: add server-side tool usage tracking and normalization#44

Merged
chenyme merged 3 commits into
devfrom
tool_group_display
May 24, 2026
Merged

fix: add server-side tool usage tracking and normalization#44
chenyme merged 3 commits into
devfrom
tool_group_display

Conversation

@chenyme

@chenyme chenyme commented May 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Add native tool billing support for provider-side tools and expose the related admin controls.

This change records native tool usage in billing snapshots and service billing items, adds default native tool pricing for OpenAI, Anthropic, and xAI, and adds an admin Tool Pricing section below Model Pricing. Native tool billing is enabled by default and can be disabled from the billing settings.

It also updates related billing UI details: Claude cache write pricing now explains that Fast Mode applies another 6x on top, pricing tooltip labels no longer wrap unexpectedly, and backend task model selectors no longer hide routable chat models just because model pricing has not been configured.

Change type

  • Bug fix
  • Feature
  • Documentation
  • Refactor
  • Configuration / deployment
  • Security hardening
  • Other

Affected areas

  • Frontend / UI
  • Backend / API
  • Authentication / authorization
  • Conversations / streaming
  • Files / RAG / extraction
  • Model routing / providers
  • MCP / tools
  • Billing / payments
  • Admin console
  • Deployment / Docker / configuration
  • Documentation

Verification

  • cd backend && make swagger
  • cd backend && go test ./internal/application/billing ./internal/application/settings ./internal/infra/llm ./internal/transport/http/billing
  • cd backend && go test ./...
  • cd frontend && pnpm build
  • git diff --check

Screenshots, API examples, or logs

Not included.

Configuration, migration, and compatibility notes

Configuration changes: Adds native tool billing configuration in billing settings. Native tool billing defaults to enabled.

API changes: Billing config responses now include nativeToolBillingEnabled and nativeToolPricing.

Database migrations: None expected.

Deployment changes: None expected.

Backward compatibility: Existing model pricing and usage billing behavior remains compatible. Native tool usage is added as service billing detail when available. If native tool billing is disabled, native tool usage can still be recorded in snapshots without charging.

Swagger was regenerated to include the new billing config fields and native tool pricing response shape.

Documentation

  • Documentation is not needed for this change.
  • Documentation was updated.
  • Documentation still needs to be updated.

Security and privacy

  • No secrets, tokens, credentials, local config, or personal data are included.
  • User data access remains scoped by authenticated user context unless an admin-only path explicitly requires broader access.
  • Security-sensitive behavior was reviewed, including authentication, authorization, provider routing, file processing, billing, and admin APIs where relevant.

Checklist

  • I searched existing issues and pull requests.
  • Changes are focused and do not include unrelated refactors.
  • Tests or static verification were run where practical.
  • User-facing behavior, deployment steps, API contracts, or configuration changes are documented.
  • Generated artifacts are included only when this project explicitly requires them.
  • Caches, build output, .pyc files, .env files, and local storage data are not committed.

@chenyme chenyme linked an issue May 24, 2026 that may be closed by this pull request
3 tasks
@chenyme
chenyme merged commit 7a1e38b into dev May 24, 2026
2 checks passed
@chenyme
chenyme deleted the tool_group_display branch May 24, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 工具调用场景下 token metrics 统计可能不准确

1 participant