Retrieve billing information with Viam's billing client API | APIs
Retrieve billing information with Viam's billing client API
The billing client allows you to retrieve billing information from Viam.
The billing API supports the following methods:
| Method Name | Description |
|---|---|
GetCurrentMonthUsage |
Access data usage information for the current billing period 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 organization. |
GetInvoicePDF |
Access invoice PDF data and optionally save it to a provided file path. |
CreateInvoiceAndChargeImmediately |
Create a flat fee invoice and charge the organization immediately. The caller must be an owner of the organization being charged. This function blocks until payment is confirmed, but will time out after 2 minutes if there is no confirmation. |
ChargeOrganization |
Charge an organization for usage. |
Establish a connection
To use the billing client API, you need to instantiate a ViamClient and then instantiate a BillingClient.
You need an API key and API key ID with Org owner permissions to use the billing client API. To get an API key (and corresponding ID), use the web UI to the Viam CLI.
Copy
Copy
Copy
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 billing period for a given organization. This method only returns usage for organizations with monthly billing at the end of the month ("in_arrears": true). 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:
Copy
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 organization 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 organization billing information.
GetInvoicesSummary
Access total outstanding balance plus invoice summaries for a given organization. This includes both monthly and annual invoices depending on the organization’s billing configuration.
Parameters:
Returns:
- ( viam.proto.app.billing.GetInvoicesSummaryResponse): : the summaries of all organization invoices.
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 organization 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.
CreateInvoiceAndChargeImmediately
Create a flat fee invoice and charge the organization immediately. The caller must be an owner of the organization being charged. This function blocks until payment is confirmed, but will time out after 2 minutes if there is no confirmation.
Parameters:
org_id_to_charge( str) (required)amount( float) (required)description( str) (optional)org_id_for_branding( str) (optional)disable_email( bool) (required)
Returns:
ChargeOrganization
Charge an organization for usage.
Parameters:
org_id_to_charge( str) (required): the organization to charge.subtotal( float) (required): the subtotal amount in dollars.tax( float) (required): the tax amount in dollars to add to the subtotal.description( str) (optional): a short description of the charge to display on the invoice PDF (must be 1000 characters or less).org_id_for_branding( str) (optional): the organization whose branding to use in the invoice PDF and confirmation email.disable_confirmation_email( bool) (required): whether or not to disable sending an email confirmation for the invoice.
Returns:
- ( viam.proto.app.billing.ChargeOrganizationResponse): : the invoice id.