{"id":5238,"library":"google-cloud-billing","title":"Google Cloud Billing API","description":"The `google-cloud-billing` Python client library provides programmatic access to the Google Cloud Billing API, allowing developers to manage their billing accounts, link projects, or browse the catalog of SKUs and pricing information. It offers a high-level interface for interacting with Google Cloud Billing services. This library is actively maintained by Google, with regular updates to support new features and maintain compatibility with the latest Python versions.","status":"active","version":"1.19.0","language":"en","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-billing","tags":["google cloud","billing","cloud management","finops","api client","gcp"],"install":[{"cmd":"pip install google-cloud-billing","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary client class is found within the `billing_v1` submodule, representing version 1 of the Billing API.","symbol":"CloudBillingClient","correct":"from google.cloud import billing_v1\nclient = billing_v1.CloudBillingClient()"}],"quickstart":{"code":"import os\nfrom google.cloud import billing_v1\n\ntry:\n    # Initialize the client using Application Default Credentials\n    # Ensure 'gcloud auth application-default login' has been run or\n    # GOOGLE_APPLICATION_CREDENTIALS environment variable is set.\n    client = billing_v1.CloudBillingClient()\n\n    # List billing accounts accessible by the authenticated user\n    # Requires 'billing.accounts.get' permission on the billing account resource.\n    print(\"Listing billing accounts:\")\n    for account in client.list_billing_accounts():\n        print(f\"  Name: {account.name}\")\n        print(f\"  Display Name: {account.display_name}\")\n        print(f\"  Open: {account.open}\")\n\n    # Example: Get a specific billing account (replace with a valid account ID)\n    # billing_account_id = \"012345-ABCDEF-789012\"\n    # billing_account_name = f\"billingAccounts/{billing_account_id}\"\n    # account = client.get_billing_account(name=billing_account_name)\n    # print(f\"\\nDetails for {account.display_name}: {account.name}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure you have set up Application Default Credentials and have sufficient permissions.\")\n    print(\"Run 'gcloud auth application-default login' for local development or set the GOOGLE_APPLICATION_CREDENTIALS environment variable.\")","lang":"python","description":"This quickstart demonstrates how to instantiate the `CloudBillingClient` and list billing accounts accessible to the authenticated user. It relies on Application Default Credentials (ADC) for authentication. Ensure your local environment is authenticated (e.g., via `gcloud auth application-default login`) and that the service account or user account has the necessary IAM permissions (e.g., `billing.accounts.get`)."},"warnings":[{"fix":"Upgrade your Python environment to Python 3.9 or a newer supported version.","message":"The `google-cloud-billing` library requires Python 3.9 or higher. Older Python versions (<=3.8) are no longer supported. Attempting to use the library with unsupported Python versions will result in installation failures or runtime errors.","severity":"breaking","affected_versions":"<= 3.8"},{"fix":"To access detailed billing costs, configure Cloud Billing export to BigQuery via the Google Cloud Console. Then, use the `google-cloud-bigquery` library to query the exported datasets.","message":"The Cloud Billing API primarily provides management capabilities for billing accounts and access to SKU/pricing catalogs. It does *not* directly provide APIs to fetch detailed cost reports or aggregated billing spend data. For granular cost analysis, you must enable Cloud Billing data export to BigQuery and then query the exported data using a BigQuery client.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For local development, use `gcloud auth application-default login`. For production, leverage attached service accounts on GCP compute resources (e.g., Compute Engine, Cloud Run, Cloud Functions) or Workload Identity Federation for external workloads. Avoid explicit JSON key files where possible.","message":"Improper management of service account keys (e.g., hardcoding in source, committing to repositories) is a security risk. Google Cloud client libraries, including `google-cloud-billing`, use Application Default Credentials (ADC) to find credentials automatically.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the official Google Cloud documentation on upcoming CUD billing model changes. Adjust your cost reporting and analysis tools to account for direct discounted pricing instead of credits. The API client will reflect the underlying data changes.","message":"Google Cloud is transitioning its spend-based Committed Use Discounts (CUDs) billing model. Starting July 15, 2025 (and fully by February 5, 2026), CUD savings will be represented as direct discounted prices on your bill, rather than credits. This change might affect how billing data is interpreted or presented.","severity":"deprecated","affected_versions":"N/A (affects billing model, not directly API behavior, but impacts data interpretation)"},{"fix":"If you configure logging for this library, take care to restrict access to logs. Do not depend on the immutability of log events. Consider setting the `GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable for simple configuration or use advanced code-based configuration if strict control is needed.","message":"The logging mechanism for `google-cloud-billing` (and other Google Cloud Python libraries) uses standard Python logging. Log events may contain sensitive information, and their occurrence, level, and content are subject to change without being flagged as breaking.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}