Skip to content

feat(proxy): let each app decide whether it may create unknown customers - #52485

Merged
devin-ai-integration[bot] merged 20 commits into
mainfrom
litellm_app_customer_provisioning
Nov 18, 2026
Merged

devin-ai-integration[bot] merged 20 commits into
mainfrom
litellm_app_customer_provisioning

Conversation

@moe-berri

@moe-berri moe-berri commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

Let admins define upsert rules per app on customer portal

Details

Link to Devin session: https://app.devin.ai/sessions/df57dd6feb764cd684428371c02d408b
Open in Devin Desktop: https://app.devin.ai/desktop/session/df57dd6feb764cd684428371c02d408b?variant=devin
Requested by: @moe-berri

Built on #52477, which adds the app model and is now on main.

TLDR

Problem this solves:

  • Any request can create a customer organization or member
  • An admin cannot limit that to chosen apps

How it solves it:

  • Each app gets a switch, "This app may create new customers"
  • One Gateway switch covers requests that belong to no app
  • Switch off, unknown customer: 403 and nothing is created
  • Known customers keep working with the switch off
  • Both switches default to on, so nothing changes by default

User Flow

Before: an admin wants only one app to onboard new tenants, but every app's first request for a new tenant creates it

  1. An app with a search team key sends POST https://litellm-domain/v1/chat/completions with x-litellm-customer-org-alias: new-tenant
  2. The response is 200, and new-tenant now exists as a customer organization

After: the admin turns the switch off for that app, and it can no longer create tenants

  1. The admin opens https://litellm-domain/ui/customers/settings, selects search, unchecks "This app may create new customers" and saves
  2. The app sends the same POST https://litellm-domain/v1/chat/completions with x-litellm-customer-org-alias: new-tenant
  3. The response is 403 Unknown customer in x-litellm-customer-org-alias. App search may not create customers., and no organization is created
  4. The same app with a tenant that already exists gets 200, and the coworker app still creates new tenants

App switch turned off for search

Gateway switch for requests with no app

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished

Screenshots / Proof of Fix

Real Postgres, one dedicated Redis on port 56379 for router and coordination state, 2 proxy workers on each proxy (two Started server process PIDs each), and real anthropic/claude-haiku-4-5 calls. The app definition is Teams, with teams coworker and search configured as apps, and one key with no team.

python litellm/proxy/proxy_cli.py --config config.yaml --num_workers 2 --detailed_debug --reload --use_v2_migration_resolver 2>&1 | tee litellm.log

Env var names: DATABASE_URL, LITELLM_MASTER_KEY, ANTHROPIC_API_KEY. config.yaml is a copy of litellm/proxy/dev_config.yaml with router_settings.redis_host/redis_port and general_settings.coordination_redis.host/port set to 127.0.0.1 and 56379.

curl -X PUT $BASE/management/v1/apps/definition -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"resource_type": "team"}'
curl -X POST $BASE/management/v1/apps -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"resource_id": "<search team id>"}'
# the switch, set in the UI in the run below
curl -X PATCH $BASE/management/v1/apps/<app_id> -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"auto_create_customers": false}'
curl -X PUT $BASE/management/v1/apps/definition -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"resource_type": "team", "auto_create_customers_without_app": false}'
# the request
curl -i -X POST $BASE/v1/chat/completions -H "Authorization: Bearer $SEARCH_KEY" -H "Content-Type: application/json" \
  -H "x-litellm-customer-org-alias: qa-search-unknown" -H "x-litellm-customer-member-id: qa-member" \
  -d '{"model": "anthropic-haiku-4-5", "messages": [{"role": "user", "content": "Reply with OK."}], "max_tokens": 10}'
# rows created
SELECT (SELECT COUNT(*) FROM "LiteLLM_CustomerOrganizationTable" WHERE alias='qa-search-unknown') AS organization_rows,
       (SELECT COUNT(*) FROM "LiteLLM_CustomerMemberTable" WHERE customer_member_id='qa-member') AS member_rows;

Before (6915477)

  1. The search key with an unknown tenant and member returns 200. There is no switch to turn off
  2. The row count is organization_rows 1, member_rows 1

After (72ef154)

App switch

  1. Default, switch on. The coworker key with a new tenant and member returns 200, and the count is 1 organization and 1 member
  2. search switched off in the UI. The search key with an unknown tenant returns 403, and the count is 0 and 0
{"error":{"message":"Unknown customer in x-litellm-customer-org-alias. App search may not create customers.","type":"auth_error","param":"x-litellm-customer-org-alias","code":"403"}}
  1. The search key with a known tenant and known member returns 200
  2. The search key with a known tenant and an unknown member returns 403, and no member row is created
{"error":{"message":"Unknown customer in x-litellm-customer-member-id. App search may not create customers.","type":"auth_error","param":"x-litellm-customer-member-id","code":"403"}}
  1. The coworker key with another new tenant still returns 200 and creates it
  2. A request with no customer headers returns 200 in every state

Requests with no app

  1. Default, switch on. The key with no team and a new tenant returns 200 and creates it
  2. "Requests with no app may create new customers" unchecked in the UI. The same kind of request with a new tenant returns 403 Requests that belong to no app may not create customers., and no row is created
  3. The same key with a known tenant and member returns 200
  4. Saving the definition as {"resource_type": "team"} without the switch keeps it off, and the definition stays Teams
  5. Switch checked again. A new tenant returns 200 and is created

Two workers

A change saved through one worker applied to the first request served by the other worker, between 0.04s and 0.67s after the save.

The 32 commands and their full output are in the collapsed block.

Case list from the run log
BEFORE base 6915477745 unknown search tenant expected 200
Default coworker creation expected 200 and 1 org / 1 member
Default no-app creation expected 200 and 1 org / 1 member
Regression all enabled, no headers expected 200
Search OFF: unknown organization expected 403 / no rows
Search OFF: known org and member expected 200
Search OFF: unknown member expected 403 / no member row
Coworker still ON: new org and member expected 200 / created
Regression search OFF, no headers expected 200
No-app OFF: unknown org expected 403 / no rows
No-app OFF: known org and member expected 200
No-app OFF: unknown member expected 403 / no member row
Regression no-app OFF, no headers expected 200
Regression both OFF, search no headers expected 200
Save Teams without no-app field: expected preserved false
No-app ON again: expected 200 / org and member created
AFTER 72ef154929 search OFF: identical unknown tenant expected 403 / no rows

Commits after 72ef154 only rename the app checkbox label and disable it while a save is pending, so the request behavior proven above is unchanged. AppsManager.integration.test.tsx covers both.

Tests

tests/unit/proxy/auth/test_customer_provisioning.py
tests/unit/proxy/auth/test_app_auth.py
tests/unit/proxy/auth/test_customer_hierarchy_auth.py
tests/unit/proxy/management_helpers/test_apps.py
tests/unit/proxy/management_endpoints/management_v1/test_apps.py
132 passed

Type

🆕 New Feature

Caveats (if any)

Severe

  • Boot migration adds one column to the app table
    • ADD COLUMN IF NOT EXISTS ... NOT NULL DEFAULT true, no row rewrite

Medium

  • A refused request returns 403, it does not run untracked
  • New apps default to on, an admin must turn each off
  • A member header with no organization header is refused when off
  • No list of which tenants an app may create

Low

  • Only the English locale has the new strings

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

Note

Medium Risk
Touches the auth and customer-hierarchy path and changes when new tenants may be created, but defaults keep prior behavior and refusal is explicit 403 instead of silent failure.

Overview
Adds per-app and gateway-level controls for whether requests may auto-register unknown customer organizations or members. Each app gets auto_create_customers (DB column, default true); gateway definition gains auto_create_customers_without_app for keys that map to no app.

During API key auth, customer hierarchy resolution uses gated registrars that skip creation when policy forbids it, and refuse_unknown_customer returns 403 with a message naming the offending header when the request references a customer the hierarchy could not resolve. Known customers still work when the switch is off.

AppStore and management types persist both settings; the dashboard exposes checkboxes on app settings and the app-definition page. A boot migration adds the app-table column with default true.

Reviewed by Cursor Bugbot for commit c5a73f6. Bugbot is set up for automated code reviews on this repo. Configure here.

ishaan-j-berri and others added 5 commits November 18, 2026 14:44
Let administrators choose Teams, Projects, or Virtual Keys as the gateway-wide app scope and assign customer budgets from existing budget groups.

Includes the shared budget-group integration from PR #52411 and builds on the existing app accounting implementation.
Use the existing dashboard controls and compact budget rows. Add app filtering to customer usage and retain trusted app context for budget rejections.

Update request-header handling, tracing registry coverage, bounded app discovery, and optional caller-metadata tests.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@veria-ai

veria-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

Reviews

…mber

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

Copy link
Copy Markdown
Contributor Author

@greptileai please review the current upsert-rule changes for correctness and authorization regressions. The configured checks on this stacked PR are passing.

Copy link
Copy Markdown
Contributor Author

bugbot run

Please review the current upsert-rule changes for incorrect customer creation, authorization gaps, and regressions in requests using existing customers.

@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The UI extraction appears safe to merge.

Summary

The latest change moves the no-app customer creation checkbox into CustomersWithoutAppSwitch without changing how it works. No new actionable issues were found.

  • Admins can choose whether each app or unassigned request creates unknown customers.

Reviews (3) · Last reviewed commit: "refactor(ui): move the no-app customer s..." · Reviewed by Greptile

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread litellm/proxy/auth/user_api_key_auth.py Resolved
…ion's budget

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

Copy link
Copy Markdown
Contributor Author

@greptileai please review the latest upsert-rule fix at 6ee9e15, including the unknown-customer refusal before budget checks. Configured CI checks pass.

Copy link
Copy Markdown
Contributor Author

bugbot run

Please verify the unknown-customer refusal fix at 6ee9e15 and review the current changes for remaining correctness issues.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

moe-berri and others added 4 commits November 18, 2026 08:50
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Let administrators choose Teams, Projects, or Virtual Keys as the gateway-wide app scope and assign customer budgets from existing budget groups.

Includes the shared budget-group integration from PR #52411 and builds on the existing app accounting implementation.
Use the existing dashboard controls and compact budget rows. Add app filtering to customer usage and retain trusted app context for budget rejections.

Update request-header handling, tracing registry coverage, bounded app discovery, and optional caller-metadata tests.
Enforce an authenticated app budget when optional customer and app headers are omitted. Normalize overlapping scalar and explicit budget windows to a single charge with the stricter cap and explicit reset time.

Cover all app primitives through native HTTP auth and use realistic empty gateway configuration in existing test doubles.

Copy link
Copy Markdown
Contributor Author

@greptileai please review the remaining UI settings extraction at c5a73f6. The prior backend fixes were reviewed and configured CI checks pass.

Copy link
Copy Markdown
Contributor Author

bugbot run

Please review the remaining UI settings extraction at c5a73f6 for regressions. The prior backend fixes were reviewed and configured CI checks pass.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c5a73f6. Configure here.

@tin-berri
tin-berri force-pushed the codex/customer-app-budget-scopes branch from 9706a91 to 677b9f1 Compare November 18, 2026 14:33
…omer_provisioning

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@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 all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ moe-berri
❌ ishaan-j-berri
You have signed the CLA already but the status is still pending? Let us recheck it.

ishaan-j-berri and others added 6 commits November 19, 2026 00:20
Use shared customer budget controls for app forms and resolve member budgets at one owner. Remove unused app lifecycle and listing routes.

Parse request identity once, check each global and app scope once, and keep app counters alive through the existing database flush window.
Persist the original trusted customer and app billing context on managed jobs. Restore it in batch and background cost polling with the original request time, preserving admission windows and existing claim behavior.

Recognize the India Bedrock model prefix in dashboard model setup.
…omer_provisioning

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Set the required migration lock timeout and add the billing-context column only if it is absent.

Use per-request completion test callbacks and await the MCP panel failure notification. Keep response, pricing, and complete callback-sequence assertions.
Use the upstream country-prefix handling to clear the model-setup merge conflict.
Base automatically changed from codex/customer-app-budget-scopes to main November 18, 2026 17:31
@moe-berri
moe-berri requested a review from a team November 18, 2026 17:31
moe-berri and others added 2 commits November 18, 2026 17:33
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ne helper

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot enabled auto-merge (squash) November 18, 2026 17:51
@moe-berri
moe-berri disabled auto-merge November 18, 2026 17:53
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.65217% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/proxy/auth/customer_provisioning.py 94.64% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 45 untouched benchmarks


Comparing litellm_app_customer_provisioning (2fedfbc) with main (8d80898)

Open in CodSpeed

@devin-ai-integration
devin-ai-integration Bot merged commit a435090 into main Nov 18, 2026
161 of 164 checks passed
@devin-ai-integration
devin-ai-integration Bot deleted the litellm_app_customer_provisioning branch November 18, 2026 19:42
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.

4 participants