Skip to content

Conversation

@JamesMcMinn
Copy link
Contributor

@JamesMcMinn JamesMcMinn commented Dec 5, 2025

Fixes https://linear.app/fullfact/issue/AI-1649/add-ability-to-add-labels-to-vertex-calls-in-genai-utils

Allows calls to optionally add labels when running the prompt. These can then be used to track requests for monitoring and billing purposes.

It also looks for an environment variables that are prefixed with GENAI_LABEL_ (e.g. GENAI_LABEL_SERVICE=cheese becomes the label service: cheese) which will let us set labels without necessarily needing to make code changes.


Pull request checklist

  • I have linked my PR to an issue
  • I’ve used conventional commits
  • My branch is up-to-date with main
  • Where appropriate, I have added or updated tests
  • Where appropriate, I have updated documentation to reflect my changes

@JamesMcMinn JamesMcMinn marked this pull request as ready for review December 5, 2025 12:14
@JamesMcMinn JamesMcMinn requested a review from dearden December 5, 2025 12:14
@github-actions
Copy link

github-actions bot commented Dec 5, 2025

❗ The branch name add-ability-to-add-labels-to-vertex-calls-in-genai-utils-ai-1649 does not follow the pattern [issue-number]-description-here.

In order to correctly link this PR to an issue, the branch name should be prefixed with the relevant issue number.

Please recreate this PR using required branch name structure (e.g. 42-add-ability-to-add-labels-to-vertex-calls-in-genai-utils-ai-1649).

Copy link
Contributor

@dearden dearden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. My only thought was that if there were other models in this library, it might make sense for the labelling stuff not to raise a GeminiError. But the aren't right now so it's all good.


if inline_citations and not use_grounding:
raise GeminiError("Inline citations only work if `use_grounding = True`")
merged_labels = DEFAULT_LABELS | labels
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you can either set labels as os variables, or as arguments? I think that makes sense/is good

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - the idea being that we might have some shared code and don't necessarily want to have to faff around adding logic to set the correct label for services X and Y if we can just bake them into the Dockerfile or Kubernetes config. The main thinking here is that it's easy to make sure new and existing services get e.g. GENAI_LABEL_SERVICE set, so we can track spend without having to add code to each project.

@JamesMcMinn JamesMcMinn merged commit 6e93131 into main Dec 8, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants