Retrieve billing information with Viam's Billing Client API
The billing client API allows you to retrieve billing information from the Viam app.
Support Notice
Billing client API methods are only available in the Python SDK.
The billing client API supports the following methods:
Method Name | Description |
---|---|
GetCurrentMonthUsage | Access data usage information for the current month for a given organization. |
GetOrgBillingInformation | Access billing information (payment method, billing tier, etc.) for a given org. |
GetInvoicesSummary | Access total outstanding balance plus invoice summaries for a given org. |
GetInvoicePdf | Access invoice PDF data and optionally save it to a provided file path. |
Establish a connection
To use the Viam billing client API, you first need to instantiate a ViamClient
and then instantiate a BillingClient
.
You will also need an API key and API key ID to authenticate your session. Your API key needs to have Org owner permissions to use the billing client API. To get an API key (and corresponding ID), you have two options:
The following example instantiates a ViamClient
, authenticating with an API key, and then instantiates a BillingClient
:
import asyncio
from viam.rpc.dial import DialOptions, Credentials
from viam.app.viam_client import ViamClient
from viam.app.billing_client import BillingClient
async def connect() -> ViamClient:
dial_options = DialOptions(
credentials=Credentials(
type="api-key",
# Replace "<API-KEY>" (including brackets) with your machine's API key
payload='<API-KEY>',
),
# Replace "<API-KEY-ID>" (including brackets) with your machine's
# API key ID
auth_entity='<API-KEY-ID>'
)
return await ViamClient.create_from_dial_options(dial_options)
async def main():
# Make a ViamClient
viam_client = await connect()
# Instantiate a BillingClient to run data client API methods on
billing_client = viam_client.billing_client
viam_client.close()
if __name__ == '__main__':
asyncio.run(main())
Once you have instantiated a BillingClient
, you can run API methods against the BillingClient
object (named billing_client
in the examples).
API
GetCurrentMonthUsage
Access data usage information for the current month for a given organization. You can also find your usage data on the Payment and billing page.
Parameters:
org_id
(str) (required): the ID of the organization to request usage data for.timeout
(float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (viam.proto.app.billing.GetCurrentMonthUsageResponse): the current month usage information.
Example:
usage = await billing_client.get_current_month_usage("<ORG-ID>")
For more information, see the Python SDK Docs.
GetOrgBillingInformation
Access billing information (payment method, billing tier, etc.) for a given org. You can also find this information on the Payment and billing page.
Parameters:
org_id
(str) (required): the ID of the org to request data for.timeout
(float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (viam.proto.app.billing.GetOrgBillingInformationResponse): the org billing information.
Example:
information = await billing_client.get_org_billing_information("<ORG-ID>")
For more information, see the Python SDK Docs.
GetInvoicesSummary
Access total outstanding balance plus invoice summaries for a given org.
Parameters:
org_id
(str) (required): the ID of the org to request data for.timeout
(float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (viam.proto.app.billing.GetInvoicesSummaryResponse): the summaries of all org invoices.
Example:
summary = await billing_client.get_invoices_summary("<ORG-ID>")
For more information, see the Python SDK Docs.
GetInvoicePdf
Access invoice PDF data and optionally save it to a provided file path. You can also find your invoices on the Payment and billing page.
Parameters:
invoice_id
(str) (required): the ID of the invoice being requested.org_id
(str) (required): the ID of the org to request data from.dest
(str) (required): the filepath to save the invoice to.timeout
(float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- None.
Example:
await billing_client.get_invoice_pdf("<INVOICE-ID>", "<ORG-ID>", "invoice.pdf")
For more information, see the Python SDK Docs.
Have questions, or want to meet other people working on robots? Join our Community Discord.
If you notice any issues with the documentation, feel free to file an issue or edit this file.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!