Skip to content

feat(copilot): add billing endpoint#855

Merged
Sg312 merged 4 commits intostagingfrom
feat/copilot-billing-v1
Aug 3, 2025
Merged

feat(copilot): add billing endpoint#855
Sg312 merged 4 commits intostagingfrom
feat/copilot-billing-v1

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Aug 3, 2025

Summary

Adds update billing endpoint for agent

Type of Change

  • New feature

Testing

Manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the [Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Aug 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sim ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 3, 2025 0:58am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Skipped (Inspect) Aug 3, 2025 0:58am

@Sg312 Sg312 requested a review from icecrasher321 August 3, 2025 00:46
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR introduces copilot-specific billing functionality by adding a new cost multiplier for copilot operations and creating an internal billing endpoint. The changes consist of three main components:

  1. Environment Configuration: A new optional environment variable COPILOT_COST_MULTIPLIER is added to lib/env.ts with proper Zod validation, following the existing pattern of the COST_MULTIPLIER variable.

  2. Cost Calculation Enhancement: The calculateCost function in providers/utils.ts is extended with an optional customMultiplier parameter, allowing callers to override the default cost multiplier while maintaining backward compatibility through the nullish coalescing operator.

  3. New Billing Endpoint: A new route at /api/billing/update-cost provides an internal API for external services to report copilot token usage. The endpoint features internal API key authentication, comprehensive input validation with Zod schemas, and database operations that mirror the existing ExecutionLogger patterns.

The implementation enables separate cost tracking for copilot operations versus regular workflow executions, allowing administrators fine-grained control over copilot pricing. The architecture maintains consistency with existing billing infrastructure while providing the flexibility needed for different product features to have distinct cost structures.

Confidence score: 4/5

  • This PR introduces new billing functionality with minimal risk to existing systems due to backward compatibility
  • Score reflects well-structured implementation following existing patterns, though the new billing endpoint requires careful monitoring
  • Pay close attention to the new billing endpoint route.ts for proper authentication and cost calculation logic

3 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs August 3, 2025 00:48 Inactive
@vercel vercel bot temporarily deployed to Preview – docs August 3, 2025 00:51 Inactive
@Sg312 Sg312 merged commit 6c12104 into staging Aug 3, 2025
4 of 5 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/copilot-billing-v1 branch August 4, 2025 17:49
waleedlatif1 pushed a commit that referenced this pull request Aug 5, 2025
* Add copilot billing

* Lint

* Update logic

* Dont count as api callg
waleedlatif1 pushed a commit that referenced this pull request Aug 6, 2025
* Add copilot billing

* Lint

* Update logic

* Dont count as api callg
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
* Add copilot billing

* Lint

* Update logic

* Dont count as api callg
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.

1 participant