管理员定价 — TypeScript SDK
模型定价:平台模型目录、客户专属价格、上架状态、折扣和计价因子。
概览
管理员 Pricing 资源管理模型的展示和定价,覆盖两层:
- 平台目录:管理员可以为整个租户上架、下架和定价的模型。
- 客户专属价格:针对单个终端客户的模型价格、上架状态和百分比折扣。
通过 admin.pricing 访问。
部分读取方法需要 partnerId,即管理员的合作伙伴 ID,可通过 admin.auth.info() 获取。
可用操作
| 方法 | 说明 |
|---|---|
listProviderModels() | 查询平台模型目录,支持分页和筛选 |
saveProviderModel() | 创建或更新平台模型 |
setProviderModelListed() | 上架或下架平台模型 |
updateProviderModelPrice() | 设置平台模型的价格配置 |
listPriceFactors() | 查询计价因子及单位 |
listUserModelPrices() | 查询客户的各模型价格 |
saveUserModelPrice() | 创建或覆盖客户的模型价格 |
setUserModelListed() | 为客户上架或下架模型 |
setDiscount() | 为客户模型应用百分比折扣 |
listProviderModels
查询平台模型目录,支持分页和筛选。后端要求提供 partnerId。
使用示例
const { partnerId } = await admin.auth.info();
const page = await admin.pricing.listProviderModels({ partnerId, pageNum: 1, pageSize: 20 });
console.log(`total: ${page.total}`);
for (const m of page.list) {
console.log(m.id, m.modelId, m.provider, m.resaleStatus);
}
按模型类型筛选:
const page = await admin.pricing.listProviderModels({ partnerId, modelType: 'LLM' });
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| partnerId | number | 是 | -- | 管理员的合作伙伴 ID,来自 auth.info() |
| modelType | string | 否 | -- | 按模型类型筛选 |
| pageNum | number | 否 | -- | 页码,从 1 开始 |
| pageSize | number | 否 | -- | 每页条数 |
后端支持的其他筛选条件可原样透传。
响应
返回包含 total、list、totalPages、currentPage、pageSize 的分页对象。每条记录提供 id、modelId、modelType、provider、providerName、endpoint、resaleStatus、sortNum、priceExtend 及相关目录字段。
错误
| 代码 | 异常 | 发生条件 |
|---|---|---|
1001 | ValidationError | 缺少 partnerId |
2007 | PermissionError | 管理员缺少定价管理权限 |
3001 | AuthenticationError | 会话过期且刷新失败 |
saveProviderModel
创建或更新平台模型。请求体原样透传;包含 id 时,更新对应模型。
使用示例
// Update the sort order of an existing catalog entry, preserving other fields
const [entry] = (await admin.pricing.listProviderModels({ partnerId, pageSize: 1 })).list;
const ok = await admin.pricing.saveProviderModel({ ...entry, sortNum: 5 });
console.log(ok); // true
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| body | object | 是 | -- | 模型目录数据;更新现有条目时包含 id |
响应
返回 boolean,成功时为 true。
错误
| 代码 | 异常 | 发生条件 |
|---|---|---|
1001 | ValidationError | 请求体格式错误或不完整 |
2007 | PermissionError | 管理员缺少定价管理权限 |
3001 | AuthenticationError | 会话过期且刷新失败 |
setProviderModelListed
上架或下架平台模型。resaleStatus 为平台上架状态码。
使用示例
const ok = await admin.pricing.setProviderModelListed(1490, 1);
console.log(ok); // true
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| id | number | 是 | -- | 模型 ID(位置参数) |
| resaleStatus | number | 是 | -- | 上架状态码(位置参数) |
响应
返回 boolean,成功时为 true。
错误
| 代码 | 异常 | 发生条件 |
|---|---|---|
2007 | PermissionError | 管理员缺少定价管理权限 |
3001 | AuthenticationError | 会话过期且刷新失败 |
updateProviderModelPrice
设置平台模型的价格配置。请求体原样透传。
使用示例
const ok = await admin.pricing.updateProviderModelPrice({ id: 1490, priceExtend: { /* ... */ } });
console.log(ok); // true
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| body | object | 是 | -- | 目标模型的价格配置数据 |
响应
返回 boolean,成功时为 true。
错误
| 代码 | 异常 | 发生条件 |
|---|---|---|
1001 | ValidationError | 价格数据格式错误 |
2007 | PermissionError | 管理员缺少定价管理权限 |
3001 | AuthenticationError | 会话过期且刷新失败 |
listPriceFactors
查询计价因子及单位。提供 modelType 时,结果限定为该类型。
使用示例
const factors = await admin.pricing.listPriceFactors();
console.log(factors);
// Scoped to a model type
const llmFactors = await admin.pricing.listPriceFactors('LLM');
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| modelType | string | 否 | -- | 将计价因子范围限定为某模型类型(位置参数) |
响应
返回计价因子条目数组。
错误
| 代码 | 异常 | 发生条件 |
|---|---|---|
2007 | PermissionError | 管理员缺少定价管理权限 |
3001 | AuthenticationError | 会话过期且刷新失败 |
listUserModelPrices
分页查询客户的各模型价格。后端要求提供 partnerId。
使用示例
const page = await admin.pricing.listUserModelPrices({
partnerId, userId: 42, pageNum: 1, pageSize: 20,
});
for (const row of page.list) {
console.log(row);
}
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| partnerId | number | 是 | -- | 管理员的合作伙伴 ID,来自 auth.info() |
| userId | number | 否 | -- | 目标客户 ID |
| pageNum | number | 否 | -- | 页码,从 1 开始 |
| pageSize | number | 否 | -- | 每页条数 |
响应
返回包含 total、list、totalPages、currentPage、pageSize 的分页对象。
错误
| 代码 | 异常 | 发生条件 |
|---|---|---|
1001 | ValidationError | 缺少 partnerId |
2007 | PermissionError | 管理员缺少定价管理权限 |
3001 | AuthenticationError | 会话过期且刷新失败 |
saveUserModelPrice
创建或覆盖客户的模型价格。请求体原样透传。
使用示例
const ok = await admin.pricing.saveUserModelPrice({
userId: 42,
partnerId,
modelId: 1490,
});
console.log(ok); // true
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| body | object | 是 | -- | 客户专属价格数据 |
响应
返回 boolean,成功时为 true。
错误
| 代码 | 异常 | 发生条件 |
|---|---|---|
1001 | ValidationError | 请求体格式错误 |
2007 | PermissionError | 管理员缺少定价管理权限 |
3001 | AuthenticationError | 会话过期且刷新失败 |
setUserModelListed
为指定客户上架或下架模型。resaleStatus 为上架状态码。
使用示例
const ok = await admin.pricing.setUserModelListed(880, 1);
console.log(ok); // true
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| id | number | 是 | -- | 用户模型价格 ID(位置参数) |
| resaleStatus | number | 是 | -- | 上架状态码(位置参数) |
响应
返回 boolean,成功时为 true。
错误
| 代码 | 异常 | 发生条件 |
|---|---|---|
2007 | PermissionError | 管理员缺少定价管理权限 |
3001 | AuthenticationError | 会话过期且刷新失败 |
setDiscount
为客户模型应用百分比折扣。discount 为字符串,"10" 表示减免 10%。
使用示例
const ok = await admin.pricing.setDiscount({
partnerId,
userId: 42,
discount: '10',
modelIds: [1490, 1491],
});
console.log(ok); // true
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| partnerId | number | 否 | -- | 目标合作伙伴 ID |
| userId | number | 否 | -- | 目标客户 ID |
| discount | string | 是 | -- | 百分比字符串,例如 "10" 表示减免 10% |
| modelIds | number[] | 是 | -- | 应用折扣的模型 ID 列表 |
响应
返回 boolean,成功时为 true。
错误
| 代码 | 异常 | 发生条件 |
|---|---|---|
1001 | ValidationError | modelIds 为空或 discount 无效 |
2007 | PermissionError | 管理员缺少定价管理权限 |
3001 | AuthenticationError | 会话过期且刷新失败 |
| 服务器 4xx | WltError | 目标模型未上架,或未配置标准价格 |