# 获取妙搭应用消耗 AI 额度

获取妙搭应用消耗 AI 额度

## 请求

基本 | &nbsp;
---|---
HTTP URL | https://open.feishu.cn/open-apis/spark/v1/apps/:app_id/credit_usage
HTTP Method | GET
接口频率限制 | [20 次/秒](https://open.feishu.cn/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
支持的应用类型 | Custom App、Store App
权限要求<br>**调用该 API 所需的权限。开启其中任意一项权限即可调用** | 获取妙搭应用信息(spark:app:read)

### 请求头

名称 | 类型 | 必填 | 描述
---|---|---|---
Authorization | string | 是 | `tenant_access_token`<br>或<br>`user_access_token`<br>**值格式**："Bearer `access_token`"<br>**示例值**："Bearer u-7f1bcd13fc57d46bac21793a18e560"<br>[了解更多：如何选择与获取 access token](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-choose-which-type-of-token-to-use)

### 路径参数

名称 | 类型 | 描述
---|---|---
app_id | string | 应用 ID<br>**示例值**："app_4jbp6bx8fwjgm"

### 查询参数

名称 | 类型 | 必填 | 描述
---|---|---|---
start_time | string | 是 | 时间范围起始时间戳，单位：秒（Unix 时间戳）<br>**示例值**：1717286400
end_time | string | 是 | 时间范围结束时间戳，单位：秒（Unix 时间戳）。须满足 end_time >= start_time<br>**示例值**：1717372800

## 响应

### 响应体

名称 | 类型 | 描述
---|---|---
code | int | 错误码，非 0 表示失败
msg | string | 错误描述
data | \- | \-
total | number(float) | 区间内 by day 数据点的总额度消耗总和
points | open_api_credit_usage_point\[\] | 按天的 AI 消耗量数据点列表，按 timestamp 升序
timestamp | string | 数据点所在自然日的起始时间戳（该自然日 0 点），单位：秒
credit_usage | number(float) | 当日 AI 消耗量（总额度，含企业 + 个人）
credit_usage_enterprise | number(float) | 当日企业额度消耗
credit_usage_personal | number(float) | 当日个人额度消耗
total_enterprise | number(float) | 区间内 by day 数据点的企业额度消耗总和
total_personal | number(float) | 区间内 by day 数据点的个人额度消耗总和

### 响应体示例
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "total": 1250.5,
        "points": [
            {
                "timestamp": "1690848000",
                "credit_usage": 1250.5,
                "credit_usage_enterprise": 820.3,
                "credit_usage_personal": 430.2
            }
        ],
        "total_enterprise": 980.2,
        "total_personal": 270.3
    }
}
```

### 错误码

HTTP状态码 | 错误码 | 描述 | 排查建议
---|---|---|---
400 | 3340001 | Invalid request parameter | 请求参数错误，请检查相关参数是否正确
404 | 3340004 | App not found | appID不存在或无权限查看，请检查填写是否有误。
500 | 3340500 | Internal server error | 服务端异常，请稍后再试

