Optional labels field in Vertex AI request - #9175
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @vvidovic i'm confused were we not passing the Any non-openai param is passed along directly to the provider |
No, unfortunately, non-openai params are not passed directly to the provider. Here is the configuration excerpt for the two models from the example calls below: model_list:
- model_name: granite3-dense
litellm_params:
model: ollama/granite3-dense:2b
api_base: http://host.docker.internal:11435
input_cost_per_token: 0.00005
output_cost_per_token: 0.00005
- model_name: gemini-pro
litellm_params:
model: vertex_ai/gemini-1.5-pro
api_base: http://host.docker.internal:11435/
vertex_project: eu-p-ustd-its-genaigw-7144
# vertex_location:
vertex_credentials: /app/eu-p-ustd-its-genaigw-7144-ee0bb89f05bf.json
input_cost_per_token: 0.00005
output_cost_per_token: 0.00005Here is the curl -s http://0.0.0.0:4000/chat/completions -H "Authorization: Bearer $ut2" -H 'Content-Type: application/json' -d '{ "model": "gemini-pro", "messages": [ { "role": "user", "content": "respond in 20 words. who are you?" } ], "user": "vedran", "metadata": { "md_key": "md_value" }, "labels": {"client": "my label"}, "seed": 42, "new_key1": "new value 1", "new_key2": "new value 2", "new_map": {"mk1": "mv1", "mk2": "mv2"} }'The request sent to the backend, as visible in the Note: I didn't pass this request to the real Google Vertex AI during this test but configured the backend for both, Ollama and Vertex AI to be a local Ollama for debugging purposes. Here is the curl -s http://0.0.0.0:4000/chat/completions -H "Authorization: Bearer $ut2" -H 'Content-Type: application/json' -d '{ "model": "granite3-dense", "messages": [ { "role": "user", "content": "respond in 20 words. who are you?" } ], "user": "vedran", "metadata": { "md_key": "md_value" }, "labels": {"client": "my label"}, "seed": 42, "new_key1": "new value 1", "new_key2": "new value 2", "new_map": {"mk1": "mv1", "mk2": "mv2"} }'In the Ollama request sent to the backend:
|
|
@krrishdholakia - here are the lines where the request is built for the Gemini calls (function Only a subset of params from the |
|
@krrishdholakia - please let me know if there is anything else I can do about this PR (more examples or tests). |
|
@ishaan-jaff - did you have time to check this PR? |
If the client sets the `labels` field in the request to the LiteLLM: - pass the `labels` field to the Vertex AI backend If the client sets the `metadata` field in the request to the LiteLLM: - if the `labels` field is not set, fill it with `metadata` key/value pairs for all string values
87ec54c to
d3b804a
Compare
|
Hi, this one is important for Vertex AI users. Unfortunately, the Google costs can't be simply calculated from token usage. They do apply some custom logic to bill customers, based on variable prices agreed for customers and depending on the number of requests and tokens (progressively cheaper prices per token when the number of calls/tokens increases). Can you please check this small PR and see if it can be merged to the main branch so this functionality becomes available in some of the next releases? |
|
Hi @vvidovic there seems to be some provider specific filtering here - which makes sense. This (hardcoding specific non-llm provider k, v pair) is probably not the pattern we want to adopt. We can either:
Which would make more sense to you as a user? |
To me, the However, if you think it is too much to find and add such mappings for all providers/vendors, I guess the |
I don't have much to add to my last comments. |
|
@krrishdholakia & @ishaan-jaff Please let us know if there is any update/ blocker for this PR. This is a must have feature for cost observability in Vertex-AI |
|
@krrishdholakia I am also looking at this feature in order to understand the consumption of llm based on labels used, if you are looking for something else to be part of this PR. please do let us know ,happy to contribute |
|
@vvidovic can you update the vertex ai doc, telling people this exists? i'm sure people would find this very useful |
- Add LlmProviders import for provider filtering - Add metadata-to-labels conversion for OpenAI-style metadata - Add provider-aware filtering to exclude labels from Google GenAI/AI Studio - Update tests to verify correct behavior: * Labels are included for Vertex AI endpoints * Labels are excluded for Google GenAI endpoints * Metadata is converted to labels only for Vertex AI - Remove extra_body handling (not in upstream implementation) This aligns with the upstream BerriAI/litellm implementation that was merged through PRs BerriAI#9175, BerriAI#14563, and BerriAI#14448. Fixes BerriAI#13692 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…ertexai_labels Optional `labels` field in Vertex AI request
If the client sets the
labelsfield in the request to the LiteLLM:labelsfield to the Vertex AI backendIf the client sets the
metadatafield in the request to the LiteLLM:labelsfield is not set, fill it withmetadatakey/value pairs for all string valuesTitle
Optional
labelsfield in Vertex AI requestRelevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit)[https://docs.litellm.ai/docs/extras/contributing_code]Type
🆕 New Feature
✅ Test
Changes
labelsfield to the Vertex AI backend (use thelabelsormetadatafield from the client request)