Skip to content

Costs API

The Costs API allows you to track, analyze, and optimize the costs associated with your AI workflows on the Lumea platform.

Overview

The Costs API provides visibility into the expenses incurred by your AI operations. It enables you to track costs at both individual workflow run level and across multiple runs, helping you optimize resource utilization and budget planning.

Note: Each customer receives a custom deployment with a unique API endpoint. The endpoints described in this documentation should be prefixed with your organization's specific API URL provided during onboarding.

Data Models

ServiceCost Object

FieldTypeDescription
idstringUnique identifier for the cost entry
run_idstringID of the workflow run that incurred the cost
servicestringThe service used (e.g., "openai", "anthropic")
groupstringOptional grouping (e.g., model name within service)
amountfloatThe cost amount in USD
created_atstringTimestamp when the cost was recorded

CostResponse Object

FieldTypeDescription
total_costfloatTotal cost sum across all services
costs_by_serviceobjectCosts aggregated by service name
costs_by_groupobjectCosts grouped by service and then by group

Endpoints

Get Run Costs

Retrieves cost information for a specific workflow run.

URL: /costs/runs/{run_id}

Method: GET

URL Parameters:

ParameterDescription
run_idThe unique ID of the workflow run

Query Parameters:

ParameterRequiredDescription
include_childrenNoWhether to include costs from child runs recursively (default: false)

Success Response:

  • Code: 200 OK
  • Content:
json
{
  "total_cost": 0.45,
  "costs_by_service": {
    "openai": 0.35,
    "anthropic": 0.1
  },
  "costs_by_group": {
    "openai": {
      "gpt-4": 0.25,
      "gpt-3.5-turbo": 0.1
    },
    "anthropic": {
      "claude-3-opus": 0.1
    }
  }
}

Error Response:

  • Code: 500 Internal Server Error
    • Content: {"detail": "Error message"}

Get Multiple Runs Costs

Retrieves aggregated cost information for multiple workflow runs with optional filtering.

URL: /costs/runs

Method: GET

Query Parameters:

ParameterRequiredDescription
workflow_idNoFilter costs by workflow ID
start_dateNoFilter costs by start date (ISO format)
end_dateNoFilter costs by end date (ISO format)
include_childrenNoWhether to include costs from child runs recursively (default: false)

Success Response:

  • Code: 200 OK
  • Content:
json
{
  "total_cost": 1.25,
  "costs_by_service": {
    "openai": 0.85,
    "anthropic": 0.3,
    "cohere": 0.1
  },
  "costs_by_group": {
    "openai": {
      "gpt-4": 0.65,
      "gpt-3.5-turbo": 0.2
    },
    "anthropic": {
      "claude-3-opus": 0.2,
      "claude-3-sonnet": 0.1
    },
    "cohere": {
      "command": 0.1
    }
  }
}

Error Response:

  • Code: 500 Internal Server Error
    • Content: {"detail": "Error message"}