MCPcopy Create free account
hub / github.com/THESIS-AGENT/AIRouter / notice_api_key_usage

Method notice_api_key_usage

api_key_manager/client.py:41–110  ·  view source on GitHub ↗

通知服务关于API密钥的使用情况。 参数: api_key: 使用的API密钥 model_name: 模型名称 source_name: 接口供应商名称 create_time: 请求开始时间 finish_time: 请求完成时间 execution_time: 执行时间(秒) status: 请求是否成功 prompt_tokens: 输入令牌数量(可选)

(
        self, 
        api_key: str, 
        model_name: str, 
        source_name: str, 
        create_time: Union[datetime, str],
        finish_time: Union[datetime, str],
        execution_time: float,
        status: bool,
        prompt_tokens: Optional[int] = None,
        completion_tokens: Optional[int] = None,
        request_id: Optional[str] = None,
        remark: Optional[str] = ""
    )

Source from the content-addressed store, hash-verified

39 return None
40
41 def notice_api_key_usage(
42 self,
43 api_key: str,
44 model_name: str,
45 source_name: str,
46 create_time: Union[datetime, str],
47 finish_time: Union[datetime, str],
48 execution_time: float,
49 status: bool,
50 prompt_tokens: Optional[int] = None,
51 completion_tokens: Optional[int] = None,
52 request_id: Optional[str] = None,
53 remark: Optional[str] = ""
54 ) -> bool:
55 """通知服务关于API密钥的使用情况。
56
57 参数:
58 api_key: 使用的API密钥
59 model_name: 模型名称
60 source_name: 接口供应商名称
61 create_time: 请求开始时间
62 finish_time: 请求完成时间
63 execution_time: 执行时间(秒)
64 status: 请求是否成功
65 prompt_tokens: 输入令牌数量(可选)
66 completion_tokens: 输出令牌数量(可选)
67 request_id: 自定义请求ID(可选,如果未提供将生成UUID)
68 remark: 备注信息,用于记录API调用的用途或来源(可选)
69
70 返回:
71 通知是否成功
72 """
73 if request_id is None:
74 request_id = str(uuid.uuid4())
75
76 # 将datetime对象转换为ISO格式字符串
77 if isinstance(create_time, datetime):
78 create_time = create_time.isoformat()
79 if isinstance(finish_time, datetime):
80 finish_time = finish_time.isoformat()
81
82 # 构建载荷
83 payload = {
84 "request_id": request_id,
85 "api_key": api_key,
86 "model_name": model_name,
87 "source_name": source_name,
88 "create_time": create_time,
89 "finish_time": finish_time,
90 "execution_time": execution_time,
91 "status": status,
92 "remark": remark or ""
93 }
94
95 # 如果提供了可选字段,则添加
96 if prompt_tokens is not None:
97 payload["prompt_tokens"] = prompt_tokens
98 if completion_tokens is not None:

Callers 1

runMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected