@@ -40,6 +40,10 @@ export interface CustomProvider {
4040 apiKeySetting ?: string ;
4141 providerType : 'openai_compatible' | 'custom' ;
4242 isEnabled : boolean ;
43+ billingType : 'pay-per-use' | 'subscription' | 'free' ;
44+ subscriptionCostUsd ?: number ;
45+ subscriptionPlan ?: string ;
46+ billingNotes ?: string ;
4347 config : Record < string , unknown > ;
4448 createdAt : Date ;
4549 updatedAt : Date ;
@@ -79,6 +83,10 @@ export interface CreateProviderInput {
7983 apiKeySetting ?: string ;
8084 providerType ?: 'openai_compatible' | 'custom' ;
8185 isEnabled ?: boolean ;
86+ billingType ?: 'pay-per-use' | 'subscription' | 'free' ;
87+ subscriptionCostUsd ?: number ;
88+ subscriptionPlan ?: string ;
89+ billingNotes ?: string ;
8290 config ?: Record < string , unknown > ;
8391}
8492
@@ -105,6 +113,9 @@ export interface CreateUserProviderConfigInput {
105113 isEnabled ?: boolean ;
106114 apiKeyEnv ?: string ;
107115 notes ?: string ;
116+ billingType ?: 'pay-per-use' | 'subscription' | 'free' ;
117+ subscriptionCostUsd ?: number ;
118+ subscriptionPlan ?: string ;
108119 config ?: Record < string , unknown > ;
109120}
110121
@@ -114,6 +125,9 @@ export interface UpdateUserProviderConfigInput {
114125 isEnabled ?: boolean ;
115126 apiKeyEnv ?: string ;
116127 notes ?: string ;
128+ billingType ?: 'pay-per-use' | 'subscription' | 'free' ;
129+ subscriptionCostUsd ?: number ;
130+ subscriptionPlan ?: string ;
117131 config ?: Record < string , unknown > ;
118132}
119133
@@ -123,6 +137,10 @@ export interface UpdateProviderInput {
123137 apiKeySetting ?: string ;
124138 providerType ?: 'openai_compatible' | 'custom' ;
125139 isEnabled ?: boolean ;
140+ billingType ?: 'pay-per-use' | 'subscription' | 'free' ;
141+ subscriptionCostUsd ?: number ;
142+ subscriptionPlan ?: string ;
143+ billingNotes ?: string ;
126144 config ?: Record < string , unknown > ;
127145}
128146
@@ -159,6 +177,10 @@ interface CustomProviderRow {
159177 api_key_setting : string | null ;
160178 provider_type : string ;
161179 is_enabled : boolean ;
180+ billing_type : string | null ;
181+ subscription_cost_usd : number | null ;
182+ subscription_plan : string | null ;
183+ billing_notes : string | null ;
162184 config : string ;
163185 created_at : string ;
164186 updated_at : string ;
@@ -204,6 +226,7 @@ function rowToModelConfig(row: ModelConfigRow): UserModelConfig {
204226}
205227
206228function rowToProvider ( row : CustomProviderRow ) : CustomProvider {
229+ const billingType = row . billing_type as CustomProvider [ 'billingType' ] | null ;
207230 return {
208231 id : row . id ,
209232 userId : row . user_id ,
@@ -213,6 +236,10 @@ function rowToProvider(row: CustomProviderRow): CustomProvider {
213236 apiKeySetting : row . api_key_setting || undefined ,
214237 providerType : row . provider_type as 'openai_compatible' | 'custom' ,
215238 isEnabled : row . is_enabled ,
239+ billingType : billingType ?? 'pay-per-use' ,
240+ subscriptionCostUsd : row . subscription_cost_usd ?? undefined ,
241+ subscriptionPlan : row . subscription_plan ?? undefined ,
242+ billingNotes : row . billing_notes ?? undefined ,
216243 config : parseJsonField ( row . config , { } ) ,
217244 createdAt : new Date ( row . created_at ) ,
218245 updatedAt : new Date ( row . updated_at ) ,
@@ -518,6 +545,10 @@ export class ModelConfigsRepository extends BaseRepository {
518545 provider_type = COALESCE($4, provider_type),
519546 is_enabled = COALESCE($5, is_enabled),
520547 config = COALESCE($6, config),
548+ billing_type = COALESCE($10, billing_type),
549+ subscription_cost_usd = COALESCE($11, subscription_cost_usd),
550+ subscription_plan = COALESCE($12, subscription_plan),
551+ billing_notes = COALESCE($13, billing_notes),
521552 updated_at = $7
522553 WHERE user_id = $8 AND provider_id = $9` ,
523554 [
@@ -530,6 +561,10 @@ export class ModelConfigsRepository extends BaseRepository {
530561 now ,
531562 userId ,
532563 input . providerId ,
564+ input . billingType ?? null ,
565+ input . subscriptionCostUsd ?? null ,
566+ input . subscriptionPlan ?? null ,
567+ input . billingNotes ?? null ,
533568 ]
534569 ) ;
535570
@@ -542,8 +577,10 @@ export class ModelConfigsRepository extends BaseRepository {
542577 await this . execute (
543578 `INSERT INTO custom_providers (
544579 id, user_id, provider_id, display_name,
545- api_base_url, api_key_setting, provider_type, is_enabled, config, created_at, updated_at
546- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)` ,
580+ api_base_url, api_key_setting, provider_type, is_enabled,
581+ billing_type, subscription_cost_usd, subscription_plan, billing_notes,
582+ config, created_at, updated_at
583+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)` ,
547584 [
548585 id ,
549586 userId ,
@@ -553,6 +590,10 @@ export class ModelConfigsRepository extends BaseRepository {
553590 input . apiKeySetting || null ,
554591 input . providerType || 'openai_compatible' ,
555592 input . isEnabled !== false ,
593+ input . billingType || 'pay-per-use' ,
594+ input . subscriptionCostUsd ?? null ,
595+ input . subscriptionPlan ?? null ,
596+ input . billingNotes ?? null ,
556597 JSON . stringify ( input . config || { } ) ,
557598 now ,
558599 now ,
0 commit comments