Skip to content

Commit dcdbd36

Browse files
committed
get rid of usd
1 parent 144c296 commit dcdbd36

File tree

6 files changed

+10
-12
lines changed

6 files changed

+10
-12
lines changed

packages/api/src/api-router/model-pricing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const modelPricingRouter = {
7777
.values(input)
7878
.onConflictDoUpdate({
7979
set: {
80-
price_per_unit_usd: input.price_per_unit_usd,
80+
price_per_unit: input.price_per_unit,
8181
updated_at: new Date(),
8282
},
8383
target: [

packages/api/src/api-router/usage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export const usageRouter = {
170170
});
171171

172172
if (usageAggregate) {
173-
currentUsageUsd = Number.parseFloat(usageAggregate.total_cost_usd);
173+
currentUsageUsd = Number.parseFloat(usageAggregate.total_cost);
174174
}
175175

176176
const canUse = currentUsageUsd < quotaUsd;
@@ -257,7 +257,7 @@ export const usageRouter = {
257257

258258
if (pricing) {
259259
const cost =
260-
Number.parseFloat(pricing.price_per_unit_usd) * metric.quantity;
260+
Number.parseFloat(pricing.price_per_unit) * metric.quantity;
261261
totalCost += cost;
262262
} else {
263263
console.warn(
@@ -270,13 +270,13 @@ export const usageRouter = {
270270
await tx
271271
.insert(UsageAggregate)
272272
.values({
273-
total_cost_usd: totalCost.toFixed(6),
273+
total_cost: totalCost.toFixed(6),
274274
usage_period_id: usagePeriod.id,
275275
user_id: usageEvent.user_id,
276276
})
277277
.onConflictDoUpdate({
278278
set: {
279-
total_cost_usd: sql`${UsageAggregate.total_cost_usd} + ${totalCost.toFixed(6)}`,
279+
total_cost: sql`${UsageAggregate.total_cost} + ${totalCost.toFixed(6)}`,
280280
updated_at: new Date(),
281281
},
282282
target: [UsageAggregate.user_id, UsageAggregate.usage_period_id],
@@ -287,7 +287,7 @@ export const usageRouter = {
287287
.update(UsageEvent)
288288
.set({
289289
status: "processed",
290-
total_cost_usd: totalCost.toFixed(6),
290+
total_cost: totalCost.toFixed(6),
291291
})
292292
.where(eq(UsageEvent.id, input.usage_event_id));
293293

packages/auth/src/stripe/price-handler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ async function upsertPrice(price: Stripe.Price) {
2929
unitAmount: price.unit_amount ?? 0,
3030
};
3131

32-
// For updates, exclude auto-generated timestamp fields and planId (shouldn't change)
3332
const updateData = {
3433
active: insertData.active,
3534
currency: insertData.currency,

packages/db/src/usage/model-pricing.schema.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
decimal,
33
index,
44
pgTable,
5-
text,
65
timestamp,
76
unique,
87
varchar,
@@ -19,7 +18,7 @@ export const ModelPricing = pgTable(
1918
length: TEXT_LIMITS.MODEL_PROVIDER,
2019
}).notNull(),
2120
unit_type: varchar("unit_type", { length: 50 }).notNull(), // e.g., "input_tokens", "output_tokens", "reasoning_tokens", "requests"
22-
price_per_unit_usd: decimal("price_per_unit_usd", {
21+
price_per_unit: decimal("price_per_unit", {
2322
precision: 12,
2423
scale: 8,
2524
}).notNull(), // High precision for token pricing (e.g., $0.00000150 per token)

packages/db/src/usage/usage-aggregate.schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const UsageAggregate = pgTable(
2323
.references(() => UsagePeriod.id, { onDelete: "cascade" }),
2424

2525
// Aggregated cost for the entire period
26-
total_cost_usd: decimal("total_cost_usd", { precision: 10, scale: 6 })
26+
total_cost: decimal("total_cost", { precision: 10, scale: 6 })
2727
.notNull()
2828
.default("0"),
2929

packages/db/src/usage/usage-event.schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const UsageEvent = pgTable(
4141
>()
4242
.notNull(),
4343
status: UsageEventStatus().notNull().default("pending"),
44-
total_cost_usd: decimal("total_cost_usd", { precision: 10, scale: 6 })
44+
total_cost: decimal("total_cost", { precision: 10, scale: 6 })
4545
.notNull()
4646
.default("0"),
4747
created_at: timestamp().defaultNow(),
@@ -76,7 +76,7 @@ export const zUsageEvent = createSelectSchema(UsageEvent);
7676
export const zUsageEventWebhook = zUsageEvent.extend({
7777
created_at: z.string().optional(),
7878
updated_at: z.string().optional(),
79-
total_cost_usd: z
79+
total_cost: z
8080
.union([z.string(), z.number()])
8181
.optional()
8282
.transform((val) => (val !== undefined ? String(val) : "0")),

0 commit comments

Comments
 (0)