Skip to main content
GET
/
v1
/
tasks
/
{task_id}
/
llm_usage
Get Task Llm Usage
curl --request GET \
  --url https://api.xpander.ai/v1/tasks/{task_id}/llm_usage \
  --header 'x-api-key: <api-key>'
import requests

url = "https://api.xpander.ai/v1/tasks/{task_id}/llm_usage"

headers = {"x-api-key": "<api-key>"}

response = requests.get(url, headers=headers)

print(response.text)
const options = {method: 'GET', headers: {'x-api-key': '<api-key>'}};

fetch('https://api.xpander.ai/v1/tasks/{task_id}/llm_usage', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.xpander.ai/v1/tasks/{task_id}/llm_usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-api-key: <api-key>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

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

func main() {

url := "https://api.xpander.ai/v1/tasks/{task_id}/llm_usage"

req, _ := http.NewRequest("GET", url, nil)

req.Header.Add("x-api-key", "<api-key>")

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

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

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.get("https://api.xpander.ai/v1/tasks/{task_id}/llm_usage")
.header("x-api-key", "<api-key>")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.xpander.ai/v1/tasks/{task_id}/llm_usage")

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

request = Net::HTTP::Get.new(url)
request["x-api-key"] = '<api-key>'

response = http.request(request)
puts response.read_body
{
  "detail": [
    {
      "loc": [
        "<string>"
      ],
      "msg": "<string>",
      "type": "<string>"
    }
  ]
}
Retrieve LLM token usage statistics for a specific task, including input/output token counts and the number of tool actions performed.

Path Parameters

task_id
string
required
Unique identifier of the task (UUID format)

Response

task_id
string
Unique identifier of the task
tokens
integer
Total number of LLM tokens consumed (input + output)
input_tokens
integer
Number of input (prompt) tokens consumed
output_tokens
integer
Number of output (completion) tokens generated
actions
integer
Number of tool actions performed during the task
is_byok
boolean
Whether the task used a Bring Your Own Key (BYOK) model configuration
cost
number
Estimated USD cost for non-BYOK executions in this task, rounded to 5 decimal places. 0.0 means no billable usage (empty task or fully BYOK).

Example Request

curl -X GET -H "x-api-key: <your-api-key>" \
  "https://api.xpander.ai/v1/tasks/<task-id>/llm_usage"

Example Response

{
  "task_id": "e6cf93db-30c7-471b-a1a9-5051a2c9e4ba",
  "tokens": 3842,
  "input_tokens": 1520,
  "output_tokens": 2322,
  "actions": 4,
  "is_byok": false,
  "cost": 0.01284
}

Use Cases

  • Track token consumption - Monitor LLM token usage for individual tasks
  • Cost tracking - cost is returned directly in USD, rounded to 5 decimal places (excludes BYOK executions)
  • Usage auditing - Review resource consumption across tasks
  • BYOK tracking - Identify which tasks ran with your own API keys vs. platform-provided keys

Authorizations

x-api-key
string
header
required

API Key for authentication

Path Parameters

task_id
string
required

Response

Successful Response