# 查询上游调用明细

检查账号的 UTC 日汇总、费用报告和可按条件过滤的供应商请求明细。

GET `/api/settings/usage`

- **认证** 控制台会话 Cookie。
- **成功状态** `200`
- **分页** 通过 page 指定页号。超出范围时返回最后一页，空结果返回第 1 页。

## 请求参数

| 参数 | 类型 | 位置 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| `from` | YYYY-MM-DD | `query` | 否 | 起始 UTC 日期（含当天），默认结束日期往前 29 天。 |
| `to` | YYYY-MM-DD | `query` | 否 | 结束 UTC 日期（含当天），默认今天。 |
| `page` | integer | `query` | 否 | 页号从 1 开始，默认 1。 |
| `task` | rednote \| douyin \| channels \| catalog | `query` | 否 | 筛选平台任务，可重复提供 task 以匹配多个任务。 |
| `status` | succeeded \| failed \| pending | `query` | 否 | 仅筛选指定状态的明细。 |
| `provider` | tikhub \| dataxapi \| socialtoai | `query` | 否 | 仅筛选指定供应商的明细。 |
| `entryPoint` | workbench \| api \| mcp | `query` | 否 | 按调用入口筛选。 |
| `apiKey` | string | `query` | 否 | 仅筛选指定 Key ID，或用 session 筛选通过会话发起的记录。 |
| `export` | csv | `query` | 否 | 提供 csv 时返回 CSV。须填写同一月份内的 from 和 to，筛选项适用于导出的请求。 |
| `requestId` | string | `query` | 否 | 匹配本服务或供应商请求 ID，1–128 个字母、数字、点、下划线或连字符。 |

## 请求示例

JavaScript 示例可在本站已登录的浏览器中运行。cURL 和 Python 示例读取你本机的 cookies.txt Cookie 文件。请将会话 Cookie 视为私密凭据。

**cURL**

```bash
curl -i -X GET 'https://social2api.com/api/settings/usage?from=2026-01-15&to=2026-01-15&task=rednote&page=1' \
  --cookie ./cookies.txt
```

**Python**

```python
from urllib.error import HTTPError
from urllib.request import Request, HTTPCookieProcessor, build_opener
from http.cookiejar import MozillaCookieJar

request = Request(
    "https://social2api.com/api/settings/usage?from=2026-01-15&to=2026-01-15&task=rednote&page=1",
    method="GET",
)
cookies = MozillaCookieJar("./cookies.txt")
cookies.load(ignore_discard=True)
send = build_opener(HTTPCookieProcessor(cookies)).open
try:
    with send(request) as response:
        print(response.status, response.read().decode("utf-8"))
except HTTPError as error:
    print(error.code, error.read().decode("utf-8"))
```

**JavaScript**

```javascript
const response = await fetch("/api/settings/usage?from=2026-01-15&to=2026-01-15&task=rednote&page=1", {
  method: "GET",
  credentials: "same-origin",
});
console.log(response.status, await response.text());
```

## 响应

**200 · 示例响应**

```json
{
  "from": "2026-01-15",
  "to": "2026-01-15",
  "today": "2026-01-15",
  "detailCoverageSince": "2026-01-15T12:00:00.000Z",
  "days": [
    {
      "day": "2026-01-15",
      "used": 0
    }
  ],
  "tasks": [],
  "billing": {
    "credits": {
      "total": 0,
      "reportedRequests": 0,
      "eligibleRequests": 0,
      "days": [],
      "tasks": []
    },
    "usd": {
      "total": 0,
      "reportedRequests": 0,
      "eligibleRequests": 0,
      "days": [],
      "tasks": []
    }
  },
  "outcomes": {
    "failedUnbilled": 0,
    "failedBilled": 0,
    "failedUnknown": 0
  },
  "endpoints": [],
  "apiKeys": [],
  "requests": [],
  "pagination": {
    "page": 1,
    "pageSize": 25,
    "total": 0
  }
}
```

**CSV**

```csv
started_at_utc,platform,provider,endpoint,parameter_fields,api_key_id,api_key_name,entry_point,status,http_status,duration_ms,result_count,socialtoai_credits,dataxapi_cost_usd,request_id,provider_request_id
```

**错误示例**

```json
{
  "error": "请先登录。"
}
```

`from=2026-01-01&to=2026-01-31&export=csv` · CSV 返回同月范围内匹配筛选条件的全部上游明细，含 UTF-8 BOM 和附件响应头。

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `from` | YYYY-MM-DD | 此次统计的起始 UTC 日期。 |
| `to` | YYYY-MM-DD | 此次统计的结束 UTC 日期。 |
| `today` | YYYY-MM-DD | 请求发出当天的 UTC 日期。 |
| `detailCoverageSince` | ISO 8601 date-time | 逐调用明细开始记录的时间。 |
| `days[].day` | YYYY-MM-DD | 汇总所属 UTC 日期。 |
| `days[].used` | integer | 日期内的上游尝试数。 |
| `tasks[].task` | rednote \| douyin \| channels \| catalog | 汇总对应的平台任务。 |
| `tasks[].requests` | integer | 该任务的上游调用次数。 |
| `tasks[].succeeded` | integer | 成功次数。 |
| `tasks[].failed` | integer | 失败次数。 |
| `tasks[].pending` | integer | 尚未记录最终结果的次数。 |
| `billing.credits` | object | 供应商报告的积分费用汇总。 |
| `billing.credits.total` | integer | 已报告的费用合计。 |
| `billing.credits.reportedRequests` | integer | 收到费用值的请求数。 |
| `billing.credits.eligibleRequests` | integer | 该单位对应供应商的请求数。 |
| `billing.credits.days[].day` | YYYY-MM-DD | 费用对应的 UTC 日期。 |
| `billing.credits.days[].amount` | integer | 该 UTC 日供应商报告的费用。 |
| `billing.credits.tasks[].task` | rednote \| douyin \| channels \| catalog | 费用对应的平台任务。 |
| `billing.credits.tasks[].amount` | integer | 该任务供应商报告的费用。 |
| `billing.usd` | object | 供应商报告的费用汇总，单位为百万分之一美元。 |
| `billing.usd.total` | integer | 已报告的费用合计。 |
| `billing.usd.reportedRequests` | integer | 收到费用值的请求数。 |
| `billing.usd.eligibleRequests` | integer | 该单位对应供应商的请求数。 |
| `billing.usd.days[].day` | YYYY-MM-DD | 费用对应的 UTC 日期。 |
| `billing.usd.days[].amount` | integer | 该 UTC 日供应商报告的费用。 |
| `billing.usd.tasks[].task` | rednote \| douyin \| channels \| catalog | 费用对应的平台任务。 |
| `billing.usd.tasks[].amount` | integer | 该任务供应商报告的费用。 |
| `outcomes.failedUnbilled` | integer | 报告费用为 0 的失败调用数。 |
| `outcomes.failedBilled` | integer | 报告费用大于 0 的失败调用数。 |
| `outcomes.failedUnknown` | integer | 没有费用信息的失败调用数。 |
| `endpoints[].task` | rednote \| douyin \| channels \| catalog | 此次汇总的取数任务。 |
| `endpoints[].provider` | string | 供应商 ID。 |
| `endpoints[].operation` | string | 归一后的供应商路径。 |
| `endpoints[].requests` | integer | 该供应商端点的上游尝试数。 |
| `endpoints[].costCredits` | integer \| null | 供应商报告的积分费用。 |
| `endpoints[].costUsdMicros` | integer \| null | 供应商报告的费用，以百万分之一美元计。 |
| `apiKeys[].id` | string | 所选 UTC 日期范围内曾使用的密钥 ID。 |
| `apiKeys[].name` | string | 所选时间内最近记录的密钥名称。 |
| `requests[].id` | string | 本服务为上游尝试分配的 ID。 |
| `requests[].startedAt` | ISO 8601 date-time | 上游尝试开始时间。 |
| `requests[].task` | rednote \| douyin \| channels \| catalog | 任务或扩展数据接口的权限范围。 |
| `requests[].provider` | string | 供应商 ID。 |
| `requests[].operation` | string | 供应商 API 路径。 |
| `requests[].status` | succeeded \| failed \| pending | 上游尝试状态。 |
| `requests[].httpStatus` | integer \| null | 提供方返回的 HTTP 状态码。 |
| `requests[].durationMs` | integer \| null | 耗时（毫秒）。 |
| `requests[].entryPoint` | workbench \| api \| mcp | 调用入口，历史数据可省略。 |
| `requests[].apiKeyId` | string | 若使用 API Key，则为对应的 ID。 |
| `requests[].apiKeyName` | string | 请求发生时的密钥显示名称。 |
| `requests[].requestSummary` | string | 可选的请求方法和参数字段名摘要。 |
| `requests[].providerRequestId` | string | 供应商返回的请求 ID。 |
| `requests[].resultCount` | integer | 如可读取，为供应商结果数。 |
| `requests[].costCredits` | integer | 供应商提供的积分费用。 |
| `requests[].costUsdMicros` | integer | 供应商报告的费用，以百万分之一美元计。 |
| `pagination.page` | integer | 实际页号，从 1 开始。 |
| `pagination.pageSize` | integer | 每页最多 25 条明细。 |
| `pagination.total` | integer | 符合筛选条件的明细总数。 |

## 错误状态

| HTTP | 原因与处理 |
| --- | --- |
| `400` | 请求格式或字段无效。 |
| `401` | 控制台会话缺失、过期或无效。 |
| `405` | 请求方法不受支持。 |
| `503` | 此部署未配置该控制台服务。 |

## 使用细节

-   起止日期都包含在内，最多覆盖 366 天。日、任务和费用汇总基于所选日期范围，明细筛选作用于请求列表和 CSV 导出。

## 同组接口

-   [GET 读取设置与每日额度](<https://social2api.com/docs/api/settings-get/>)
-   [PATCH 更新偏好和每日额度](<https://social2api.com/docs/api/settings-update/>)
-   [GET 读取计费用量摘要](<https://social2api.com/docs/api/settings-billing/>)
-   [GET 查看自动切换状态](<https://social2api.com/docs/api/settings-fallback-get/>)
-   [PATCH 更新自动切换状态](<https://social2api.com/docs/api/settings-fallback-update/>)
-   [GET 列出 API Key](<https://social2api.com/docs/api/api-keys-list/>)
-   [POST 创建 API Key](<https://social2api.com/docs/api/api-keys-create/>)
-   [PATCH 更新 API Key](<https://social2api.com/docs/api/api-keys-update/>)
-   [DELETE 撤销 API Key](<https://social2api.com/docs/api/api-keys-revoke/>)

规范页面：<https://social2api.com/docs/api/settings-usage/>
