Skip to content

Connect UI to "LiteLLM_DailyUserSpend" spend table - enables usage tab to work at 1m+ spend logs #9603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 28, 2025

Conversation

krrishdholakia
Copy link
Contributor

@krrishdholakia krrishdholakia commented Mar 28, 2025

Title

Screenshot 2025-03-27 at 7 32 34 PM

API Request

curl -L -X GET 'http://localhost:4000/user/daily/activity?start_date=2025-03-20&end_date=2025-03-27' \
-H 'Authorization: Bearer sk-...'

API Response

{
    "results": [
        {
            "date": "2025-03-27",
            "metrics": {
                "spend": 0.017707200000000003,
                "prompt_tokens": 111,
                "completion_tokens": 1711,
                "total_tokens": 1822,
                "api_requests": 11
            },
            "breakdown": {
                "models": {
                    "gpt-4o-mini": {
                        "spend": 1.095e-05,
                        "prompt_tokens": 37,
                        "completion_tokens": 9,
                        "total_tokens": 46,
                        "api_requests": 1
                    },
                    "mistral-large": {
                        "spend": 0.006016,
                        "prompt_tokens": 13,
                        "completion_tokens": 497,
                        "total_tokens": 510,
                        "api_requests": 3
                    },
                    "claude-3-5-sonnet-20241022": {
                        "spend": 0.003546,
                        "prompt_tokens": 17,
                        "completion_tokens": 233,
                        "total_tokens": 250,
                        "api_requests": 1
                    },
                    ...
                },
                "providers": {
                    "openai": {
                        "spend": 1.095e-05,
                        "prompt_tokens": 37,
                        "completion_tokens": 9,
                        "total_tokens": 46,
                        "api_requests": 1
                    },
                    "azure_ai": {
                        "spend": 0.006016,
                        "prompt_tokens": 13,
                        "completion_tokens": 497,
                        "total_tokens": 510,
                        "api_requests": 3
                    },
                    ...
                },
                "api_keys": {
                    "3126b6eaf1cb90dbde0b4e4da3028c995bb1d564419750e5cbbe684b07c221bf": {
                        "spend": 0.00156375,
                        "prompt_tokens": 47,
                        "completion_tokens": 386,
                        "total_tokens": 433,
                        "api_requests": 3
                    },
                    ...
                }
            }
        },
        {
            "date": "2025-03-26",
            "metrics": {
                "spend": 0.7097595000000197,
                "prompt_tokens": 280879,
                "completion_tokens": 374963,
                "total_tokens": 655842,
                "api_requests": 3
            },
            "breakdown": {
                "models": {
                    "gpt-3.5-turbo": {
                        "spend": 0.0,
                        "prompt_tokens": 0,
                        "completion_tokens": 0,
                        "total_tokens": 0,
                        "api_requests": 1
                    },
                    "chatgpt-v-2": {
                        "spend": 0.7021125000000198,
                        "prompt_tokens": 280845,
                        "completion_tokens": 374460,
                        "total_tokens": 655305,
                        "api_requests": 1
                    },
                    "claude-3-5-sonnet-20241022": {
                        "spend": 0.007646999999999999,
                        "prompt_tokens": 34,
                        "completion_tokens": 503,
                        "total_tokens": 537,
                        "api_requests": 1
                    }
                },
                "providers": {
                    "unknown": {
                        "spend": 0.0,
                        "prompt_tokens": 0,
                        "completion_tokens": 0,
                        "total_tokens": 0,
                        "api_requests": 1
                    },
                    "azure": {
                        "spend": 0.7021125000000198,
                        "prompt_tokens": 280845,
                        "completion_tokens": 374460,
                        "total_tokens": 655305,
                        "api_requests": 1
                    },
                    "anthropic": {
                        "spend": 0.007646999999999999,
                        "prompt_tokens": 34,
                        "completion_tokens": 503,
                        "total_tokens": 537,
                        "api_requests": 1
                    }
                },
                "api_keys": {
                    "": {
                        "spend": 0.0,
                        "prompt_tokens": 0,
                        "completion_tokens": 0,
                        "total_tokens": 0,
                        "api_requests": 1
                    },
                    "a188e7b5ac1213f8ec14280b8fb122720b4478c4287851bb228c2ea5d297bf95": {
                        "spend": 0.7097595000000197,
                        "prompt_tokens": 280879,
                        "completion_tokens": 374963,
                        "total_tokens": 655842,
                        "api_requests": 2
                    }
                }
            }
        }
    ],
    "metadata": {
        "total_spend": 0.7274667000000198,
        "total_prompt_tokens": 280990,
        "total_completion_tokens": 376674,
        "total_api_requests": 14,
        "page": 1,
        "total_pages": 1,
        "has_more": false
    }
}

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on (make test-unit)[https://docs.litellm.ai/docs/extras/contributing_code]
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test

Changes

  • feat(spend_management_endpoints.py): expose new endpoint for querying user's usage at 1m+ spend logs

Allows user to view their spend at 1m+ spend logs

  • build(schema.prisma): add api_requests to dailyuserspend table

  • build(migration.sql): add migration file for new column to daily user spend table

  • build(prisma_client.py): add logic for copying over migration folder, if deploy/migrations present in expected location

enables easier testing of prisma migration flow

  • build(ui/): initial commit successfully using the dailyuserspend table on the UI

  • refactor(internal_user_endpoints.py): refactor /user/daily/activity to give breakdowns by provider/model/key

  • feat: feature parity (cost page) with existing 'usage' page

  • build(ui/): add activity tab to new_usage.tsx

gets to feature parity on 'All Up' page of 'usage.tsx'

  • fix(proxy/utils.py): count number of api requests in daily user spend table

allows us to see activity by model on new usage tab

  • style(new_usage.tsx): fix y-axis to be in ascending order of date

  • fix: fix linting errors

  • fix: fix ruff check errors

Copy link

vercel bot commented Mar 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 28, 2025 5:27am

gets to feature parity on 'All Up' page of 'usage.tsx'
… table

allows us to see activity by model on new usage tab
@krrishdholakia krrishdholakia merged commit cdcc8ea into main Mar 28, 2025
35 of 39 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.

1 participant