Skip to content

feat(openai): apply regional-processing cost uplift for EU/US data residency#28622

Draft
mateo-berri wants to merge 2 commits into
litellm_internal_stagingfrom
claude/epic-goodall-T4V9Y
Draft

feat(openai): apply regional-processing cost uplift for EU/US data residency#28622
mateo-berri wants to merge 2 commits into
litellm_internal_stagingfrom
claude/epic-goodall-T4V9Y

Conversation

@mateo-berri

Copy link
Copy Markdown
Collaborator

Summary

OpenAI charges a flat 10% uplift on the latest GPT models when requests are served from a regionalized hostname (docs). LiteLLM didn't account for this; cost-tracking under-reported for any project on eu.api.openai.com / us.api.openai.com.

This PR adds regional-processing cost tracking that's fully driven by api_base — no new request parameter required.

Approach

  • Infer region from api_base host. OpenAI enforces a hostname-per-region for regionalized projects and rejects mismatches (confirmed by the requester on both directions), so the host is an authoritative signal:
    • eu.api.openai.com"eu"
    • us.api.openai.com"us"
    • anything else → None (global, no uplift)
  • Per-model multiplier in the price map. Added regional_processing_uplift_multiplier_eu / _us fields (e.g. 1.10) to the latest GPT models (gpt-5 family, gpt-4.1 family, gpt-4o family). Multiplier is applied at the end of generic_cost_per_token after service-tier resolution, so it composes cleanly with flex / priority.
  • Pre-resolved value on litellm_params. Custom callbacks can read kwargs["litellm_params"]["data_residency"] without having to parse the URL themselves.

Why multiplier instead of explicit _eu / _us cost-key variants like _flex / _priority? OpenAI's uplift is a uniform flat percentage across every token type, so a single multiplier captures it without bloating the price map with ~18 new keys per affected model.

Files

Area Change
litellm/litellm_core_utils/data_residency.py new helper infer_openai_data_residency(api_base)
litellm/litellm_core_utils/get_litellm_params.py populate litellm_params["data_residency"]
litellm/litellm_core_utils/llm_cost_calc/utils.py apply multiplier in generic_cost_per_token
litellm/litellm_core_utils/litellm_logging.py forward data_residency into the cost calculator
litellm/cost_calculator.py, litellm/llms/openai/cost_calculation.py plumb data_residency through cost_per_token / completion_cost / response_cost_calculator
litellm/types/utils.py DataResidency enum, new ModelInfo fields
model_prices_and_context_window.json (+ backup) regional_processing_uplift_multiplier_{eu,us} on gpt-5, gpt-5-mini, gpt-5-nano, gpt-5-pro, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, gpt-4o, gpt-4o-2024-08-06, gpt-4o-2024-11-20, gpt-4o-mini

Docs PR: BerriAI/litellm-docs#claude/epic-goodall-T4V9Y

Test plan

  • pytest tests/test_litellm/litellm_core_utils/test_data_residency.py — host-parsing helper (12 cases)
  • pytest tests/test_litellm/litellm_core_utils/test_get_litellm_params.py::TestGetLitellmParamsDataResidencylitellm_params["data_residency"] plumbing
  • pytest tests/test_litellm/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py -k data_residency — uplift applied, composes with priority, no-op for unmarked models / None
  • pytest tests/test_litellm/test_cost_calculator.py — full cost-calculator regression, 53 passing
  • pytest tests/test_litellm/llms/openai/ — OpenAI provider tests, 500 passing

https://claude.ai/code/session_012ebH44s7ohYxjoix5CXzTW


Generated by Claude Code

…sidency

OpenAI charges a 10% uplift on the latest GPT models when requests are
served from a regionalized hostname (eu./us.api.openai.com).  Infer the
region from `api_base`, expose it on `kwargs["litellm_params"]["data_residency"]`,
and multiply the computed cost by a per-model
`regional_processing_uplift_multiplier_<region>` field.

https://claude.ai/code/session_012ebH44s7ohYxjoix5CXzTW
@CLAassistant

CLAassistant commented May 22, 2026

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.

@mateo-berri mateo-berri changed the base branch from main to litellm_internal_staging May 22, 2026 16:50
@mateo-berri mateo-berri changed the base branch from litellm_internal_staging to litellm_oss_staging May 22, 2026 16:50
@codspeed-hq

codspeed-hq Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Congrats! CodSpeed is installed 🎉

🆕 16 new benchmarks were detected.

You will start to see performance impacts in the reports once the benchmarks are run from your default branch.

Detected benchmarks


Open in CodSpeed

...(data.refresh_token ? { refresh_token: data.refresh_token } : {}),
};
try {
window.sessionStorage.setItem(storageKey(serverId, userId), JSON.stringify(stored));
api_key: effectiveFilters[FILTER_KEYS.KEY_HASH] || undefined,
team_id: effectiveFilters[FILTER_KEYS.TEAM_ID] || undefined,
request_id: effectiveFilters[FILTER_KEYS.REQUEST_ID] || undefined,
user_id: effectiveFilters[FILTER_KEYS.USER_ID] || (filterByCurrentUser ? userID ?? undefined : undefined),
@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.21053% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/litellm_core_utils/llm_cost_calc/utils.py 77.77% 4 Missing ⚠️
litellm/litellm_core_utils/data_residency.py 84.61% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mateo-berri mateo-berri changed the base branch from litellm_oss_staging to litellm_internal_staging May 22, 2026 16:57
…r_* fields

The schema validation in test_aaamodel_prices_and_context_window_json_is_valid
runs with additionalProperties=False, so the new
regional_processing_uplift_multiplier_eu / _us fields on gpt-5,
gpt-5-mini, gpt-5-nano, gpt-5-pro, gpt-4.1 family, and gpt-4o family
entries must be declared in the test schema.

https://claude.ai/code/session_012ebH44s7ohYxjoix5CXzTW
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