feat(vantage): include organization metadata in FOCUS Tags export#28184
feat(vantage): include organization metadata in FOCUS Tags export#28184milan-berri wants to merge 1 commit into
Conversation
Join LiteLLM_OrganizationTable when building Vantage/FOCUS export rows so organization_id and organization_alias appear in Tags for org-level filtering. Co-authored-by: Cursor <cursoragent@cursor.com>
Greptile SummaryThis PR extends the Vantage/FOCUS export pipeline to include organization metadata (
Confidence Score: 5/5Small, focused change confined to the FOCUS export pipeline; the LEFT JOIN is additive and cannot drop existing rows, and the transformer's column-presence guard prevents any breakage when the new fields are absent. The SQL change is a straightforward additive LEFT JOIN — NULL-safe throughout the join chain — and the transformer correctly omits the new keys when they are not present in the frame. Tests are mock-based, cover both the happy path and the missing-column case, and make no real network calls. No existing tests were weakened or removed. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/integrations/focus/database.py | Adds LEFT JOIN to LiteLLM_OrganizationTable via COALESCE(vt.organization_id, tt.organization_id) and selects organization_id/organization_alias; non-breaking, correct NULL handling through the LEFT JOIN chain. |
| litellm/integrations/focus/transformer.py | Adds organization_id and organization_alias to _TAG_KEYS; the existing available_keys filter (if k in frame.columns) correctly handles rows where these columns are absent. |
| tests/test_litellm/integrations/focus/test_focus_database.py | Adds mock-based test asserting the generated SQL contains the org JOIN and COALESCE select; no real network calls. |
| tests/test_litellm/integrations/focus/test_transformer.py | New test file covering both presence and absence of org fields in Tags JSON output; no real network calls, covers the happy path and the null/missing column case. |
Reviews (1): Last reviewed commit: "feat(vantage): include organization meta..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Linear ticket
Resolves LIT-2895
Docs
Companion docs PR: BerriAI/litellm-docs#162
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
Local verification against
db_berriaiafter seeding org-linked team, key, and daily spend:POST /vantage/dry-run—usage_dataincludes organization fields:{ "api_key": "vantage_org_seed_api_key_hash_001", "organization_id": "840fa8b4-9ada-48b7-be52-6957dcce30a5", "organization_alias": "repro_org_1778259917", "team_id": "team_m2a_1777028518", "team_alias": "M2 A" }normalized_dataTags (FOCUS export payload):{ "team_id": "team_m2a_1777028518", "team_alias": "M2 A", "organization_id": "840fa8b4-9ada-48b7-be52-6957dcce30a5", "organization_alias": "repro_org_1778259917", "user_id": "default_user_id", "api_key_alias": "vantage-org-seed-key", "model": "gpt-4o", "model_group": "gpt-4o", "custom_llm_provider": "openai" }Unit tests:
poetry run pytest tests/test_litellm/integrations/focus/test_focus_database.py \ tests/test_litellm/integrations/focus/test_transformer.py -v # 7 passedType
🆕 New Feature
Changes
Problem
Vantage/FOCUS export reads from
LiteLLM_DailyUserSpendand maps team →SubAccountId/SubAccountName, but organization is not included anywhere in the export. Customers using LiteLLM organizations cannot filter or allocate LLM spend by org in Vantage today.Solution
Include organization metadata in the existing user-level export (non-breaking):
FocusLiteLLMDatabase— JOINLiteLLM_OrganizationTableviaCOALESCE(vt.organization_id, tt.organization_id)and selectorganization_id,organization_alias.FocusTransformer— Add those fields to_TAG_KEYSso they appear in FOCUSTagsJSON (Vantage-supported column for custom metadata).Org resolution order: API key
organization_idfirst, then teamorganization_id.Files changed
litellm/integrations/focus/database.pylitellm/integrations/focus/transformer.pyorganization_id,organization_aliasin Tagstests/test_litellm/integrations/focus/test_focus_database.pytests/test_litellm/integrations/focus/test_transformer.pyTest plan
poetry run pytest tests/test_litellm/integrations/focus/test_focus_database.py tests/test_litellm/integrations/focus/test_transformer.py -v/vantage/dry-runwith org-linked key/team/spend shows org inusage_dataandTags