or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

aggregated-cost.mdbudget-management.mdclient-management.mdcost-analysis.mdcredits-billing.mdindex.mdoperations.mdreservation-management.mdtags-operations.mdusage-analytics.md

cost-analysis.mddocs/

0

# Cost Analysis

1

2

Analyze charges, balances, aggregated costs, and marketplace usage for comprehensive financial reporting and cost allocation. This module provides detailed cost breakdowns and aggregation capabilities.

3

4

## Capabilities

5

6

### Charges Analysis

7

8

Access charge information for different billing periods and scopes with filtering and aggregation options.

9

10

```python { .api }

11

def list(

12

scope: str,

13

start_date: str = None,

14

end_date: str = None,

15

filter: str = None,

16

apply: str = None,

17

**kwargs

18

) -> ChargesListResult:

19

"""

20

List charges for the specified scope and time period.

21

22

Parameters:

23

- scope: The scope for the charges query (str)

24

- start_date: Start date for the query (str, optional)

25

- end_date: End date for the query (str, optional)

26

- filter: OData filter expression (str, optional)

27

- apply: OData apply expression for aggregation (str, optional)

28

29

Returns:

30

ChargesListResult: Charges information

31

"""

32

```

33

34

### Balance Information

35

36

Get account balance information for billing accounts and billing periods.

37

38

```python { .api }

39

def get_by_billing_account(billing_account_id: str, **kwargs) -> Balance:

40

"""

41

Get balance information for a billing account.

42

43

Parameters:

44

- billing_account_id: The billing account ID (str)

45

46

Returns:

47

Balance: Account balance information

48

"""

49

50

def get_for_billing_period_by_billing_account(

51

billing_account_id: str,

52

billing_period_name: str,

53

**kwargs

54

) -> Balance:

55

"""

56

Get balance information for a specific billing period.

57

58

Parameters:

59

- billing_account_id: The billing account ID (str)

60

- billing_period_name: The billing period name (str)

61

62

Returns:

63

Balance: Account balance for the billing period

64

"""

65

```

66

67

### Aggregated Cost Analysis

68

69

Analyze aggregated costs for management groups with hierarchical cost rollup.

70

71

```python { .api }

72

def get_by_management_group(

73

management_group_id: str,

74

filter: str = None,

75

**kwargs

76

) -> ManagementGroupAggregatedCostResult:

77

"""

78

Get aggregated cost for a management group and all child groups.

79

80

Parameters:

81

- management_group_id: The management group ID (str)

82

- filter: OData filter expression (str, optional)

83

84

Returns:

85

ManagementGroupAggregatedCostResult: Aggregated cost information

86

"""

87

88

def get_for_billing_period_by_management_group(

89

management_group_id: str,

90

billing_period_name: str,

91

**kwargs

92

) -> ManagementGroupAggregatedCostResult:

93

"""

94

Get aggregated cost for a management group for a specific billing period.

95

96

Parameters:

97

- management_group_id: The management group ID (str)

98

- billing_period_name: The billing period name (str)

99

100

Returns:

101

ManagementGroupAggregatedCostResult: Aggregated cost for billing period

102

"""

103

```

104

105

**Usage Example:**

106

107

```python

108

# Analyze charges for current month

109

from datetime import datetime, timedelta

110

111

scope = f"/subscriptions/{subscription_id}"

112

start_date = datetime.now().replace(day=1).strftime("%Y-%m-%d")

113

end_date = datetime.now().strftime("%Y-%m-%d")

114

115

charges = client.charges.list(

116

scope=scope,

117

start_date=start_date,

118

end_date=end_date

119

)

120

121

print("Charge Summary:")

122

for charge in charges.value:

123

print(f"Charge Type: {charge.kind}")

124

if hasattr(charge, 'azure_charges'):

125

print(f"Azure Charges: ${charge.azure_charges}")

126

if hasattr(charge, 'marketplace_charges'):

127

print(f"Marketplace Charges: ${charge.marketplace_charges}")

128

129

# Get balance information for EA billing account

130

billing_account_id = "your-billing-account-id"

131

balance = client.balances.get_by_billing_account(billing_account_id)

132

133

print(f"Current Balance: ${balance.new_purchases}")

134

print(f"Adjustments: ${balance.adjustments}")

135

print(f"Beginning Balance: ${balance.beginning_balance}")

136

print(f"Ending Balance: ${balance.ending_balance}")

137

138

# Get aggregated costs for management group

139

management_group_id = "your-management-group-id"

140

aggregated_cost = client.aggregated_cost.get_by_management_group(

141

management_group_id=management_group_id,

142

filter="properties/usageStart ge '2024-01-01'"

143

)

144

145

print(f"Total Cost: ${aggregated_cost.azure_charges}")

146

print(f"Billing Period: {aggregated_cost.billing_period}")

147

print(f"Children Count: {len(aggregated_cost.children)}")

148

149

# Analyze charges with grouping

150

charges_grouped = client.charges.list(

151

scope=scope,

152

apply="groupby((properties/chargeType))"

153

)

154

```

155

156

## Types

157

158

### Charge Models

159

160

```python { .api }

161

class ChargeSummary:

162

"""Base class for charge summaries."""

163

id: str

164

name: str

165

type: str

166

etag: str

167

kind: str

168

169

class LegacyChargeSummary(ChargeSummary):

170

"""Legacy format charge summary."""

171

billing_period_name: str

172

usage_start: datetime

173

usage_end: datetime

174

azure_charges: float

175

marketplace_charges: float

176

billing_account_id: str

177

billing_account_name: str

178

billing_profile_id: str

179

billing_profile_name: str

180

invoice_section_id: str

181

invoice_section_name: str

182

customer_tenant_id: str

183

customer_name: str

184

is_invoice_ready: bool

185

186

class ModernChargeSummary(ChargeSummary):

187

"""Modern format charge summary."""

188

azure_charges: float

189

marketplace_charges: float

190

billing_account_id: str

191

billing_period_name: str

192

usage_start: datetime

193

usage_end: datetime

194

```

195

196

### Balance Models

197

198

```python { .api }

199

class Balance:

200

"""Account balance information."""

201

id: str

202

name: str

203

type: str

204

etag: str

205

beginning_balance: float

206

ending_balance: float

207

new_purchases: float

208

adjustments: float

209

utilized: float

210

service_overage: float

211

charges_billed_separately: float

212

total_overage: float

213

total_usage: float

214

azure_marketplace_service_charges: float

215

billing_frequency: str

216

price_hidden: bool

217

new_purchases_details: List[BalancePropertiesNewPurchasesDetailsItem]

218

adjustment_details: List[BalancePropertiesAdjustmentDetailsItem]

219

220

class BalancePropertiesNewPurchasesDetailsItem:

221

"""New purchases detail item."""

222

name: str

223

value: float

224

225

class BalancePropertiesAdjustmentDetailsItem:

226

"""Adjustment detail item."""

227

name: str

228

value: float

229

```

230

231

### Aggregated Cost Models

232

233

```python { .api }

234

class ManagementGroupAggregatedCostResult:

235

"""Aggregated cost result for management group."""

236

id: str

237

name: str

238

type: str

239

etag: str

240

management_group_id: str

241

azure_charges: float

242

marketplace_charges: float

243

billing_period: str

244

usage_start: datetime

245

usage_end: datetime

246

children: List[ManagementGroupAggregatedCostResult]

247

included_subscriptions: List[str]

248

excluded_subscriptions: List[str]

249

```

250

251

### List Result Models

252

253

```python { .api }

254

class ChargesListResult:

255

"""Container for charges list response."""

256

value: List[ChargeSummary]

257

next_link: str

258

```

259

260

### Enumeration Types

261

262

```python { .api }

263

class ChargeSummaryKind:

264

"""Charge summary format types."""

265

LEGACY = "legacy"

266

MODERN = "modern"

267

268

class BillingFrequency:

269

"""Billing frequency options."""

270

MONTH = "Month"

271

QUARTER = "Quarter"

272

YEAR = "Year"

273

```