Retrieve billing information with Viam's Billing Client API

The billing client API allows you to retrieve billing information from the Viam app.

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

The billing client API supports the following methods:

Method NameDescription
GetCurrentMonthUsageAccess data usage information for the current month for a given organization.
GetInvoicePdfAccess invoice PDF data and optionally save it to a provided file path.
GetInvoicesSummaryAccess total outstanding balance plus invoice summaries for a given org.
GetOrgBillingInformationAccess billing information (payment method, billing tier, etc.) for a given org.

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): the ID of the organization to request usage data for

Returns:

usage = await viam_client.billing_client.get_current_month_usage("<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): the ID of the invoice being requested
  • org_id (str): the ID of the org to request data from
  • dest (str): filepath to save the invoice to

Returns:

  • None.
await viam_client.billing_client.get_invoice_pdf(
    "<INVOICE-ID>", "<ORG-ID>", "<FILENAME>")

For more information, see the Python SDK Docs.

GetInvoicesSummary

Access total outstanding balance plus invoice summaries for a given org.

Parameters:

  • org_id (str): the ID of the org to request data for

Returns:

summary = await viam_client.billing_client.get_invoices_summary("<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): the ID of the org to request data for

Returns:

information = await viam_client.billing_client.get_org_billing_information(
    "<ORG-ID>")

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.