Skip to content

Comments

Add feature column to microdollar usage API responses#362

Open
kiloconnect[bot] wants to merge 1 commit intomainfrom
session/agent_0d5ba474-0405-455b-adb3-8ad4ad92db98
Open

Add feature column to microdollar usage API responses#362
kiloconnect[bot] wants to merge 1 commit intomainfrom
session/agent_0d5ba474-0405-455b-adb3-8ad4ad92db98

Conversation

@kiloconnect
Copy link
Contributor

@kiloconnect kiloconnect bot commented Feb 19, 2026

Summary

This PR adds the (feature_name) column to the microdollar usage API responses for both organization-level and user-level usage.

Changes Made:

  1. User-level usage API ():

    • Added import for and tables
    • Added LEFT JOIN with metadata and feature tables to get feature information
    • Added to SELECT and GROUP BY clauses
    • Response now includes field
  2. Organization-level usage API ():

    • Added imports for and tables
    • Updated endpoint to include feature in response
    • Updated endpoint to include feature in response
    • Added feature to schema output types
  3. Type definition ():

    • Added field to type

How it works:

The already exists in the table which links to the lookup table. This PR joins these tables to expose the feature name (e.g., vscode-extension, jetbrains-extension, cli, slack, kilo-claw, cloud-agent, code-review) in the usage API responses.

Built for Brendan by Kilo for Slack

- Add feature (feature_name) to user-level usage API (profile/usage)
- Add feature to organization-level usage API (get and getTimeSeries endpoints)
- Join with microdollar_usage_metadata and feature tables to get feature info
- Update UsageDetailByDay type to include feature field

Built for [Brendan](https://kilo-code.slack.com/archives/C0AF922FTB4/p1771511489370519?thread_ts=1771499545.031009&cid=C0AF922FTB4) by [Kilo for Slack](https://kilo.ai/features/slack-integration)
const selectFields = {
date: sql<string>`DATE(${microdollar_usage.created_at})`,
...(groupByModel && { model: microdollar_usage.model }),
feature: sql<string>`${feature.feature}`.as('feature'),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WARNING: Incorrect type annotation — sql<string> should be sql<string | null> since this comes from a leftJoin. When there's no matching microdollar_usage_metadata or feature row, the value will be null at runtime, but TypeScript will believe it's string.

Suggested change
feature: sql<string>`${feature.feature}`.as('feature'),
feature: sql<string | null>`${feature.feature}`.as('feature'),

@kiloconnect
Copy link
Contributor Author

kiloconnect bot commented Feb 19, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
src/app/api/profile/usage/route.ts 25 sql<string> should be sql<string | null> — the leftJoin can produce null when no matching metadata/feature row exists
Files Reviewed (3 files)
  • src/app/api/profile/usage/route.ts - 1 issue
  • src/lib/organizations/organization-types.ts - 0 issues
  • src/routers/organizations/organization-usage-details-router.ts - 0 issues

Fix these issues in Kilo Cloud

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.

0 participants