litellm/scripts/generate_owned_kwargs.py
Yujong Lee 9cfb7d5394 refactor(rust): own the LiteLLM kwarg set in core-utils and stop forwarding metadata
The bridge asked Python's is_litellm_owned_kwarg about every request field
and unioned the answer with Rust's is_control_param, so the owned set lived
in two places and the gateway could not use it. core-utils now carries a
generated copy of all_litellm_params plus the _litellm_ prefix
(scripts/generate_owned_kwargs.py, kept fresh by a unit test) and exposes
one is_litellm_owned check; compose_body and the bridge projection both use
it. is_secret_param moves next to it.

metadata was forwarded to every provider. On chat and Responses it holds
LiteLLM's proxy metadata (key alias, team, budgets), which leaked upstream
and made the native chat path reject proxied calls. Each route now passes
the owned names its API defines as provider fields; chat and Responses
pass none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 09:15:58 -07:00

47 lines
1.5 KiB
Python

"""Writes the Rust copy of the kwarg names LiteLLM owns. Run from the repo root: `python -m scripts.generate_owned_kwargs`"""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
from typing import Final
from litellm.constants import INTERNAL_KWARG_PREFIX
from litellm.types.utils import all_litellm_params
ROOT: Final = Path(__file__).resolve().parents[1]
TARGET: Final = ROOT / "litellm-rust/crates/core-utils/src/params/owned.rs"
HEADER: Final = (
"// @generated by `python -m scripts.generate_owned_kwargs` from `litellm.types.utils.all_litellm_params`."
" Do not edit\n"
)
def render() -> str:
names: Final = sorted(set(all_litellm_params))
entries: Final = "".join(f' "{name}",\n' for name in names)
return (
f"{HEADER}\n"
f'pub(super) const INTERNAL_PREFIX: &str = "{INTERNAL_KWARG_PREFIX}";\n\n'
"#[rustfmt::skip]\n"
f"pub(super) const PYTHON_OWNED: &[&str] = &[\n{entries}];\n"
)
def main() -> int:
parser: Final = argparse.ArgumentParser()
parser.add_argument("--check", action="store_true")
check: Final = parser.parse_args().check is True
expected: Final = render()
if not check:
TARGET.write_text(expected)
return 0
if TARGET.read_text() == expected:
return 0
sys.stderr.write(f"{TARGET.relative_to(ROOT)} is stale; run `python -m scripts.generate_owned_kwargs`\n")
return 1
if __name__ == "__main__":
sys.exit(main())