0
# Credits and Billing
1
2
Manage Azure credits, lots, events, and price sheet information for Enterprise Agreement and Microsoft Customer Agreement billing accounts. This module provides comprehensive billing and credit management capabilities.
3
4
## Capabilities
5
6
### Credits Management
7
8
Access credit balance and summary information for billing profiles.
9
10
```python { .api }
11
def get(billing_account_id: str, billing_profile_id: str, **kwargs) -> Optional[CreditSummary]:
12
"""
13
Get credit summary for a billing account and billing profile.
14
15
Parameters:
16
- billing_account_id: The billing account ID (str)
17
- billing_profile_id: The billing profile ID (str)
18
19
Returns:
20
CreditSummary: Credit balance and summary information
21
"""
22
```
23
24
### Lots Management
25
26
Access Azure credit lots and Microsoft Azure consumption commitments.
27
28
```python { .api }
29
def list_by_billing_profile(
30
billing_account_id: str,
31
billing_profile_id: str,
32
**kwargs
33
) -> Iterable[Lots]:
34
"""
35
List Azure credits for a billing profile.
36
37
Parameters:
38
- billing_account_id: The billing account ID (str)
39
- billing_profile_id: The billing profile ID (str)
40
41
Returns:
42
Iterable[Lots]: Collection of credit lots
43
"""
44
45
def list_by_billing_account(
46
billing_account_id: str,
47
filter: str = None,
48
**kwargs
49
) -> Iterable[Lots]:
50
"""
51
List Azure consumption commitments for a billing account.
52
53
Parameters:
54
- billing_account_id: The billing account ID (str)
55
- filter: OData filter expression (str, optional)
56
57
Returns:
58
Iterable[Lots]: Collection of lots
59
"""
60
61
def list_by_customer(
62
billing_account_id: str,
63
customer_id: str,
64
filter: str = None,
65
**kwargs
66
) -> Iterable[Lots]:
67
"""
68
List Azure credits for a customer (MPA billing accounts only).
69
70
Parameters:
71
- billing_account_id: The billing account ID (str)
72
- customer_id: The customer ID (str)
73
- filter: OData filter expression (str, optional)
74
75
Returns:
76
Iterable[Lots]: Collection of customer lots
77
"""
78
```
79
80
### Events Tracking
81
82
Access events that impact Azure credits or consumption commitments.
83
84
```python { .api }
85
def list_by_billing_profile(
86
billing_account_id: str,
87
billing_profile_id: str,
88
start_date: str,
89
end_date: str,
90
**kwargs
91
) -> Iterable[Events]:
92
"""
93
List events that impact credits for a billing profile.
94
95
Parameters:
96
- billing_account_id: The billing account ID (str)
97
- billing_profile_id: The billing profile ID (str)
98
- start_date: Start date for events query (str)
99
- end_date: End date for events query (str)
100
101
Returns:
102
Iterable[Events]: Collection of credit events
103
"""
104
105
def list_by_billing_account(
106
billing_account_id: str,
107
filter: str = None,
108
**kwargs
109
) -> Iterable[Events]:
110
"""
111
List events that impact consumption commitments for a billing account.
112
113
Parameters:
114
- billing_account_id: The billing account ID (str)
115
- filter: OData filter expression (str, optional)
116
117
Returns:
118
Iterable[Events]: Collection of consumption events
119
"""
120
```
121
122
### Price Sheet Information
123
124
Access current and historical pricing information for resources.
125
126
```python { .api }
127
def get(
128
expand: str = None,
129
skiptoken: str = None,
130
top: int = None,
131
**kwargs
132
) -> PriceSheetResult:
133
"""
134
Get the price sheet for a subscription.
135
136
Parameters:
137
- expand: Expand pricing information (str, optional)
138
- skiptoken: Token for pagination (str, optional)
139
- top: Maximum number of items to return (int, optional)
140
141
Returns:
142
PriceSheetResult: Price sheet information
143
"""
144
145
def get_by_billing_period(
146
billing_period_name: str,
147
expand: str = None,
148
skiptoken: str = None,
149
top: int = None,
150
**kwargs
151
) -> PriceSheetResult:
152
"""
153
Get the price sheet for a specific billing period.
154
155
Parameters:
156
- billing_period_name: The billing period name (str)
157
- expand: Expand pricing information (str, optional)
158
- skiptoken: Token for pagination (str, optional)
159
- top: Maximum number of items to return (int, optional)
160
161
Returns:
162
PriceSheetResult: Historical price sheet information
163
"""
164
```
165
166
### Operations Information
167
168
Access available REST API operations for the consumption service.
169
170
```python { .api }
171
def list(**kwargs) -> Iterable[OperationListResult]:
172
"""
173
List all available consumption REST API operations.
174
175
Returns:
176
Iterable[OperationListResult]: Available API operations
177
"""
178
```
179
180
**Usage Example:**
181
182
```python
183
# Get credit summary
184
billing_account_id = "your-billing-account-id"
185
billing_profile_id = "your-billing-profile-id"
186
187
credit_summary = client.credits.get(
188
billing_account_id=billing_account_id,
189
billing_profile_id=billing_profile_id
190
)
191
192
if credit_summary:
193
print(f"Current Balance: ${credit_summary.balance.amount}")
194
print(f"Currency: {credit_summary.balance.currency}")
195
if credit_summary.pending_credit_adjustments:
196
print(f"Pending Adjustments: ${credit_summary.pending_credit_adjustments.amount}")
197
198
# List credit lots
199
lots = client.lots.list_by_billing_profile(
200
billing_account_id=billing_account_id,
201
billing_profile_id=billing_profile_id
202
)
203
204
for lot in lots:
205
for lot_item in lot.value:
206
print(f"Lot Source: {lot_item.source}")
207
print(f"Original Amount: ${lot_item.original_amount.amount}")
208
print(f"Closed Balance: ${lot_item.closed_balance.amount}")
209
print(f"Status: {lot_item.status}")
210
211
# Get credit events
212
events = client.events.list_by_billing_profile(
213
billing_account_id=billing_account_id,
214
billing_profile_id=billing_profile_id,
215
start_date="2024-01-01",
216
end_date="2024-01-31"
217
)
218
219
for event_collection in events:
220
for event in event_collection.value:
221
print(f"Event Type: {event.event_type}")
222
print(f"Amount: ${event.amount.amount}")
223
print(f"Date: {event.transaction_date}")
224
225
# Get current price sheet
226
price_sheet = client.price_sheet.get(expand="meterDetails", top=100)
227
228
print(f"Billing Period: {price_sheet.billing_period}")
229
print(f"Currency: {price_sheet.currency}")
230
231
for price_item in price_sheet.price_sheet:
232
print(f"Meter: {price_item.meter_name}")
233
print(f"Unit Price: ${price_item.unit_price}")
234
print(f"Currency: {price_item.currency_code}")
235
236
# List available operations
237
operations = client.operations.list()
238
for operation_result in operations:
239
for operation in operation_result.value:
240
print(f"Operation: {operation.name}")
241
print(f"Display Name: {operation.display.operation}")
242
print(f"Description: {operation.display.description}")
243
```
244
245
## Types
246
247
### Credit Models
248
249
```python { .api }
250
class CreditSummary:
251
"""Credit summary information."""
252
id: str
253
name: str
254
type: str
255
etag: str
256
balance: CreditBalanceSummary
257
pending_credit_adjustments: Amount
258
expired_credit: Amount
259
pending_eligible_charges: Amount
260
261
class CreditBalanceSummary:
262
"""Credit balance summary."""
263
estimated_balance: Amount
264
current_balance: Amount
265
266
class Amount:
267
"""Monetary amount with currency."""
268
currency: str
269
amount: float
270
271
class AmountWithExchangeRate(Amount):
272
"""Amount with exchange rate information."""
273
exchange_rate: float
274
exchange_rate_month: int
275
```
276
277
### Lots Models
278
279
```python { .api }
280
class LotSummary:
281
"""Lot summary information."""
282
id: str
283
name: str
284
type: str
285
etag: str
286
original_amount: Amount
287
closed_balance: Amount
288
source: str
289
start_date: datetime
290
expiration_date: datetime
291
po_number: str
292
purchased_date: datetime
293
status: str
294
credit_type: str
295
billing_profile_id: str
296
billing_profile_display_name: str
297
lot_id: str
298
lot_source: str
299
reseller: Reseller
300
301
class Reseller:
302
"""Reseller information."""
303
reseller_id: str
304
reseller_description: str
305
306
class Lots:
307
"""Collection of lots."""
308
value: List[LotSummary]
309
next_link: str
310
```
311
312
### Events Models
313
314
```python { .api }
315
class EventSummary:
316
"""Event summary information."""
317
id: str
318
name: str
319
type: str
320
etag: str
321
transaction_date: datetime
322
description: str
323
new_credit: Amount
324
adjustments: Amount
325
credit_expired: Amount
326
charges: Amount
327
closed_balance: Amount
328
event_type: str
329
invoice_number: str
330
billing_profile_id: str
331
billing_profile_display_name: str
332
lot_id: str
333
lot_source: str
334
cancellation_reason: str
335
credit_type: str
336
337
class Events:
338
"""Collection of events."""
339
value: List[EventSummary]
340
next_link: str
341
```
342
343
### Price Sheet Models
344
345
```python { .api }
346
class PriceSheetResult:
347
"""Price sheet result information."""
348
id: str
349
name: str
350
type: str
351
etag: str
352
price_sheet: List[PriceSheetProperties]
353
next_link: str
354
billing_period: str
355
currency: str
356
357
class PriceSheetProperties:
358
"""Individual price sheet item."""
359
billing_period: str
360
meter_id: str
361
meter_name: str
362
meter_category: str
363
meter_subcategory: str
364
unit: str
365
currency_code: str
366
unit_price: float
367
part_number: str
368
tier_minimum_units: float
369
market_price: float
370
effective_start_date: datetime
371
included_quantity_property: float
372
```
373
374
### Operation Models
375
376
```python { .api }
377
class Operation:
378
"""API operation information."""
379
name: str
380
id: str
381
display: OperationDisplay
382
origin: str
383
384
class OperationDisplay:
385
"""Operation display information."""
386
provider: str
387
resource: str
388
operation: str
389
description: str
390
usage: str
391
392
class OperationListResult:
393
"""Collection of operations."""
394
value: List[Operation]
395
next_link: str
396
```
397
398
### Enumeration Types
399
400
```python { .api }
401
class EventType:
402
"""Credit event types."""
403
SETTLED_CHARGES = "SettledCharges"
404
PENDING_CHARGES = "PendingCharges"
405
PENDING_ADJUSTMENTS = "PendingAdjustments"
406
CREDIT_EXPIRED = "CreditExpired"
407
PENDING_NEW_CREDIT = "PendingNewCredit"
408
NEW_CREDIT = "NewCredit"
409
410
class LotSource:
411
"""Lot source types."""
412
PURCHASE_CREDIT = "PurchaseCredit"
413
PROMOTIONAL_CREDIT = "PromotionalCredit"
414
CONSUMED_CREDIT = "ConsumedCredit"
415
416
class Status:
417
"""General status options."""
418
ACTIVE = "Active"
419
INACTIVE = "Inactive"
420
EXPIRED = "Expired"
421
EXHAUSTED = "Exhausted"
422
CANCELLED = "Cancelled"
423
COMPLETE = "Complete"
424
NONE = "None"
425
426
class CultureCode:
427
"""Culture code options for localization."""
428
EN_US = "en-us"
429
JA_JP = "ja-jp"
430
ZH_CN = "zh-cn"
431
DE_DE = "de-de"
432
ES_ES = "es-es"
433
FR_FR = "fr-fr"
434
IT_IT = "it-it"
435
KO_KR = "ko-kr"
436
PT_BR = "pt-br"
437
RU_RU = "ru-ru"
438
ZH_TW = "zh-tw"
439
CS_CZ = "cs-cz"
440
PL_PL = "pl-pl"
441
TR_TR = "tr-tr"
442
DA_DK = "da-dk"
443
EN_GB = "en-gb"
444
HU_HU = "hu-hu"
445
NB_NO = "nb-no"
446
NL_NL = "nl-nl"
447
PT_PT = "pt-pt"
448
SV_SE = "sv-se"
449
450
class PricingModelType:
451
"""Pricing model types."""
452
ON_DEMAND = "OnDemand"
453
RESERVATION = "Reservation"
454
SPOT = "Spot"
455
```