管理 API

账单管理

查看 Markdown


获取账单信息

/v1/billing/teams/{team_id}/billing-info

获取指定团队 ID 的账单信息。

路径参数

team_idstring

(字符串,必需)— 团队 ID。

响应体

billingInfoobject

(对象)——账单信息。

Exampletext

text

No parameters.
Exampletext

text

{
  "billingInfo": {
    "name": "Acme Inc.",
    "address": {
      "line1": "123 Main St.",
      "line2": "",
      "city": "New York",
      "country": "US",
      "postalCode": "12345",
      "state": "New York"
    },
    "email": "foo@example.com",
    "taxIdType": "us_ein",
    "taxNumber": "12-3456789"
  }
}

设置账单信息

/v1/billing/teams/{team_id}/billing-info

设置团队的计费信息。

路径参数

team_idstring

(字符串,必需)— 团队 ID。

请求体

Exampletext

text

{
  "billingInfo": {
    "name": "Acme Inc.",
    "address": {
      "line1": "123 Main St.",
      "line2": "",
      "city": "New York",
      "country": "US",
      "postalCode": "12345",
      "state": "New York"
    },
    "email": "foo@example.com",
    "taxIdType": "us_ein",
    "taxNumber": "12-3456789"
  }
}
Exampletext

text

{}

列出发票

/v1/billing/teams/{team_id}/invoices

列出属于团队的发票。

路径参数

team_idstring

(字符串,必需)— 团队 ID。

查询参数

billingCycle.yearinteger

billingCycle.monthinteger

since.yearinteger

since.monthinteger

invoiceIds.invoiceIdsarray<string>

(数组<字符串>)

响应体

invoicesarray<object>

发票。

Exampletext

text

No parameters.
Exampletext

text

{
  "invoices": [
    {
      "teamId": "65c1e471-205f-4566-9c5a-07198bcdf4ce",
      "invoiceId": "aUa1nsnCQfxOFnWjqdimZczKKNJJ5xuwlkb-k0XiUOQ=",
      "invoiceNumber": "742-250-927-721",
      "createTime": "2025-04-01T21:19:48.569466Z",
      "invoiceStatus": "PAID",
      "firstDesiredNextCycleTs": "2025-04-11T02:46:58Z",
      "chargerAttempts": [
        {
          "ticket": 0,
          "successful": false,
          "paymentMethodId": ""
        },
        {
          "ticket": 1,
          "successful": true,
          "paymentMethodId": ""
        }
      ],
      "lines": [
        {
          "clusterName": "us-east-1",
          "description": "Chat grok-2-1212-1.0.0",
          "unitType": "Prompt text tokens",
          "unitPrice": "20000",
          "numUnits": "908",
          "amount": "0"
        },
        {
          "clusterName": "us-east-1",
          "description": "Chat grok-2-1212-1.0.0",
          "unitType": "Completion text tokens",
          "unitPrice": "100000",
          "numUnits": "534",
          "amount": "0"
        }
      ],
      "subtotal": "0",
      "tax": "0",
      "total": "0",
      "invoicePdfAssetKeySuffix": "teams/65c1e471-205f-4566-9c5a-07198bcdf4ce/billing/2025-2-aUa1nsnCQfxOFnWjqdimZczKKNJJ5xuwlkb-k0XiUOQ=.pdf",
      "monthly": {
        "billingCycle": {
          "year": 2025,
          "month": 2
        },
        "defaultCreditsIssued": {
          "val": "0"
        },
        "autoCreditsIssued": {
          "val": "0"
        },
        "prepaidTokensToSpend": {
          "val": "0"
        },
        "billingItemsCsvAssetKeySuffix": "teams/65c1e471-205f-4566-9c5a-07198bcdf4ce/billing/2025-2-aUa1nsnCQfxOFnWjqdimZczKKNJJ5xuwlkb-k0XiUOQ=-billing_items.csv.zstd",
        "correctionsCsvAssetKeySuffix": "teams/65c1e471-205f-4566-9c5a-07198bcdf4ce/billing/2025-2-aUa1nsnCQfxOFnWjqdimZczKKNJJ5xuwlkb-k0XiUOQ=-corrections.csv.zstd"
      }
    }
  ]
}

列出付款方式

/v1/billing/teams/{team_id}/payment-method

列出团队已保存的付款方式。你可以添加或删除付款方式https://console.x.ai.

路径参数

team_idstring

(字符串,必需)— 团队 ID。

响应体

paymentMethodsarray<object>

已保存的付款方式。

pendingPaymentMethodobject

表示添加付款方式的不完整尝试。 可能会转化为付款方式。

Exampletext

text

No parameters.
Exampletext

text

{
  "paymentMethods": [
    {
      "paymentMethodId": "pm_xxxxxxxxxxxxxxxxxxxxxxxx",
      "billingInfo": {
        "name": "Acme Inc.",
        "address": {
          "line1": "123 Main St.",
          "line2": "",
          "city": "New York",
          "country": "US",
          "postalCode": "12345",
          "state": "New York"
        },
        "email": "foo@example.com",
        "taxIdType": "us-ein",
        "taxNumber": "123-3456789"
      },
      "cardDetails": {
        "brand": "mastercard",
        "expMonth": "12",
        "expYear": "2030",
        "last4": "4444"
      },
      "usBankAccountDetails": null,
      "linkDetails": null,
      "paymentType": "card"
    }
  ],
  "pendingPaymentMethod": null
}

设置默认付款方式

/v1/billing/teams/{team_id}/payment-method/default

将默认付款方式设置为存档的现有付款方式。

路径参数

team_idstring

(字符串,必需)— 团队 ID。

请求体

Exampletext

text

{
  "paymentMethodId": "pm_xxxxxxxxxxxxxxxxxxxxxxxx"
}
Exampletext

text

{}

预览本月 postpaid 发票

/v1/billing/teams/{team_id}/postpaid/invoice/preview

预览当前计费周期后付费用量的应付金额。

路径参数

team_idstring

(字符串,必需)— 团队 ID。

响应体

coreInvoiceobject

发票对象。

effectiveSpendingLimitstring

当前有效支出限额,以 USD 美分为单位。

defaultCreditsstring

(字符串)— 当前默认额度(单位:USD 美分)。

billingCycleobject

Exampletext

text

No parameters.
Exampletext

text

{
  "coreInvoice": {
    "lines": [],
    "amountBeforeVat": "0",
    "vatCost": "0",
    "amountAfterVat": "0",
    "autoCreditsIssued": "0",
    "defaultCreditsIssued": "0",
    "totalWithCorr": {
      "val": "0"
    },
    "prepaidCredits": {
      "val": "-4500"
    },
    "prepaidCreditsUsed": {
      "val": "0"
    }
  },
  "effectiveSpendingLimit": "20000",
  "defaultCredits": "0",
  "billingCycle": {
    "year": 2025,
    "month": 11
  }
}

获取每月 postpaid 消费限额

/v1/billing/teams/{team_id}/postpaid/spending-limits

获取后付费每月支出限额。团队耗尽全部预付费额度且后付费用量达到用户设置的软支出限额后,API 将停止工作。

路径参数

team_idstring

(字符串,必需)— 团队 ID。

响应体

spendingLimitsobject

(对象)— 后付费每月支出限额。

Exampletext

text

No parameters.
Exampletext

text

{
  "spendingLimits": {
    "hardSlAuto": {
      "val": "22500"
    },
    "effectiveHardSl": {
      "val": "22500"
    },
    "softSl": {
      "val": "20000"
    },
    "effectiveSl": {
      "val": "20000"
    }
  }
}

设置每月 postpaid 消费限额

/v1/billing/teams/{team_id}/postpaid/spending-limits

设置团队的后付费每月支出限额,可用于限制后付费 API 用量的最高金额。请注意,这不会限制预付费额度的使用;预付费额度总会先于后付费用量被消耗。若只想使用预付费额度,可将此限额设为 0。

路径参数

team_idstring

(字符串,必需)— 团队 ID。

请求体

响应体

thisBpSoftSpendingLimitobject

USD 美分的表示。

Exampletext

text

{
  "desiredSoftSpendingLimit": {
    "val": "20000"
  }
}
Exampletext

text

{
  "thisBpSoftSpendingLimit": {
    "val": "20000"
  }
}

列出 prepaid credit 余额和余额变更

/v1/billing/teams/{team_id}/prepaid/balance

列出团队的预付费额度余额及其变化。

路径参数

team_idstring

(字符串,必需)— 团队 ID。

响应体

changesarray<object>

预付费额度余额的变化。

totalobject

USD 美分的表示。

Exampletext

text

No parameters.
Exampletext

text

{
  "changes": [
    {
      "teamId": "65c1e471-205f-4566-9c5a-07198bcdf4ce",
      "changeOrigin": "PURCHASE",
      "topupStatus": "SUCCEEDED",
      "amount": {
        "val": "-1000"
      },
      "invoiceId": "7v7blf6c1G2g34OdI4N5tD1CKCdag4ZYLhn5vTBLIMM=",
      "invoiceNumber": "062-446-653-166",
      "createTime": "2025-02-24T15:28:02.308840Z",
      "paymentProcessor": {
        "kind": "STRIPE"
      }
    }
  ],
  "total": {
    "val": "-1000"
  }
}

充值 prepaid credit

/v1/billing/teams/{team_id}/prepaid/top-up

使用默认付款方式为预付费额度充值。

路径参数

team_idstring

(字符串,必填)— 要充值的团队的团队 ID。

请求体

响应体

changeobject

(对象)— 预付费额度余额的变动项。

Exampletext

text

{
  "amount": {
    "val": "500"
  }
}
Exampletext

text

{
  "change": {
    "teamId": "65c1e471-205f-4566-9c5a-07198bcdf4ce",
    "changeOrigin": "PURCHASE",
    "topupStatus": "TO_CHARGE",
    "amount": {
      "val": "-500"
    },
    "createTime": "2025-11-13T14:02:21.309537Z",
    "createTs": "2025-11-13T14:02:21.309537Z",
    "paymentProcessor": {
      "kind": "STRIPE"
    }
  }
}

获取 API 历史用量

/v1/billing/teams/{team_id}/usage

获取一段时间内 API 的历史使用情况(按字段聚合)。

路径参数

team_idstring

(字符串,必需)— 要分析其计费记录的团队。

请求体

响应体

timeSeriesarray<object>

对于 group-by 子句的每个值,我们返回一个时间序列。

limitReachedboolean

(布尔值)— 如果为 true,说明查询已达到最大基数,返回的仅是结果子集。

Exampletext

text

{
  "analyticsRequest": {
    "timeRange": {
      "startTime": "2025-10-01 00:00:00",
      "endTime": "2025-10-07 23:59:59",
      "timezone": "Etc/GMT"
    },
    "timeUnit": "TIME_UNIT_DAY",
    "values": [
      {
        "name": "usd",
        "aggregation": "AGGREGATION_SUM"
      }
    ],
    "groupBy": [
      "description"
    ],
    "filters": []
  }
}
Exampletext

text

{
  "timeSeries": [
    {
      "group": [
        "Chat grok-4-0709"
      ],
      "groupLabels": [
        "Chat grok-4-0709"
      ],
      "dataPoints": [
        {
          "timestamp": "2025-10-01T00:00:00Z",
          "values": [
            0.75973725
          ]
        },
        {
          "timestamp": "2025-10-02T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-03T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-04T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-05T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-06T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-07T00:00:00Z",
          "values": [
            0
          ]
        }
      ]
    },
    {
      "group": [
        "Chat grok-4-fast-non-reasoning"
      ],
      "groupLabels": [
        "Chat grok-4-fast-non-reasoning"
      ],
      "dataPoints": [
        {
          "timestamp": "2025-10-01T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-02T00:00:00Z",
          "values": [
            0.0001037
          ]
        },
        {
          "timestamp": "2025-10-03T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-04T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-05T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-06T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-07T00:00:00Z",
          "values": [
            0
          ]
        }
      ]
    },
    {
      "group": [
        "grok-2-image-1212"
      ],
      "groupLabels": [
        "grok-2-image-1212"
      ],
      "dataPoints": [
        {
          "timestamp": "2025-10-01T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-02T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-03T00:00:00Z",
          "values": [
            0.14
          ]
        },
        {
          "timestamp": "2025-10-04T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-05T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-06T00:00:00Z",
          "values": [
            0
          ]
        },
        {
          "timestamp": "2025-10-07T00:00:00Z",
          "values": [
            0
          ]
        }
      ]
    }
  ],
  "limitReached": false
}

最后更新:2026 年 2 月 13 日