Skip to content

Commit 8291f23

Browse files
committed
(feat) proxy server: add spend column
1 parent 65d9786 commit 8291f23

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

litellm/proxy/proxy_server.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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(

litellm/proxy/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ generator client {
1010
// required for token gen
1111
model LiteLLM_VerificationToken {
1212
token String @unique
13+
spend Float
1314
expires DateTime
1415
models String[]
1516
aliases Json @default("{}")

0 commit comments

Comments
 (0)