[GCP Billing & Vertex AI] Solving Gemini Cost Allocation in…
    Neura MarketNeura Market/Gemini
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityDeepSeekDeepSeek
    CoPilotCoPilotStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsGamesBlogVideosGuidesCoursesCommunityGemsExtensionsTrending
    GeminiBlog[GCP Billing & Vertex AI] Solving Gemini Cost Allocation in a Single Project: Vertex AI Dynamic Billing Labels in Action
    Back to Blog
    [GCP Billing & Vertex AI] Solving Gemini Cost Allocation in a Single Project: Vertex AI Dynamic Billing Labels in Action
    ai

    [GCP Billing & Vertex AI] Solving Gemini Cost Allocation in a Single Project: Vertex AI Dynamic Billing Labels in Action

    Evan Lin July 9, 2026
    0 views

    Pain Point: How to Accurately Allocate Gemini API Costs Within the Same Project? When...

    Pain Point: How to Accurately Allocate Gemini API Costs Within the Same Project?

    When developing enterprise-level LLM services or operating multi-tenant platforms, the question most frequently asked by finance and operations teams is:

    "We have many different business lines and LINE Bots connected within the same GCP project. Every day, the Gemini Key costs all appear under the Gemini API category. Is there a way for us to split the costs based on different Gemini Keys or different users?"

    Direct answer to your question: In Google Cloud Billing reports, it is not possible to directly display costs "based on different API Key names." The smallest attribution dimensions for Google Cloud billing reports are "Project," "Service," and "SKU (Product Line Item)." The system does not treat individual API Key strings as independent billing items. For the billing system, whether you create 10 or 100 API Keys within the same project, they will all be lumped together as a single Gemini API total.


    A Workaround: Vertex AI "Request Labels" to the Rescue

    If architectural constraints force you to stay within the same project, the most recommended approach is: switch to Vertex AI calls and use "Request Labels."

    If you are currently using a Google AI Studio API Key, it cannot pass billing labels within a single project. However, if you change your code to call the Vertex AI Gemini API (still within the same project), Vertex AI supports dynamically including custom labels with each request.

    Principle and Workflow

    When sending each request (e.g., calling generateContent), include specific metadata in the API Request:

    {
      "contents": { ... },
      "labels": {
        "client_id": "info_helper",
        "api_key_group": "marketing_team"
      }
    }
    
    

    These custom labels are passed directly to the GCP billing system. Later, when you go to the GCP Billing report and select your set label key (e.g., client_id) in "Group by," you can clearly see the costs for different labels (representing different services, clients, or users) within the same project!


    Project Implementation: Full Adoption of the Labels Mechanism

    To fulfill this requirement, we audited the current API call architecture of the LINE Bot project and performed the following refactoring.

    1. Project API Call Audit

    Through scanning, we found that the vast majority of calls in the project use Vertex AI (14 out of 17 clients use vertexai=True), with only a few exceptions:

    • Vertex AI calls: Including GitHub summaries, multiple Google Maps Grounding tools, text summarization, image analysis, speech-to-text, etc. (total of 11 files, 19 call points).
    • Gemini API Key calls: Live API in main.py, Batch service in batch_service.py, and TTS speech synthesis in tts_tool.py.

    [!IMPORTANT] The labels parameter is only supported by Vertex AI. If this parameter is included under an API Key (vertexai=False), it will cause the SDK to throw an error. Therefore, we only modified the 11 files that use Vertex AI.

    2. Implementation Method

    For the google-genai Python SDK, we have two main modification scenarios:

    Scenario A: Already contains GenerateContentConfig

    If the original call already includes a Config, we just need to pass an additional labels={"client_id": "info_helper"} into the config:

    # Before (e.g., loader/gh_tools.py)
    response = client.models.generate_content(
        model="gemini-2.5-flash",
        contents=prompt,
        config=types.GenerateContentConfig(
            temperature=0,
            max_output_tokens=2048,
        )
    )
    
    # After
    response = client.models.generate_content(
        model="gemini-2.5-flash",
        contents=prompt,
        config=types.GenerateContentConfig(
            temperature=0,
            max_output_tokens=2048,
            labels={"client_id": "info_helper"}, # Include billing label
        )
    )
    
    

    Scenario B: No Config parameter

    If the original call is very simple (e.g., searchtool.py or youtube_gcp.py), we need to proactively include a GenerateContentConfig containing labels:

    # Before (e.g., loader/searchtool.py)
    response = client.models.generate_content(
        model="gemini-3.1-flash-lite-preview",
        contents=prompt,
    )
    
    # After
    response = client.models.generate_content(
        model="gemini-3.1-flash-lite-preview",
        contents=prompt,
        config=types.GenerateContentConfig(
            labels={"client_id": "info_helper"}, # Add config to include label
        ),
    )
    
    

    3. List of Modified Files

    We performed precise modifications on a total of 19 call points across the following 11 files, and used Python's AST module (ast.parse) and Flake8 for syntax and formatting checks before submission:

    1. agents/chat_agent.py: Modify _create_chat_config() to add labels to both general Q&A and Grounding conversations.
    2. loader/chat_session.py: Include labels in Chat session config.
    3. loader/gh_tools.py: GitHub summary API.
    4. loader/langtools.py: Text summarization, image JSON generation, social media post generation.
    5. loader/maps_grounding.py: Maps search API.
    6. loader/searchtool.py: Keyword extraction tool.
    7. loader/youtube_gcp.py: YouTube video understanding API.
    8. tools/audio_tool.py: Asynchronous speech-to-text.
    9. tools/maps_tool.py: 5 call points including nearby search, restaurant name extraction, batch and review search, etc.
    10. tools/summarizer.py: Text summarization and Agentic Vision image understanding.
    11. tools/youtube_tool.py: YouTube summary tool.

    Pitfall Guide: Watch Out for SDK Module Import Issues

    When refactoring calls without Config for youtube_gcp.py and youtube_tool.py, since these two files originally only used named imports for specific types:

    from google.genai.types import HttpOptions, Part
    
    

    When we write types.GenerateContentConfig(...) in the code, the system throws a NameError: name 'types' is not defined error.

    Solution: We need to correct the import statement and directly import GenerateContentConfig:

    # Before
    from google.genai.types import HttpOptions, Part
    
    # After
    from google.genai.types import HttpOptions, Part, GenerateContentConfig
    
    

    And use it directly in the call without the types. prefix:

    config=GenerateContentConfig(labels={"client_id": "info_helper"})
    
    

    Summary and Next Steps

    This modification successfully injected the client_id=info_helper label into all Vertex AI API calls within the LINE Bot project.

    1. Billing Delay: Please note that after we start including labels, GCP billing data usually has a 24 to 48-hour delay before taking effect.
    2. Configure in GCP Billing: After two days, you can go to the GCP Console -> Billing -> Reports. In the "Group by" section on the right, select Labels and enter our key client_id.
    3. Mission Accomplished: At this point, the report will draw info_helper as a separate billing row, perfectly solving the problem of separating project costs for reimbursement and statistics!

    Tags

    aicloudgooglellm

    Comments

    More Blog

    View all
    Automated GitHub Code Reviews Using Google Geminigithubactions

    Automated GitHub Code Reviews Using Google Gemini

    I Built a Thing! TL;DR — Google Gemini-based Pull Request reviews and Issue Triaging for...

    D
    Darren "Dazbo" Lester
    Stop Your LLMs from Forgetting (Part 2): How a Graph-Anchor Pyramid Cures AI’s Relational Blindspotsai

    Stop Your LLMs from Forgetting (Part 2): How a Graph-Anchor Pyramid Cures AI’s Relational Blindspots

    Have you ever had a brilliant solution get completely crushed by a single comment on a technical blog...

    T
    Tanaike
    Remote Control Antigravity - Migrating to new Antigravity ecossytem and fully autonomous goalsantigravity

    Remote Control Antigravity - Migrating to new Antigravity ecossytem and fully autonomous goals

    In my previous post, we explored how to build an AI-powered IDE companion app from scratch using...

    M
    Marcelo Costa
    Stop Your LLMs from Forgetting: How a 2016 String Algorithm Solves AI's Biggest Memory Loss Problemai

    Stop Your LLMs from Forgetting: How a 2016 String Algorithm Solves AI's Biggest Memory Loss Problem

    Have you ever tried to read a massive pile of reports and summarize them in under 50 words? It’s...

    T
    Tanaike
    Google VP of Technology says he’s given up on codingaie

    Google VP of Technology says he’s given up on coding

    In his keynote on Wednesday, Benoit Schillings, vice president of Technology at Google DeepMind and...

    I
    Iain Thomson
    Omni Flash Preview with Kirogemini

    Omni Flash Preview with Kiro

    This article covers the MCP setup and configuration for using Google Omni Preview and underlying...

    X
    xbill

    Stay up to date

    Get the latest Gemini prompts, rules, and resources delivered to your inbox weekly.

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for Gemini and more.

    Content Types

    • Rules
    • Prompts
    • MCPs
    • Agents
    • Guides

    Platforms

    • ChatGPT Directory
    • Claude Directory
    • Gemini Directory
    • Cursor Directory
    • Grok Directory
    • Perplexity Directory
    • DeepSeek Directory
    • CoPilot Directory
    • Stable Diffusion Directory
    • Midjourney Directory
    • All Directories

    Resources

    • Blog
    • Documentation
    • Help Center
    • Marketplace

    Legal

    • Privacy Policy
    • Terms of Service

    © 2026 Neura Market. All rights reserved.

    |

    Not affiliated with any AI platform vendors.

    Neura Market

    Custom AI Systems & Services

    Our team of experienced AI builders will help build custom AI systems, workflows, and solutions for your business.

    Request custom work

    Ready-made automations for this

    Workflows from the Neura Market marketplace related to this Gemini resource

    • Dynamic Line Chart Generation for Healthcare Billing Insightsn8n · $4.08 · Related topic
    • Automate Player Creation and Point Allocation in Pointagram from Excelmake · $3.99 · Related topic
    • Automated HTTP Update Webhook for Healthcare Billing & Insurancen8n · $10.36 · Related topic
    • Automate Client Billing and Invoice Generation with Gmail and QuickBooksn8n · $9.99 · Related topic
    Browse all workflows