@@ -303,7 +303,7 @@ def load_router_config(router: Optional[litellm.Router], config_file_path: str):
303303 run_ollama_serve ()
304304 return router , model_list , general_settings
305305
306- async def generate_key_helper_fn (duration_str : str , models : list , aliases : dict , config : dict ):
306+ async def generate_key_helper_fn (duration_str : str , models : list , aliases : dict , config : dict , spend : float ):
307307 token = f"sk-{ secrets .token_urlsafe (16 )} "
308308 def _duration_in_seconds (duration : str ):
309309 match = re .match (r"(\d+)([smhd]?)" , duration )
@@ -336,7 +336,8 @@ def _duration_in_seconds(duration: str):
336336 "expires" : expires ,
337337 "models" : models ,
338338 "aliases" : aliases_json ,
339- "config" : config_json
339+ "config" : config_json ,
340+ "spend" : spend
340341 }
341342 print (f"verification_token_data: { verification_token_data } " )
342343 new_verification_token = await db .litellm_verificationtoken .create ( # type: ignore
@@ -636,8 +637,9 @@ async def generate_key_fn(request: Request):
636637 models = data .get ("models" , []) # Default to an empty list (meaning allow token to call all models)
637638 aliases = data .get ("aliases" , {}) # Default to an empty dict (no alias mappings, on top of anything in the config.yaml model_list)
638639 config = data .get ("config" , {})
640+ spend = data .get ("spend" , 0 )
639641 if isinstance (models , list ):
640- response = await generate_key_helper_fn (duration_str = duration_str , models = models , aliases = aliases , config = config )
642+ response = await generate_key_helper_fn (duration_str = duration_str , models = models , aliases = aliases , config = config , spend = spend )
641643 return {"key" : response ["token" ], "expires" : response ["expires" ]}
642644 else :
643645 raise HTTPException (
0 commit comments