Refactor AI billing config and align credits cost handling#590
Refactor AI billing config and align credits cost handling#590
Conversation
- Removed the TOKEN_COSTS dictionary and related methods from AgentConfig, simplifying the agent configuration. - Updated billing configuration to centralize token pricing for AI operations in billing/ai.py, with clear definitions for input and output token costs. - Adjusted README and documentation to reflect changes in credit consumption and billing structure. - Enhanced tests to validate the new token pricing model and ensure proper functionality across configurations.
- Adjusted monthly price and infrastructure details for the LadybugDB Standard offering to reflect new pricing and resource allocation. - Removed the bulk export configuration from the SEC_MANIFEST, streamlining the manifest structure.
|
@claude please review this PR |
|
Claude finished @jfrench9's task in 1m 35s —— View job PR Review: Refactor AI billing config and align credits cost handlingTodo:
Overall this is a clean, well-motivated refactor. The net reduction of ~243 lines is real simplification, not just deletion of useful code. A few things worth discussing: Bug Fix (Important)
{"input": Decimal("0.003"), "output": Decimal("0.015")}These are dollar amounts, not credit amounts. The correct values are Product Change Embedded in Refactor
This is a significant pricing and positioning change. It may be intentional, but it deserves its own explicit review/sign-off rather than being bundled into a billing config cleanup. Were these changes meant to be in this PR, or are they left over from another branch? Fix this → Weak Test Replacement
assert "agent_capabilities" in summaryThis is redundant — assert "token_cost_models" not in summary...which actually documents the intentional removal of that key. Fix this → Narrowed Model Pricing (Deliberate, but Note the Tradeoff)Removing Opus and OpenAI entries from Minor Observations
Summary
The code is production-ready pending review of the offering price change. The billing math is consistent across all three touch points ( |
- Modified the test to assert that "token_cost_models" is not present in the summary, ensuring accurate validation of the agent configuration output.
|
@claude please review this PR |
|
Claude finished @jfrench9's task in 2m 26s —— View job Todo:
PR Review: Refactor AI billing config and align credits cost handlingThis is a clean, well-scoped refactor. The ~243 line reduction is genuine simplification. A few things worth calling out: Bug Fix (Important) ✅
{"input": Decimal("0.003"), "output": Decimal("0.015")}...are dollar amounts, not credits. The new fallback: {"input": Decimal("3"), "output": Decimal("15")}...is correct (3 and 15 credits per 1K tokens, matching Offering.py Example — Clarification on Prior Review
|
| Area | Assessment |
|---|---|
| Core billing logic | ✅ Correct and simplified |
| Bug fix (orchestrator fallback 1000x undercharge) | ✅ Critical fix |
| Offering.py example | ✅ Correcting stale docstring, not a price change |
CREDIT_COSTS partial subset |
|
| Test coverage | ✅ Solid, test_agents.py:140 is correct |
| Removed Opus/OpenAI pricing | ✅ Acknowledged, graceful fallback in place |
Code is production-ready. The partial CREDIT_COSTS dict is the only nit worth cleaning up, but it's not a blocker.
Summary
Simplifies and streamlines the AI billing configuration, agent token cost handling, and credits system by removing unnecessary abstractions, consolidating logic, and eliminating the bulk export configuration. This refactor reduces the codebase by ~243 lines while maintaining equivalent functionality.
Key Accomplishments
config/billing/ai.py): Significantly reduced complexity by removing redundant configuration layers and flattening the billing model structure.config/agents.py,operations/agents/orchestrator.py): Removed the dedicated agents config module's excess abstractions, simplifying how agent token costs are resolved and passed through the orchestrator.config/credits.py,operations/graph/credit_service.py): Reduced indirection in the credit service by simplifying cost lookups and removing unnecessary intermediate mappings.adapters/sec/manifest.py): Cleaned up the SEC adapter manifest by removing a bulk export config entry that is no longer needed.routers/offering.py): Aligned the offerings endpoint with the simplified billing and credits structures.config/README.md): Rewrote and condensed the configuration README to accurately reflect the simplified architecture.Breaking Changes
config/agents.pymay need to be updated.Testing Notes
tests/config/billing/test_ai.py,tests/config/billing/test_core.py, andtests/config/test_agents.pyhave been updated to reflect the simplified interfaces.Infrastructure Considerations
🤖 Generated with Claude Code
Branch Info:
refactor/credits-cost-alignmentmainCo-Authored-By: Claude noreply@anthropic.com