# 查询 AI 用量定价

Operation / SDK: `readAiPricing` · `read_ai_pricing` · `ReadAiPricing`

读取 AI 用量 Feature 的定价配置与模型加价。

更新于 2026-11-06

[网页版本](https://www.longplayai.com/zh-hans/docs/api/read-ai-pricing)

<a id="request"></a>

## 请求

- **凭据**: Server Key，权限 `credits:read`。只在后端调用。
- **SDK**: JavaScript `createLongplayServer().readAiPricing` · Python `read_ai_pricing` · Go `ReadAiPricing`
- **成功状态**: HTTP 200

响应为示例数据。

**cURL: request.sh**

```bash
curl -X POST "$LONGPLAY_API_URL/api/v1/ai/pricing/read" \
  -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \
  -H "X-Indiana-Protocol: 0.10" \
  -H "Content-Type: application/json" \
  -d '{
  "internal_feature_id": "f317c851-0ef2-4d7a-8e3c-e8a29df676ed"
}'
```

**TypeScript: readAiPricing.ts**

```ts
import { createLongplayServer } from "@tinkerlandai/longplay-sdk/server";

const longplay = createLongplayServer({
  baseUrl: process.env.LONGPLAY_API_URL!,
  apiKey: process.env.LONGPLAY_SERVER_KEY!,
  scope: { projectId: process.env.LONGPLAY_PROJECT_ID!, environment: "sandbox" },
});

export async function readAiPricing() {
  return longplay.readAiPricing({
    internal_feature_id: "f317c851-0ef2-4d7a-8e3c-e8a29df676ed",
  });
}
```

**请求体: request.json**

```json
{
  "internal_feature_id": "f317c851-0ef2-4d7a-8e3c-e8a29df676ed"
}
```

**响应示例: response.json**

```json
{
  "requestId": "44f5fcb8-6ed8-41b8-818f-7571941c5fd5",
  "scope": {
    "projectId": "df5426d6-b335-403c-8f3e-b0f73d2e3511",
    "environment": "sandbox"
  },
  "internal_feature_id": "f317c851-0ef2-4d7a-8e3c-e8a29df676ed",
  "config": {
    "schema": []
  }
}
```

<a id="parameters"></a>

## 请求体参数

**application/json**

- `internal_feature_id` (uuid, required): Feature 的 ID。
- `customerId` (uuid, optional): Customer 的 UUID。
- `entityId` (uuid, optional): 当前客户范围内的 Entity ID；只用于已配置的 Entity 和许可 Feature。

<a id="response"></a>

## 响应字段

成功响应都包含 `requestId`（本次请求 ID，排查时提供）和 `scope`（App 与环境）。

**HTTP 200 · application/json**

- `requestId` (uuid, required): 服务端为这次 HTTP 请求生成的 UUID，排查时提供；它不是你的业务 requestId。
- `scope` (object, required): 响应实际所属的 App 和环境。Header 只能核对，不能切换 Key 范围。
- `scope.projectId` (string, required): 凭据绑定的 App ID。 minLength: 1
- `scope.environment` (enum, required): 独立数据范围：sandbox 或 live。 Values: `"sandbox"`, `"live"`.
- `internal_feature_id` (uuid, required): Feature 的 ID。
- `config` (object, required): 配置。
- `config.schema` (array, required): 按计量 Feature 设置的积分费率。AI 积分 Feature 按模型 token 成本和加价计价，此数组始终为空。 minItems: 0 · maxItems: 0
- `config.schema.metered_feature_id` (string | string, required): 该费率所计价的计量 Feature 的 key。
- `config.schema.feature_amount` (number | number, optional): 花费 `credit_amount` 个积分所对应的计量 Feature 单位数；默认为 1。
- `config.schema.dimensions` (object | object, optional): 按维度名称索引的替代费率。`match` 与用量属性相符的维度（匹配键最多者优先，其次 `priority` 最高）取代基础费率。
- `config.schema.multipliers` (object | object, optional): 按名称索引的调整规则；`match` 与用量属性相符的每条规则都会把积分数乘以 `factor` 并加上 `add`。
- `config.schema.credit_amount` (number | object, optional): 积分数量。
- `config.schema.tier_behavior` (object | "graduated", optional): 使用 `tiers` 时为 `graduated`：每一档 `to` 以内的单位按该档的 `credit_amount` 计费。固定费率时不出现。
- `config.schema.tiers` (object | array, optional): 阶梯价格档位。
- `config.schema.tiers.to` (number | "inf", required): 时间范围终点（ISO 8601）。
- `config.schema.tiers.credit_amount` (number, required): 积分数量。
- `config.invoice_credit` (boolean, optional): 是否把积分当作分项用量发票上的计费货币（1 个积分等于 1 个货币单位）；省略时为 `false`。
- `config.usage_type` (enum, optional): 积分 Feature 始终为 `single_use`：积分消耗后即用完。`continuous_use` 表示席位这类持续占用，不适用于此处。 default: "single_use" Values: `"single_use"`, `"continuous_use"`.
- `config.default_markup` (number, optional): 模型及其提供方都未单独设置加价时，对模型 token 成本使用的加价百分比；例如 `20` 加价 20%，`-50` 使成本减半。省略时为 0。 min: -100
- `config.provider_markups` (object | null, optional): 按模型提供方（模型 ID 中 `/` 之前的部分）索引的加价百分比，格式为 `{ markup }`；模型未单独设置加价时使用。未设置时为 `null`。
- `model_markups` (object | null, optional): 按模型 ID（`provider/model`）索引的模型级覆盖：`markup` 加价百分比，以及以美元／百万 token 计的自定义 `input_cost`／`output_cost`。未设置时为 `null`；传入 `customerId` 时反映该 Customer（或 Entity）的生效价格。

<a id="errors"></a>

## 错误

失败时返回错误对象，按 `error.code` 与 `error.recovery` 处理。下表是这个接口的凭据、作用域和幂等字段决定的错误；视请求内容还可能返回 `NOT_FOUND`（引用的资源不存在）、`NOT_CONFIGURED`（所需的集成未连接）或 `PAYLOAD_TOO_LARGE`。有些拒绝（如余额不足）不是错误，而是成功响应里的 `reason`。

**可能的错误**

| code | HTTP | 何时 | recovery |
| --- | --- | --- | --- |
| `INVALID_REQUEST` | 400 | 请求不符合本页的参数。缺少或无法解析协议头时分别返回 `UNSUPPORTED_PROTOCOL_VERSION` 或 `INVALID_PROTOCOL_VERSION`。 | `fix_request` |
| `UNAUTHENTICATED` | 401 | 凭据缺失、无效、过期或已撤销。 | `authenticate` |
| `FORBIDDEN` | 403 | 凭据没有 `credits:read` 权限。 | `check_permissions` |
| `SCOPE_MISMATCH` | 403 | `X-Indiana-Project` 或 `X-Indiana-Environment` 与凭据所属的 App 和环境不一致。 | `check_scope` |
| `RATE_LIMITED` | 429 | 请求过多；按 `Retry-After` 等待后用同一请求重试。 | `retry_same_request` |
| `SERVICE_UNAVAILABLE` | 503 | 服务暂时不可用；用同一请求重试。 | `retry_same_request` |
| `INTERNAL_ERROR` | 500 | 结果未知；稍后重试。 | `recover_operation` |

- [错误码与恢复](https://www.longplayai.com/zh-hans/docs/api/errors.md)
- [请求约定](https://www.longplayai.com/zh-hans/docs/api.md)
- [全部接口](https://www.longplayai.com/zh-hans/docs/api/operations.md#ai)
