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

> Source: <https://dev.to/gde/gcp-billing-vertex-ai-solving-gemini-cost-allocation-in-a-single-project-vertex-ai-dynamic-5aok>
> Published: 2026-07-12 15:09:09+00:00

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.

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.

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!

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

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:

`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.

For the `google-genai`

Python SDK, we have two main modification scenarios:

`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
    )
)
```

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
    ),
)
```

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:

`_create_chat_config()`

to add labels to both general Q&A and Grounding conversations.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:

``` python
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]:

``` python
# 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"})
```

This modification successfully injected the `client_id=info_helper`

label into all Vertex AI API calls within the LINE Bot project.

`labels`

, GCP billing data usually has a 24 to 48-hour delay before taking effect.`client_id`

.`info_helper`

as a separate billing row, perfectly solving the problem of separating project costs for reimbursement and statistics!
