tencentcloud-sdk-python-tokenhub 3.1.106__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,426 @@
1
+ # -*- coding: utf8 -*-
2
+ # Copyright (c) 2017-2025 Tencent. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import json
17
+
18
+ from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
19
+ from tencentcloud.common.abstract_client import AbstractClient
20
+ from tencentcloud.tokenhub.v20260322 import models
21
+
22
+
23
+ class TokenhubClient(AbstractClient):
24
+ _apiVersion = '2026-03-22'
25
+ _endpoint = 'tokenhub.tencentcloudapi.com'
26
+ _service = 'tokenhub'
27
+
28
+
29
+ def CreateTokenPlanApiKeys(self, request):
30
+ r"""批量创建 TokenPlan APIKey。
31
+
32
+ 传入名称前缀和数量,自动按 {ApiKeyName}-{序号} 格式生成名称(如 aaa-1, aaa-2)。允许同名。支持部分成功,最多 100 条。
33
+
34
+ :param request: Request instance for CreateTokenPlanApiKeys.
35
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.CreateTokenPlanApiKeysRequest`
36
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.CreateTokenPlanApiKeysResponse`
37
+
38
+ """
39
+ try:
40
+ params = request._serialize()
41
+ headers = request.headers
42
+ body = self.call("CreateTokenPlanApiKeys", params, headers=headers)
43
+ response = json.loads(body)
44
+ model = models.CreateTokenPlanApiKeysResponse()
45
+ model._deserialize(response["Response"])
46
+ return model
47
+ except Exception as e:
48
+ if isinstance(e, TencentCloudSDKException):
49
+ raise
50
+ else:
51
+ raise TencentCloudSDKException(type(e).__name__, str(e))
52
+
53
+
54
+ def CreateTokenPlanTeamOrderAndBuy(self, request):
55
+ r"""购买套餐。
56
+
57
+ 发起 TokenPlan 套餐下单并完成支付,成功后返回大订单 ID 及关联的子订单、资源信息。
58
+
59
+ :param request: Request instance for CreateTokenPlanTeamOrderAndBuy.
60
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.CreateTokenPlanTeamOrderAndBuyRequest`
61
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.CreateTokenPlanTeamOrderAndBuyResponse`
62
+
63
+ """
64
+ try:
65
+ params = request._serialize()
66
+ headers = request.headers
67
+ body = self.call("CreateTokenPlanTeamOrderAndBuy", params, headers=headers)
68
+ response = json.loads(body)
69
+ model = models.CreateTokenPlanTeamOrderAndBuyResponse()
70
+ model._deserialize(response["Response"])
71
+ return model
72
+ except Exception as e:
73
+ if isinstance(e, TencentCloudSDKException):
74
+ raise
75
+ else:
76
+ raise TencentCloudSDKException(type(e).__name__, str(e))
77
+
78
+
79
+ def DeleteTokenPlanApiKey(self, request):
80
+ r"""删除 TokenPlan APIKey。
81
+
82
+ 同时删除额度中心子额度包并通知网关清除缓存。
83
+
84
+ :param request: Request instance for DeleteTokenPlanApiKey.
85
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.DeleteTokenPlanApiKeyRequest`
86
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.DeleteTokenPlanApiKeyResponse`
87
+
88
+ """
89
+ try:
90
+ params = request._serialize()
91
+ headers = request.headers
92
+ body = self.call("DeleteTokenPlanApiKey", params, headers=headers)
93
+ response = json.loads(body)
94
+ model = models.DeleteTokenPlanApiKeyResponse()
95
+ model._deserialize(response["Response"])
96
+ return model
97
+ except Exception as e:
98
+ if isinstance(e, TencentCloudSDKException):
99
+ raise
100
+ else:
101
+ raise TencentCloudSDKException(type(e).__name__, str(e))
102
+
103
+
104
+ def DescribeApiKey(self, request):
105
+ r"""根据 API 密钥 ID 或密钥值查询 API 密钥详情,返回明文密钥。ApiKeyId 和 ApiKey 至少需传入其一,优先使用 ApiKeyId。
106
+
107
+ :param request: Request instance for DescribeApiKey.
108
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.DescribeApiKeyRequest`
109
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.DescribeApiKeyResponse`
110
+
111
+ """
112
+ try:
113
+ params = request._serialize()
114
+ headers = request.headers
115
+ body = self.call("DescribeApiKey", params, headers=headers)
116
+ response = json.loads(body)
117
+ model = models.DescribeApiKeyResponse()
118
+ model._deserialize(response["Response"])
119
+ return model
120
+ except Exception as e:
121
+ if isinstance(e, TencentCloudSDKException):
122
+ raise
123
+ else:
124
+ raise TencentCloudSDKException(type(e).__name__, str(e))
125
+
126
+
127
+ def DescribeApiKeyList(self, request):
128
+ r"""查询 API 密钥列表。
129
+
130
+ 查询当前用户的 API 密钥列表,密钥值脱敏展示。支持分页、过滤和排序。
131
+
132
+ :param request: Request instance for DescribeApiKeyList.
133
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.DescribeApiKeyListRequest`
134
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.DescribeApiKeyListResponse`
135
+
136
+ """
137
+ try:
138
+ params = request._serialize()
139
+ headers = request.headers
140
+ body = self.call("DescribeApiKeyList", params, headers=headers)
141
+ response = json.loads(body)
142
+ model = models.DescribeApiKeyListResponse()
143
+ model._deserialize(response["Response"])
144
+ return model
145
+ except Exception as e:
146
+ if isinstance(e, TencentCloudSDKException):
147
+ raise
148
+ else:
149
+ raise TencentCloudSDKException(type(e).__name__, str(e))
150
+
151
+
152
+ def DescribeTokenPlan(self, request):
153
+ r"""查询 TokenPlan 套餐详情。
154
+
155
+ 返回套餐基本信息及额度中心主额度包余量。
156
+
157
+ :param request: Request instance for DescribeTokenPlan.
158
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanRequest`
159
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanResponse`
160
+
161
+ """
162
+ try:
163
+ params = request._serialize()
164
+ headers = request.headers
165
+ body = self.call("DescribeTokenPlan", params, headers=headers)
166
+ response = json.loads(body)
167
+ model = models.DescribeTokenPlanResponse()
168
+ model._deserialize(response["Response"])
169
+ return model
170
+ except Exception as e:
171
+ if isinstance(e, TencentCloudSDKException):
172
+ raise
173
+ else:
174
+ raise TencentCloudSDKException(type(e).__name__, str(e))
175
+
176
+
177
+ def DescribeTokenPlanApiKey(self, request):
178
+ r"""查询 TokenPlan APIKey 详情。
179
+
180
+ 返回 APIKey 完整信息(含明文密钥)及子额度包余量。
181
+
182
+ :param request: Request instance for DescribeTokenPlanApiKey.
183
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanApiKeyRequest`
184
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanApiKeyResponse`
185
+
186
+ """
187
+ try:
188
+ params = request._serialize()
189
+ headers = request.headers
190
+ body = self.call("DescribeTokenPlanApiKey", params, headers=headers)
191
+ response = json.loads(body)
192
+ model = models.DescribeTokenPlanApiKeyResponse()
193
+ model._deserialize(response["Response"])
194
+ return model
195
+ except Exception as e:
196
+ if isinstance(e, TencentCloudSDKException):
197
+ raise
198
+ else:
199
+ raise TencentCloudSDKException(type(e).__name__, str(e))
200
+
201
+
202
+ def DescribeTokenPlanApiKeyList(self, request):
203
+ r"""查询 TokenPlan APIKey 列表。
204
+
205
+ 返回指定套餐下的 APIKey 列表,密钥已脱敏。主账号可查看全部,子账号仅可查看自己创建的。
206
+
207
+ :param request: Request instance for DescribeTokenPlanApiKeyList.
208
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanApiKeyListRequest`
209
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanApiKeyListResponse`
210
+
211
+ """
212
+ try:
213
+ params = request._serialize()
214
+ headers = request.headers
215
+ body = self.call("DescribeTokenPlanApiKeyList", params, headers=headers)
216
+ response = json.loads(body)
217
+ model = models.DescribeTokenPlanApiKeyListResponse()
218
+ model._deserialize(response["Response"])
219
+ return model
220
+ except Exception as e:
221
+ if isinstance(e, TencentCloudSDKException):
222
+ raise
223
+ else:
224
+ raise TencentCloudSDKException(type(e).__name__, str(e))
225
+
226
+
227
+ def DescribeTokenPlanApiKeySecret(self, request):
228
+ r"""查询 TokenPlan APIKey 密钥(明文)。
229
+
230
+ 返回指定 APIKey 的明文密钥值,请妥善保管。
231
+
232
+ :param request: Request instance for DescribeTokenPlanApiKeySecret.
233
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanApiKeySecretRequest`
234
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanApiKeySecretResponse`
235
+
236
+ """
237
+ try:
238
+ params = request._serialize()
239
+ headers = request.headers
240
+ body = self.call("DescribeTokenPlanApiKeySecret", params, headers=headers)
241
+ response = json.loads(body)
242
+ model = models.DescribeTokenPlanApiKeySecretResponse()
243
+ model._deserialize(response["Response"])
244
+ return model
245
+ except Exception as e:
246
+ if isinstance(e, TencentCloudSDKException):
247
+ raise
248
+ else:
249
+ raise TencentCloudSDKException(type(e).__name__, str(e))
250
+
251
+
252
+ def DescribeTokenPlanApiKeyUsageDetail(self, request):
253
+ r"""查询 TokenPlan APIKey 调用明细。
254
+
255
+ 从 CLS 日志服务查询套餐下的调用明细,按 pkg_id 过滤,支持游标分页。
256
+
257
+ :param request: Request instance for DescribeTokenPlanApiKeyUsageDetail.
258
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanApiKeyUsageDetailRequest`
259
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanApiKeyUsageDetailResponse`
260
+
261
+ """
262
+ try:
263
+ params = request._serialize()
264
+ headers = request.headers
265
+ body = self.call("DescribeTokenPlanApiKeyUsageDetail", params, headers=headers)
266
+ response = json.loads(body)
267
+ model = models.DescribeTokenPlanApiKeyUsageDetailResponse()
268
+ model._deserialize(response["Response"])
269
+ return model
270
+ except Exception as e:
271
+ if isinstance(e, TencentCloudSDKException):
272
+ raise
273
+ else:
274
+ raise TencentCloudSDKException(type(e).__name__, str(e))
275
+
276
+
277
+ def DescribeTokenPlanList(self, request):
278
+ r"""查询 TokenPlan 套餐列表。
279
+
280
+ 支持分页、过滤和排序。主账号可查看全部,子账号仅可查看自己创建的。返回结果包含每个套餐关联的额度中心主额度包详情。
281
+
282
+ :param request: Request instance for DescribeTokenPlanList.
283
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanListRequest`
284
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.DescribeTokenPlanListResponse`
285
+
286
+ """
287
+ try:
288
+ params = request._serialize()
289
+ headers = request.headers
290
+ body = self.call("DescribeTokenPlanList", params, headers=headers)
291
+ response = json.loads(body)
292
+ model = models.DescribeTokenPlanListResponse()
293
+ model._deserialize(response["Response"])
294
+ return model
295
+ except Exception as e:
296
+ if isinstance(e, TencentCloudSDKException):
297
+ raise
298
+ else:
299
+ raise TencentCloudSDKException(type(e).__name__, str(e))
300
+
301
+
302
+ def DescribeUsageRankList(self, request):
303
+ r"""查询用量排行列表。
304
+
305
+ 按 apikey、endpoint、model 三个维度统计指定时间窗内的用量排行,返回顶部数据卡所需的 PageStats/TotalStats、左侧 Top 列表(含每对象整段累计值)、右侧色块趋势图所需的逐点曲线。前端通过 Offset 翻页、ShowAll 切换 CSV 全量导出模式。
306
+
307
+ MetricType 字段用于切换指标族,本期支持 tokens;接口预留以支持后续指标族扩展。响应回显 MetricType 与 MetricKeys(实际参与渲染的 metric key 列表,顺序固定 [Total, Input, Output]),前端按此渲染顶部数据卡与趋势图,无需硬编码 key 名。
308
+
309
+ :param request: Request instance for DescribeUsageRankList.
310
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.DescribeUsageRankListRequest`
311
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.DescribeUsageRankListResponse`
312
+
313
+ """
314
+ try:
315
+ params = request._serialize()
316
+ headers = request.headers
317
+ body = self.call("DescribeUsageRankList", params, headers=headers)
318
+ response = json.loads(body)
319
+ model = models.DescribeUsageRankListResponse()
320
+ model._deserialize(response["Response"])
321
+ return model
322
+ except Exception as e:
323
+ if isinstance(e, TencentCloudSDKException):
324
+ raise
325
+ else:
326
+ raise TencentCloudSDKException(type(e).__name__, str(e))
327
+
328
+
329
+ def ModifyTokenPlanApiKey(self, request):
330
+ r"""修改 TokenPlan APIKey 配置(网关关注字段)。
331
+
332
+ 修改后自动通知网关更新缓存并同步额度中心。
333
+
334
+ :param request: Request instance for ModifyTokenPlanApiKey.
335
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.ModifyTokenPlanApiKeyRequest`
336
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.ModifyTokenPlanApiKeyResponse`
337
+
338
+ """
339
+ try:
340
+ params = request._serialize()
341
+ headers = request.headers
342
+ body = self.call("ModifyTokenPlanApiKey", params, headers=headers)
343
+ response = json.loads(body)
344
+ model = models.ModifyTokenPlanApiKeyResponse()
345
+ model._deserialize(response["Response"])
346
+ return model
347
+ except Exception as e:
348
+ if isinstance(e, TencentCloudSDKException):
349
+ raise
350
+ else:
351
+ raise TencentCloudSDKException(type(e).__name__, str(e))
352
+
353
+
354
+ def ModifyTokenPlanApiKeySecret(self, request):
355
+ r"""重置 TokenPlan APIKey 密钥。
356
+
357
+ 重新生成密钥值,密钥版本号递增,旧密钥立即失效。APIKey ID 不变。重置后需通过 DescribeTokenPlanApiKeySecret 查询新密钥。
358
+
359
+ :param request: Request instance for ModifyTokenPlanApiKeySecret.
360
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.ModifyTokenPlanApiKeySecretRequest`
361
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.ModifyTokenPlanApiKeySecretResponse`
362
+
363
+ """
364
+ try:
365
+ params = request._serialize()
366
+ headers = request.headers
367
+ body = self.call("ModifyTokenPlanApiKeySecret", params, headers=headers)
368
+ response = json.loads(body)
369
+ model = models.ModifyTokenPlanApiKeySecretResponse()
370
+ model._deserialize(response["Response"])
371
+ return model
372
+ except Exception as e:
373
+ if isinstance(e, TencentCloudSDKException):
374
+ raise
375
+ else:
376
+ raise TencentCloudSDKException(type(e).__name__, str(e))
377
+
378
+
379
+ def RenewTokenPlanTeamOrder(self, request):
380
+ r"""续费套餐。
381
+
382
+ 对已有的 TokenPlan 套餐发起续费下单并完成支付,成功后返回大订单 ID 及关联的子订单、资源信息。
383
+
384
+ :param request: Request instance for RenewTokenPlanTeamOrder.
385
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.RenewTokenPlanTeamOrderRequest`
386
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.RenewTokenPlanTeamOrderResponse`
387
+
388
+ """
389
+ try:
390
+ params = request._serialize()
391
+ headers = request.headers
392
+ body = self.call("RenewTokenPlanTeamOrder", params, headers=headers)
393
+ response = json.loads(body)
394
+ model = models.RenewTokenPlanTeamOrderResponse()
395
+ model._deserialize(response["Response"])
396
+ return model
397
+ except Exception as e:
398
+ if isinstance(e, TencentCloudSDKException):
399
+ raise
400
+ else:
401
+ raise TencentCloudSDKException(type(e).__name__, str(e))
402
+
403
+
404
+ def UpgradeTokenPlanTeamOrder(self, request):
405
+ r"""升配套餐。
406
+
407
+ 对已有的 TokenPlan 套餐发起升配下单并完成支付,扩容积分或 Token 额度,成功后返回大订单 ID 及关联的子订单、资源信息。新额度必须大于当前额度。
408
+
409
+ :param request: Request instance for UpgradeTokenPlanTeamOrder.
410
+ :type request: :class:`tencentcloud.tokenhub.v20260322.models.UpgradeTokenPlanTeamOrderRequest`
411
+ :rtype: :class:`tencentcloud.tokenhub.v20260322.models.UpgradeTokenPlanTeamOrderResponse`
412
+
413
+ """
414
+ try:
415
+ params = request._serialize()
416
+ headers = request.headers
417
+ body = self.call("UpgradeTokenPlanTeamOrder", params, headers=headers)
418
+ response = json.loads(body)
419
+ model = models.UpgradeTokenPlanTeamOrderResponse()
420
+ model._deserialize(response["Response"])
421
+ return model
422
+ except Exception as e:
423
+ if isinstance(e, TencentCloudSDKException):
424
+ raise
425
+ else:
426
+ raise TencentCloudSDKException(type(e).__name__, str(e))