> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xpander.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Task LLM Usage

> Get LLM token usage for a specific task

Retrieve LLM token usage statistics for a specific task, including input/output token counts and the number of tool actions performed.

## Path Parameters

<ParamField path="task_id" type="string" required>
  Unique identifier of the task (UUID format)
</ParamField>

## Response

<ResponseField name="task_id" type="string">
  Unique identifier of the task
</ResponseField>

<ResponseField name="tokens" type="integer">
  Total number of LLM tokens consumed (input + output)
</ResponseField>

<ResponseField name="input_tokens" type="integer">
  Number of input (prompt) tokens consumed
</ResponseField>

<ResponseField name="output_tokens" type="integer">
  Number of output (completion) tokens generated
</ResponseField>

<ResponseField name="actions" type="integer">
  Number of tool actions performed during the task
</ResponseField>

<ResponseField name="is_byok" type="boolean">
  Whether the task used a Bring Your Own Key (BYOK) model configuration
</ResponseField>

<ResponseField name="cost" type="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).
</ResponseField>

## Example Request

```bash theme={"dark"}
curl -X GET -H "x-api-key: <your-api-key>" \
  "https://api.xpander.ai/v1/tasks/<task-id>/llm_usage"
```

## Example Response

```json theme={"dark"}
{
  "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


## OpenAPI

````yaml GET /v1/tasks/{task_id}/llm_usage
openapi: 3.1.0
info:
  title: xpander.ai API Service
  description: |2-

        The xpander.ai API Service provides a unified REST API for managing AI agents,
        executing tasks, managing knowledge bases, and integrating with external systems.
        
        Features:
        - Agent Management: Create, update, deploy, and delete AI agents
        - Task Execution: Invoke agents with support for sync, async, and streaming modes
        - Knowledge Bases: Manage knowledge bases and documents for RAG workflows
        - Tools: Discover, connect, and attach tools (connectors, custom functions, MCP servers, sub-agents, workflows) to agents and workflows
        - MCP Integration: Model Context Protocol support for standardized AI interactions
        
        Authentication: All endpoints require authentication via either an API key (`x-api-key`) or an OAuth2 JWT (`Authorization: Bearer <jwt>`).
        
  version: '0.001'
servers:
  - url: https://api.xpander.ai
security: []
paths:
  /v1/tasks/{task_id}/llm_usage:
    get:
      tags:
        - API v1
        - Tasks
        - Tasks CRUD
      summary: Get Task Llm Usage
      description: Get LLM token usage for a specific task
      operationId: Get_Task_LLM_Usage_v1_tasks__task_id__llm_usage_get
      parameters:
        - name: task_id
          in: path
          required: true
          schema:
            type: string
            title: Task Id
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      description: API Key for authentication
      in: header
      name: x-api-key

````