Per-user cost attribution with the Gemini Developer API’s Interactions API

Hello,

We use the Gemini Developer API’s Interactions API for multiple users within one Google Cloud project. Our application records the user and analysis run associated with each request, along with the returned usage data.

We would like to associate these records with the actual charges reported by Google. We have checked Cloud Billing export to BigQuery, but have not found a way to link the billed amounts to individual users or analysis runs. We are also open to other supported reporting methods.

Before posting, we reviewed:

  • This earlier per-customer billing discussion, which recommends application-side usage tracking. We already maintain those records; our remaining question is how to connect them to Google’s actual charges.
  • python-genai issue #2296, concerning billing-label support for GenerateContentConfig. Since we use Interactions, we are unsure whether the same limitations apply.

We also tried attaching custom user and run labels to requests. The requests succeeded, and we verified that the labels were present in the outgoing request bodies, but we could not find them in the billing export. We have not found documentation stating that these labels should appear in billing data, so we are not assuming this is a defect.

Could you please advise whether there is a supported way to attribute actual charges to users or analysis runs within a shared Developer API project? If so, we would appreciate the relevant documentation or an example workflow. If not, could you please clarify what billing granularity is available?

We would prefer to continue using the Developer API with a shared project.

Thank you for your time and guidance.

Hi @Hyunsun_Choi,

  1. Request-Level labels (Interactions API & GenerateContent): On the Gemini Developer API, labels are request-level metadata (such as {“safety_identifier”: “user_session_123”}) and are not exported to Cloud Billing or BigQuery billing exports.
  2. Billing Granularity (Gemini API Billing): Usage across all requests and API keys is aggregated at the Google Cloud project level, broken down only by Project, Service (Gemini API), and SKU.
  3. Per-User / Per-Run Attribution (Pricing): Within a shared project, attribution must be done application-side by logging each Interaction’s usage object (total_input_tokens, total_output_tokens, total_cached_tokens, total_thought_tokens, and grounding_tool_count) and apportioning your project’s billed SKU totals (or applying pricing rates) across your logged runs.