> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# 获取工作区用量

POST https://api.elevenlabs.io/v1/workspace/analytics/query/usage-by-product-over-time
Content-Type: application/json

返回按产品类型细分的信用额度使用情况及其时间变化。响应为表格结构，包含 columns、column_types、column_units 和 rows。部分 id 列还会在现有列后附加显示名称列，例如 user_label 或 voice_name。

Reference: https://elevenlabs.io/docs/api-reference/analytics/workspace/usage

## Servers

- `https://api.elevenlabs.io` (Production, default)
- `https://api.us.elevenlabs.io` (Production US)
- `https://api.eu.residency.elevenlabs.io` (Production EU)
- `https://api.in.residency.elevenlabs.io` (Production India)
- `https://api.sg.residency.elevenlabs.io` (Production Singapore)

## Request

### Body (application/json)

This endpoint expects a Body_Get_Workspace_Usage_v1_workspace_analytics_query_usage_by_product_over_time_post.

- `start_time` (integer, required) — 时间范围起点，以毫秒 Unix 时间戳表示。不得早于 2020-01-01。
- `end_time` (integer, required) — 时间范围结束时间，以毫秒级 Unix 时间戳表示。不得早于 2020-01-01。
- `interval_seconds` (integer, optional, default: 60) — Bucket size in seconds. Each row in the response covers this many seconds of the selected time range. For example, pass 3600 for hourly buckets, 86400 for daily buckets, or 604800 for weekly buckets. Whether `time_zone` shifts bucket boundaries depends on this value: week multiples (e.g. 604800) are calendar weeks that start Monday at local midnight; whole-day multiples that are not whole weeks (e.g. 86400) align to local midnight; whole-hour multiples up to 24 hours (e.g. 3600, 14400) align to local hour boundaries from midnight; sub-hour values and other sizes remain UTC-anchored regardless of `time_zone`.
- `group_by` (list of enum, optional, nullable)
  - Allowed values: `product_type`, `model`, `voice_id`, `user_id`, `fiat_currency`, `fiat_charge_type`, `region`, `reporting_workspace_id`, `request_source`, `resource_id`, `subresource_id`, `request_queue_type`, `voice_multiplier`, `hashed_xi_api_key`, `billing_group_id`, `surface`, `actor`
- `filters` (list of ColumnFilter, optional, nullable)
- `time_zone` (string, optional, default: UTC) — 用于对齐符合条件的 `interval_seconds` 值分桶边界的 IANA 时区标识符（例如 'America/New_York'、'Europe/London'、'UTC'）。周的倍数（例如 604800）为从当地时间周一午夜开始的自然周。非整周的整天倍数从当地时间午夜开始；不超过 24 小时的整小时倍数与从午夜起算的本地整点边界对齐。无论此设置为何，小时以下的间隔和其他分桶大小仍以 UTC 为基准。默认为 UTC。

## Response

### 200

成功响应

- `columns` (list of string, required)
- `column_types` (list of enum, required)
  - Allowed values: `String`, `Float`, `DateTime`, `Int`, `Bool`, `JSON`, `Map`, `Array`
- `rows` (list of list of WorkspaceAnalyticsQueryResponseModelRowsItemsItems, required)
- `column_units` (list of enum, required)
  - Allowed values: `ms`, `s`, `min`, `duration`, `credits`, `usd`, `eur`, `inr`, `pln`, `gbp`, `ratio`, `rating`

## Errors

### 422 Unprocessable Entity Error

验证错误。

- `detail` (list of ValidationError, optional)

## Types

### ColumnFilter

- `column` (string, required)
- `operation` (enum, required)
  - Allowed values: `in`, `not_in`, `le`, `ge`, `lt`, `gt`, `eq`, `neq`
- `values` (list of ColumnFilterValuesItems, required)

### WorkspaceAnalyticsQueryResponseModelRowsItemsItems

- string
- integer
- double
- boolean
- string

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)

### ColumnFilterValuesItems

- string
- integer
- double
- string
- boolean

### ValidationErrorLocItems

- string
- integer

## Examples

**Request**

```json
{
  "start_time": 1,
  "end_time": 1
}
```

**Response**

```json
{
  "columns": [
    "string"
  ],
  "column_types": [
    "String"
  ],
  "rows": [
    [
      "string"
    ]
  ],
  "column_units": [
    "ms"
  ]
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/workspace/analytics/query/usage-by-product-over-time"

payload = {
    "start_time": 1,
    "end_time": 1
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/workspace/analytics/query/usage-by-product-over-time';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"start_time":1,"end_time":1}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.elevenlabs.io/v1/workspace/analytics/query/usage-by-product-over-time"

	payload := strings.NewReader("{\n  \"start_time\": 1,\n  \"end_time\": 1\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.elevenlabs.io/v1/workspace/analytics/query/usage-by-product-over-time")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"start_time\": 1,\n  \"end_time\": 1\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.elevenlabs.io/v1/workspace/analytics/query/usage-by-product-over-time")
  .header("Content-Type", "application/json")
  .body("{\n  \"start_time\": 1,\n  \"end_time\": 1\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.elevenlabs.io/v1/workspace/analytics/query/usage-by-product-over-time', [
  'body' => '{
  "start_time": 1,
  "end_time": 1
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/workspace/analytics/query/usage-by-product-over-time");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"start_time\": 1,\n  \"end_time\": 1\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "start_time": 1,
  "end_time": 1
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/workspace/analytics/query/usage-by-product-over-time")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```