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.
  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_v1_XXXXXX_XXXXXX_XXXXXX (the suffix is your billing account ID).
  4. Click the table, then click Details. The full table ID is shown as project-id.dataset.table_name.
  5. 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. Click the new service account, go to the Keys tab.
  8. Click Add Key > Create new key > JSON.
  9. 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.

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.table_name).
  6. Optionally add a label (e.g. Production — Google AI).
  7. Click Test Connection — a green checkmark confirms the credentials work and the table is accessible.
  8. 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 via the automated cron job to pull newly exported billing records.

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
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
Generative Language APIGoogle AI Studio (Gemini Developer API)
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 cron sync captures the latest available data. For the most current view, click Force Sync on your integration card.

Troubleshooting

"Test Connection" fails

  • Verify the JSON key: Make sure you pasted the entire JSON file, including the opening and closing braces. The key should contain fields like project_id, client_email, and private_key.
  • Check the table path: The format must be project-id.dataset.table_name with exactly two dots. You can find it in the BigQuery Console under the table's Details tab.
  • Verify IAM roles: The service account needs both BigQuery Data Viewer and BigQuery Job User. Go to IAM & Admin > IAM to check.

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.