Skip to content

fix(terraform): read team per-model rpm/tpm limits from metadata and clear them on removal - #40439

Merged
yassin-berriai merged 2 commits into
litellm_internal_stagingfrom
litellm_team_model_limits_read
Sep 10, 2026
Merged

yassin-berriai merged 2 commits into
litellm_internal_stagingfrom
litellm_team_model_limits_read

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • litellm_team accepts model_rpm_limit / model_tpm_limit but never reads them back
  • out-of-band changes to those limits are invisible to terraform plan
  • removing the maps from config leaves the limits on the proxy

How it solves it:

  • read the limits from team_info.metadata, where the proxy stores them
  • send an explicit {} on /team/update when a map is removed from config

User Flow

Before: a platform team manages LiteLLM teams with Terraform and cannot trust terraform plan for per-model limits

  1. They write a litellm_team with model_rpm_limit = { "gpt-4o-mini" = 100 } and model_tpm_limit = { "gpt-4o-mini" = 5000 } and run terraform apply
  2. GET http://localhost:4000/team/info?team_id= shows "metadata": {"model_rpm_limit": {"gpt-4o-mini": 100}, "model_tpm_limit": {"gpt-4o-mini": 5000}}, so creation works
  3. Someone bumps the limit from the Admin UI or with POST http://localhost:4000/team/update {"team_id": "<id>", "model_rpm_limit": {"gpt-4o-mini": 250}}
  4. terraform plan says No changes. Your infrastructure matches the configuration. even though the proxy now enforces 250
  5. They delete both maps from the .tf file and run terraform apply; Terraform prints Apply complete! Resources: 0 added, 1 changed
  6. GET /team/info still returns {"gpt-4o-mini": 250} and {"gpt-4o-mini": 5000}: the limits were never removed
  7. terraform import of an existing team followed by terraform plan always wants to re-add the maps, even when the proxy already has those exact values

After: terraform plan reflects what the proxy enforces and removing a map clears it

  1. Same litellm_team with both maps, terraform apply
  2. GET /team/info shows the same metadata as before
  3. Same out-of-band POST /team/update bumps the RPM limit to 250
  4. terraform plan now shows ~ "gpt-4o-mini" = 250 -> 100 and terraform apply sets the proxy back to 100
  5. They delete both maps from the .tf file and run terraform apply
  6. GET /team/info returns "model_rpm_limit": {}, "model_tpm_limit": {} and a follow-up terraform plan says No changes
  7. terraform import followed by terraform plan says No changes when the config matches the proxy

Relevant issues

Fixes BerriAI/terraform-provider-litellm#58

Linear ticket

Resolves LIT-6400

Pre-Submission checklist

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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Shared setup: LiteLLM proxy from this branch's merge base on http://127.0.0.1:20400 with Postgres, master key sk-1234, two model_list entries (gpt-4o-mini, anthropic-haiku-4-5, both backed by Anthropic). Terraform 1.13.3 with a dev_overrides entry pointing at a provider binary built from terraform/provider with go build. The proxy code is identical in both legs; only the provider binary changes. Fixture used in both legs:

resource "litellm_team" "t" {
  team_alias = "lit6400-per-model-limits"
  models     = ["gpt-4o-mini", "anthropic-haiku-4-5"]
  rpm_limit  = 1000
  model_rpm_limit = { "gpt-4o-mini" = 100 }
  model_tpm_limit = { "gpt-4o-mini" = 5000 }
}

INFO below is:

curl -s "http://127.0.0.1:20400/team/info?team_id=$TEAM_ID" -H 'Authorization: Bearer sk-1234' \
  | python3 -c 'import sys,json;d=json.load(sys.stdin)["team_info"];print(json.dumps({k:d["metadata"].get(k) for k in ("model_rpm_limit","model_tpm_limit")}))'

Before (096984b)

Case 1: out-of-band change on the proxy

  1. terraform apply -auto-approve, then INFO
    {"model_rpm_limit": {"gpt-4o-mini": 100}, "model_tpm_limit": {"gpt-4o-mini": 5000}}
    
  2. curl -s -X POST http://127.0.0.1:20400/team/update -H 'Authorization: Bearer sk-1234' -H 'Content-Type: application/json' -d '{"team_id":"'$TEAM_ID'","model_rpm_limit":{"gpt-4o-mini":250}}' -o /dev/null -w 'update http %{http_code}\n'; INFO
    update http 200
    {"model_rpm_limit": {"gpt-4o-mini": 250}, "model_tpm_limit": {"gpt-4o-mini": 5000}}
    
  3. terraform plan -no-color
    No changes. Your infrastructure matches the configuration.
    

Case 2: remove both maps from config

  1. Delete both model_*_limit blocks from the fixture, terraform apply -auto-approve -no-color
          ~ model_rpm_limit             = {
              - "gpt-4o-mini" = 100 -> null
          ~ model_tpm_limit             = {
              - "gpt-4o-mini" = 5000 -> null
    Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
    
  2. INFO
    {"model_rpm_limit": {"gpt-4o-mini": 250}, "model_tpm_limit": {"gpt-4o-mini": 5000}}
    
  3. terraform plan -no-color
    No changes. Your infrastructure matches the configuration.
    

Case 3: import then plan

  1. Fresh directory with the same fixture, terraform import litellm_team.t $TEAM_ID, then terraform plan -no-color
      + model_rpm_limit = {
          + "gpt-4o-mini" = 100
        }
      + model_tpm_limit = {
          + "gpt-4o-mini" = 5000
        }
    Plan: 0 to add, 1 to change, 0 to destroy.
    

After (8808643)

Case 1: out-of-band change on the proxy

  1. terraform apply -auto-approve, then INFO
    {"model_rpm_limit": {"gpt-4o-mini": 100}, "model_tpm_limit": {"gpt-4o-mini": 5000}}
    
  2. Same POST /team/update to 250, then INFO
    update http 200
    {"model_rpm_limit": {"gpt-4o-mini": 250}, "model_tpm_limit": {"gpt-4o-mini": 5000}}
    
  3. terraform plan -no-color
      # litellm_team.t will be updated in-place
      ~ resource "litellm_team" "t" {
          ~ model_rpm_limit             = {
              ~ "gpt-4o-mini" = 250 -> 100
            }
    Plan: 0 to add, 1 to change, 0 to destroy.
    
  4. terraform apply -auto-approve, then INFO, then terraform plan -no-color
    Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
    {"model_rpm_limit": {"gpt-4o-mini": 100}, "model_tpm_limit": {"gpt-4o-mini": 5000}}
    No changes. Your infrastructure matches the configuration.
    

Case 2: remove both maps from config

  1. Delete both model_*_limit blocks from the fixture, terraform apply -auto-approve -no-color
          ~ model_rpm_limit             = {
              - "gpt-4o-mini" = 100 -> null
          ~ model_tpm_limit             = {
              - "gpt-4o-mini" = 5000 -> null
    Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
    
  2. INFO
    {"model_rpm_limit": {}, "model_tpm_limit": {}}
    
  3. terraform plan -no-color
    No changes. Your infrastructure matches the configuration.
    

Case 3: import then plan

  1. Fresh directory with the same fixture, terraform import litellm_team.t $TEAM_ID, then terraform plan -no-color
    Import successful!
    No changes. Your infrastructure matches the configuration.
    

Regression tests TestTeamReadMapsPerModelLimitsFromMetadata and TestTeamUpdateClearsRemovedPerModelLimits in terraform/provider/litellm/resource_team_test.go both fail on the merge base and pass on this branch (checked by swapping resource_team.go back to HEAD and running them)

Type

🐛 Bug Fix

Caveats (if any)

Low

  • a team whose proxy metadata has {} for a limit reads back as an empty map, which Terraform treats the same as an absent attribute
  • the top-level model_rpm_limit / model_tpm_limit keys in /team/info are still preferred if the proxy ever starts returning them there

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/9e85dfd3970b419ca00228e1343612b6
Open in Devin Desktop: https://app.devin.ai/desktop/session/9e85dfd3970b419ca00228e1343612b6?variant=devin
Requested by: @yassin-berriai

…clear them on removal

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR updates the Terraform team resource to synchronize per-model RPM and TPM limits with the proxy.

  • Reads per-model limits from team metadata when top-level values are absent.
  • Sends explicit empty maps when configured limits are removed.
  • Adds regression coverage for metadata reads and limit removal.
  • Removes the redundant source comments flagged in the previous review without changing behavior.

Confidence Score: 5/5

The PR appears safe to merge with no outstanding findings.

The only changes since the previous review remove the redundant comments identified by the resolved thread, leaving the reviewed behavior unchanged; no new issues or applicable rule violations were found.

Important Files Changed

Filename Overview
terraform/provider/litellm/resource_team.go Reads per-model limits from metadata and includes empty changed maps in update payloads; the previously flagged comment was removed.
terraform/provider/litellm/resource_team_test.go Adds regression tests for metadata synchronization and explicit limit clearing; the previously flagged comments were removed.

Reviews (2): Last reviewed commit: "chore(terraform): drop explanatory comme..." | Re-trigger Greptile

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

… helper and tests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please re-review 8808643, which drops the flagged comments and leaves the code unchanged

@yassin-berriai
yassin-berriai merged commit 4ddc5e2 into litellm_internal_staging Sep 10, 2026
83 of 84 checks passed
@yassin-berriai
yassin-berriai deleted the litellm_team_model_limits_read branch September 10, 2026 02:44
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.

enhancement: expose model_rpm_limit / model_tpm_limit on litellm_team

2 participants