litellm - ✅(Solved) Fix [Bug]: max_budget cannot be configured with environment variable [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#23843Fetched 2026-04-08 00:48:55
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Author
Participants
Timeline (top)
labeled ×2referenced ×2closed ×1cross-referenced ×1

Error Message

[long stack trace]

File "/usr/lib/python3.13/site-packages/litellm/proxy/proxy_server.py", line 859, in proxy_startup_event

if prisma_client is not None and litellm.max_budget > 0:

                                 ^^^^^^^^^^^^^^^^^^^^^^

TypeError: '>' not supported between instances of 'str' and 'int'

Root Cause

I configured the value max_budget with an environment variable. I expected to be able to do this, because in https://docs.litellm.ai/docs/proxy/configs, it says:

Fix Action

Fixed

PR fix notes

PR #23855: fix(proxy): convert max_budget to float when set via environment variable

Description (problem / solution / changelog)

Relevant issues

Fixes #23843

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Type

🐛 Bug Fix

Changes

When max_budget is set via environment variable (os.environ/MAX_BUDGET), it arrives as a string. The comparison litellm.max_budget > 0 in proxy_startup_event then raises TypeError: '>' not supported between instances of 'str' and 'int'.

Fix: convert max_budget to float() in initialize() before assigning to litellm.max_budget.

Changed files

  • litellm/proxy/proxy_server.py (modified, +33/-35)
  • tests/test_litellm/proxy/test_max_budget_env_var.py (added, +38/-0)

Code Example

[long stack trace]

File "/usr/lib/python3.13/site-packages/litellm/proxy/proxy_server.py", line 859, in proxy_startup_event

    if prisma_client is not None and litellm.max_budget > 0:

                                     ^^^^^^^^^^^^^^^^^^^^^^

TypeError: '>' not supported between instances of 'str' and 'int'
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

I configured the value max_budget with an environment variable. I expected to be able to do this, because in https://docs.litellm.ai/docs/proxy/configs, it says:

If you have secrets saved in your environment, and don't want to expose them in the config.yaml, here's how to load model-specific keys from the environment. This works for ANY value on the config.yaml

os.environ/<YOUR-ENV-VAR> # runs os.getenv("YOUR-ENV-VAR")

But the value could not be recognised, and the budget configuration was disabled.

Steps to Reproduce

  1. Add a budget to config.yaml litellm_settings: max_budget: os.environ/MAX_BUDGET and budget_duration: 30d
  2. Define the environment variable MAX_BUDGET so that LiteLLM will read it.
  3. Start LiteLLM
  4. The logs show an error.

I suspect the conversion from str to float is missing.

Relevant log output

[long stack trace]

File "/usr/lib/python3.13/site-packages/litellm/proxy/proxy_server.py", line 859, in proxy_startup_event

    if prisma_client is not None and litellm.max_budget > 0:

                                     ^^^^^^^^^^^^^^^^^^^^^^

TypeError: '>' not supported between instances of 'str' and 'int'

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v.1.82.0

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

To resolve the issue, you need to convert the max_budget environment variable to a float.

Here are the steps:

  • Update the config.yaml to use a template string that converts the environment variable to a float:
litellm_settings:
  max_budget: ${MAX_BUDGET:.0f}
  budget_duration: 30d

However, since the config.yaml does not support this conversion natively, you will need to modify the Python code that loads the configuration.

  • Modify the proxy_server.py to convert the max_budget to a float before using it:
import os

# ...

max_budget = float(os.environ.get('MAX_BUDGET'))
litellm.max_budget = max_budget

# ...

Alternatively, you can also modify the config.yaml loading code to support environment variable conversion.

Verification

To verify that the fix worked, restart LiteLLM and check the logs for any errors related to the max_budget configuration. You can also test the budget functionality to ensure it is working as expected.

Extra Tips

  • Make sure to handle cases where the MAX_BUDGET environment variable is not set or is not a valid float.
  • Consider adding input validation and error handling to ensure that the max_budget value is valid and can be converted to a float.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - ✅(Solved) Fix [Bug]: max_budget cannot be configured with environment variable [1 pull requests, 1 participants]