Google AI Integration

Track Gemini model costs from Google AI Studio and Vertex AI using BigQuery billing export.

Overview

Grafient tracks your Gemini API spending by reading your Google Cloud billing data from BigQuery. This covers both Google AI Studio and Vertex AI - any Gemini usage that appears on your Cloud Billing account is tracked automatically.

Unlike OpenAI or Anthropic, Google does not provide a dedicated cost API. Instead, Google Cloud streams all billing records into a BigQuery table when you enable billing export. Grafient queries this table daily to pull your Gemini costs, broken down by model and token type.

BigQuery queries run using your service account credentials in your GCP project. The query cost is billed to your Google Cloud account - typically fractions of a cent per sync (a billing export table is very small).

Prerequisites

  • A Google Cloud project with billing enabled (required for paid-tier Gemini API usage).
  • Owner or Billing Account Administrator role on the Cloud Billing account - needed to enable the billing export.
  • A Grafient account on the Free, Pro, or Ultimate plan.

Step 1: Enable BigQuery Billing Export

If you already have billing export enabled, skip to Step 2.

  1. Go to the Google Cloud Console.
  2. Navigate to Billing > Billing export (or search for "Billing export" in the top search bar).
  3. Click the BigQuery export tab.
  4. Click Edit settings next to Detailed usage cost data. Make sure you enable the Detailed export, not Standard - the standard export does not include the per-service breakdown Grafient needs.
  5. Select a project to host the BigQuery dataset (this can be any project in your organization).
  6. Select an existing BigQuery dataset or create a new one (e.g. billing_export).
  7. Click Save.

Use a multi-region dataset (US or EU) if you want retroactive data. Google backfills up to the start of the current month for new exports. Historical data before the export was enabled is not available.

Once enabled, Google begins streaming billing records into the dataset. Initial data may take a few hours to appear.

Step 2: Find Your BigQuery Table Name

  1. Go to BigQuery Console.
  2. In the left sidebar, expand your project and the dataset you selected in Step 1.
  3. You'll see a table named like gcp_billing_export_resource_v1_XXXXXX_XXXXXX_XXXXXX (the suffix is your billing account ID).

Don't see the table? It's created automatically when Google delivers the first batch of billing data, which can take a few hours up to 24 hours after enabling the export. If your dataset is empty, wait and check back later. Make sure the export status shows "Enabled" under Billing > Billing export.

  1. Click the table, then click Details. The full table ID is shown as project-id.dataset.table_name.
  2. Copy this full table ID - you'll need it in Step 4.

Step 3: Create a Service Account

  1. In the Google Cloud Console, go to IAM & Admin > Service Accounts.
  2. Click Create Service Account.
  3. Name it something descriptive (e.g. grafient-reader).
  4. Click Create and Continue.
  5. Grant the following roles:
    • BigQuery Data Viewer (roles/bigquery.dataViewer) - read access to the billing table
    • BigQuery Job User (roles/bigquery.jobUser) - permission to run queries
  6. Click Done.
  7. Back on the Service Accounts list, click the service account you just created to open it.
  8. Go to the Keys tab.
  9. Click Add Key, then select Create new key.
  10. Choose JSON as the key type and click Create.
  11. Download the JSON key file. This contains the credentials Grafient needs.

These two roles follow the principle of least privilege - the service account can only read data and run queries. It cannot modify any billing settings, create resources, or access other GCP services.

"Service account key creation is disabled" - Many Google Cloud organizations enforce the iam.disableServiceAccountKeyCreation policy (often inherited from a parent organization as part of "Secure by Default" enforcements), which blocks JSON key creation. To resolve this:

  1. Go to Organization Policies and search for iam.disableServiceAccountKeyCreation.
  2. Click the policy, then click Manage Policy.
  3. Under Policy source, select Override parent's policy.
  4. Under Policy enforcement, select Not enforced.
  5. Click Set Policy, then retry creating the key.

This requires the Organization Policy Administrator (roles/orgpolicy.policyAdmin) role. If the Manage Policy button is grayed out, you need to grant yourself this role first:

  1. Go to IAM & Admin > IAM and switch to your organization (not a project) using the dropdown at the top.
  2. Click Grant Access, enter your email, and assign the Organization Policy Administrator role.
  3. Save, wait a moment for the permissions to propagate, then retry managing the policy.

You can re-enable the constraint after creating the key.

Step 4: Add the Integration in Grafient

  1. In Grafient, navigate to Integrations in the sidebar.
  2. Click Add Integration.
  3. Select Google AI as the provider.
  4. Paste the entire contents of the JSON key file into the Service Account JSON field.
  5. Enter the BigQuery table ID from Step 2 (format: project-id.dataset.gcp_billing_export_resource_v1_XXXXXX_XXXXXX_XXXXXX).
  6. Optionally add a label (e.g. Production - Google AI).
  7. Click Add Integration to save.

What Happens Next

Once connected, Grafient will:

  1. Validate your credentials by running a test query against the billing table.
  2. Backfill historical costs - up to 30 days on Free, or 365 days on Pro/Ultimate (limited by what's in your billing export).
  3. Sync daily - an automated sync pulls newly exported billing records each day.

Costs appear on the Dashboard grouped by Gemini model (e.g. Gemini 2.5 Flash, Gemini 2.5 Pro).

Data Collected

Data PointDescription
Daily cost (USD)Total Gemini spend per day, broken down by model. Costs are automatically normalized to USD using the billing export's currency_conversion_rate, so non-USD billing accounts are handled correctly.
Model breakdownCost per Gemini model (e.g. Gemini 2.5 Flash, Gemini 2.0 Flash Lite)
Input tokensToken count for input (text, audio, image, video)
Output tokensToken count for output (including thinking tokens)

Services Tracked

Grafient queries for both Google AI services:

ServiceDescription
Gemini APIGoogle AI Studio (newer billing exports)
Generative Language APIGoogle AI Studio (older billing exports)
Vertex AIGoogle Cloud Vertex AI Gemini endpoints

Both appear in the same billing export. If you use Gemini through either service, the costs are captured automatically.

Data Freshness

Google Cloud billing export has a 12–24 hour delay. Cost data from today will typically appear in BigQuery tomorrow. This is a Google Cloud limitation - the billing pipeline does not export in real time.

The daily sync captures the latest available data. For the most current view, click Force Sync on your integration card.

Troubleshooting

No cost data after sync

  • Check export timing: If you just enabled billing export, data may take several hours to appear. Google backfills from the start of the current month.
  • Verify Gemini usage: If there has been no Gemini API usage, there will be no cost data. Check the Google Cloud Console billing reports to confirm charges exist.
  • Try Force Sync: Click the refresh icon on your integration card to trigger a manual sync.

Cost data looks incomplete

  • Export start date: BigQuery billing export only contains data from when it was first enabled. Historical data before the export was turned on is not available.
  • Data delay: Due to the 12–24 hour export delay, yesterday's costs may not have arrived yet. Check again tomorrow.
  • Non-Gemini costs: Grafient only tracks Gemini model costs. Other GCP services (Compute Engine, Cloud Storage, etc.) are filtered out.

Data stops at an old date

New billing exports from Google can take some time to backfill into BigQuery. If you notice a gap, try a Force Sync and keep monitoring - the data usually catches up within a day or two. If costs remain stuck at an old date and are not updating after several days, reach out to support.