> 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.

# Get Workspace Cost Usage

POST https://api.elevenlabs.io/v1/workspace/analytics/usage
Content-Type: application/json

Returns the cost of the workspace's usage over time, for workspaces billed by cost. Usage is bucketed by UTC day. The response is a tabular structure with columns, column_types, column_units, and rows, with one row per group and bucket. `total_cost` is the cost in the workspace's currency and `total_charge_count` the billed quantity. Usage can be grouped or filtered by at most two of `user_id`, `hashed_xi_api_key`, `region`, `reporting_workspace_id`, `billing_group_id`, `product_type`, `surface` and `actor`, and grouping by two of them requires an `eq` or `in` filter on one. `model`, `request_source`, `fiat_charge_type` and `fiat_currency` can always be added. Some id columns also get a display-name column, such as user_label, appended after the existing columns. Workspaces billed in credits should use /v1/workspace/analytics/query/usage-by-product-over-time.

Reference: https://elevenlabs.io/docs/api-reference/workspace/usage/get-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_Cost_Usage_v1_workspace_analytics_usage_post.

- `start_time` (integer, required) — Start of the time range as a Unix timestamp in milliseconds. Must be at least 2020-01-01.
- `end_time` (integer, required) — End of the time range as a Unix timestamp in milliseconds. Must be at least 2020-01-01.
- `interval_seconds` (integer, required) — Bucket size in seconds, in whole UTC days. Pass 86400 for daily buckets or 604800 for weekly buckets, which start on Monday.
- `group_by` (list of enum, optional, nullable)
  - Allowed values: `model`, `request_source`, `fiat_charge_type`, `fiat_currency`, `user_id`, `hashed_xi_api_key`, `region`, `reporting_workspace_id`, `billing_group_id`, `product_type`, `surface`, `actor`
- `filters` (list of MetronomeUsageColumnFilter, optional, nullable)

## Response

### 200

Successful Response

- `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

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### MetronomeUsageColumnFilter

- `column` (enum, required)
  - Allowed values: `model`, `request_source`, `fiat_charge_type`, `fiat_currency`, `user_id`, `hashed_xi_api_key`, `region`, `reporting_workspace_id`, `billing_group_id`, `product_type`, `surface`, `actor`
- `operation` (enum, required)
  - Allowed values: `eq`, `in`, `neq`, `not_in`
- `values` (list of MetronomeUsageColumnFilterValuesItems, required)

### WorkspaceAnalyticsQueryResponseModelRowsItemsItems

- string
- integer
- double
- boolean
- string

### ValidationError

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

### MetronomeUsageColumnFilterValuesItems

- string
- integer
- double
- string
- boolean

### ValidationErrorLocItems

- string
- integer

## Examples

**Request**

```json
{
  "start_time": 1,
  "end_time": 1,
  "interval_seconds": 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/usage"

payload = {
    "start_time": 1,
    "end_time": 1,
    "interval_seconds": 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/usage';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"start_time":1,"end_time":1,"interval_seconds":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/usage"

	payload := strings.NewReader("{\n  \"start_time\": 1,\n  \"end_time\": 1,\n  \"interval_seconds\": 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/usage")

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  \"interval_seconds\": 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/usage")
  .header("Content-Type", "application/json")
  .body("{\n  \"start_time\": 1,\n  \"end_time\": 1,\n  \"interval_seconds\": 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/usage', [
  'body' => '{
  "start_time": 1,
  "end_time": 1,
  "interval_seconds": 1
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/workspace/analytics/usage");
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  \"interval_seconds\": 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,
  "interval_seconds": 1
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/workspace/analytics/usage")! 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()
```