管理员

GET /core/v1/admin/usage

管理员完整区间用量与 UTC 趋势

身份要求

管理员. 会话/管理写操作不在公共 Playground 执行。

接口

curl --request GET 'https://api.oneaster.ai/core/v1/admin/usage' \
  --header 'Authorization: Bearer '"$ONEASTER_SESSION_TOKEN"

参数

- from (query, 可选): {"type":"string","format":"date-time"} 包含起点;RFC3339 UTC,最多微秒精度。

- to (query, 可选): {"type":"string","format":"date-time"} 不包含终点;RFC3339 UTC,最多微秒精度。

- model (query, 可选): {"type":"string","minLength":1,"maxLength":200}

- key_id (query, 可选): {"type":"string","pattern":"^[0-9]+$"}

- state (query, 可选): {"enum":["reserved","forwarding","completed","unknown","rejected"]}

- billing_state (query, 可选): {"enum":["reserved","settled","released"]}

- stream (query, 可选): {"type":"boolean"}

- user_id (query, 可选): {"type":"string","pattern":"^[0-9]+$"}

- provider_id (query, 可选): {"type":"string","pattern":"^[0-9]+$"}

- interval (query, 可选): {"type":"string","enum":["hour","day"],"default":"day"}

响应

200

管理员完整区间用量与 UTC 趋势

{
  "application/json": {
    "schema": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "success": {
          "const": true
        },
        "data": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "from": {
              "type": "string",
              "format": "date-time"
            },
            "to": {
              "type": "string",
              "format": "date-time"
            },
            "interval": {
              "enum": [
                "hour",
                "day"
              ]
            },
            "timezone": {
              "const": "UTC"
            },
            "attribution": {
              "const": "request_created_at"
            },
            "currency": {
              "const": "CREDITS"
            },
            "micro_per_credit": {
              "const": 10000
            },
            "summary": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "request_count": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "completed_count": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "unknown_count": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "unresolved_count": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "rejected_count": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "settled_count": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "released_count": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "pending_count": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "charge_micro": {
                  "type": "string",
                  "pattern": "^[0-9]+$",
                  "description": "整数账务单位;1 积分 = 10000 单位,1 USD = 100 积分。前端用 BigInt。"
                },
                "held_micro": {
                  "type": "string",
                  "pattern": "^[0-9]+$",
                  "description": "整数账务单位;1 积分 = 10000 单位,1 USD = 100 积分。前端用 BigInt。"
                },
                "prompt_tokens": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "completion_tokens": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "cache_read_tokens": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "cache_creation_tokens": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "cache_read_reported_count": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                },
                "cache_creation_reported_count": {
                  "type": "string",
                  "pattern": "^[0-9]+$"
                }
              },
              "required": [
                "request_count",
                "completed_count",
                "unknown_count",
                "unresolved_count",
                "rejected_count",
                "settled_count",
                "released_count",
                "pending_count",
                "charge_micro",
                "held_micro",
                "prompt_tokens",
                "completion_tokens",
                "cache_read_tokens",
                "cache_creation_tokens",
                "cache_read_reported_count",
                "cache_creation_reported_count"
              ]
            },
            "series": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "bucket_start": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "request_count": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "completed_count": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "unknown_count": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "unresolved_count": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "rejected_count": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "settled_count": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "released_count": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "pending_count": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "charge_micro": {
                    "type": "string",
                    "pattern": "^[0-9]+$",
                    "description": "整数账务单位;1 积分 = 10000 单位,1 USD = 100 积分。前端用 BigInt。"
                  },
                  "held_micro": {
                    "type": "string",
                    "pattern": "^[0-9]+$",
                    "description": "整数账务单位;1 积分 = 10000 单位,1 USD = 100 积分。前端用 BigInt。"
                  },
                  "prompt_tokens": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "completion_tokens": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "cache_read_tokens": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "cache_creation_tokens": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "cache_read_reported_count": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  },
                  "cache_creation_reported_count": {
                    "type": "string",
                    "pattern": "^[0-9]+$"
                  }
                },
                "required": [
                  "bucket_start",
                  "request_count",
                  "completed_count",
                  "unknown_count",
                  "unresolved_count",
                  "rejected_count",
                  "settled_count",
                  "released_count",
                  "pending_count",
                  "charge_micro",
                  "held_micro",
                  "prompt_tokens",
                  "completion_tokens",
                  "cache_read_tokens",
                  "cache_creation_tokens",
                  "cache_read_reported_count",
                  "cache_creation_reported_count"
                ]
              }
            }
          },
          "required": [
            "from",
            "to",
            "interval",
            "timezone",
            "attribution",
            "currency",
            "micro_per_credit",
            "summary",
            "series"
          ]
        }
      },
      "required": [
        "success",
        "data"
      ]
    }
  }
}

default

错误代码见 core-api.md;供应商/数据库错误已隐藏。

{
  "application/json": {
    "schema": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "success": {
          "const": false
        },
        "error": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "type": {
              "const": "oneaster_error"
            }
          },
          "required": [
            "code",
            "message",
            "type"
          ]
        },
        "data": {
          "type": "null"
        }
      },
      "required": [
        "success",
        "error",
        "data"
      ]
    }
  }
}