The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_claude_code_e2e_gpt_big3
mateo-berri35b042ffa54c
diff --cc tests/e2e/claude_code/_builder_unit_tests/test_v0_layout.pyindex 2ea60dea586,04e0facff5e..874c892c74a--- a/tests/e2e/claude_code/_builder_unit_tests/test_v0_layout.py+++ b/tests/e2e/claude_code/_builder_unit_tests/test_v0_layout.py@@@ -200,46 -158,6 +200,46 @@@ def test_per_provider_test_file_imports), f"{feature_id}/test_{provider}.py does not reference {tier}"[email protected]("feature_id", GPT_FEATURE_IDS)[email protected]("provider", GPT_PROVIDERS)+def test_gpt_cell_test_file_exists(feature_id, provider):+ """Every (GPT feature, GPT provider) cell must be backed by a test+ file; a missing file silently becomes a `not_tested` cell in the+ published matrix rather than a CI failure surfacing the drift."""- test_file = REPO_ROOT / feature_id / f"test_{provider}.py"++ test_file = SUITE_ROOT / feature_id / f"test_{provider}.py"+ assert test_file.is_file(), f"missing per-provider test file: {test_file}"++[email protected]("feature_id", GPT_FEATURE_IDS)[email protected]("provider", GPT_LIVE_PROVIDERS)+def test_gpt_cell_references_three_gpt_tiers(feature_id, provider):+ """Every live GPT cell must exercise Sol, Terra, and Luna — the+ same all-tiers-or-red rule the v0 columns apply to the three+ Claude tiers."""- text = (REPO_ROOT / feature_id / f"test_{provider}.py").read_text()++ text = (SUITE_ROOT / feature_id / f"test_{provider}.py").read_text()+ for tier in GPT_TIER_SUBSTRINGS:+ assert (+ tier in text+ ), f"{feature_id}/test_{provider}.py does not reference {tier}"++[email protected]("feature_id", GPT_FEATURE_IDS)+def test_vertex_ai_gpt_cell_is_a_static_not_applicable_stub(feature_id):+ """GCP does not offer the closed-weight GPT-5.6 family, so the+ `vertex_ai_gpt` cells must report `not_applicable` and must not+ drive the claude CLI. If Google adds the models, flip the stubs to+ live cells and update this pin alongside GPT_LIVE_PROVIDERS."""- text = (REPO_ROOT / feature_id / "test_vertex_ai_gpt.py").read_text()++ text = (SUITE_ROOT / feature_id / "test_vertex_ai_gpt.py").read_text()+ assert '"status": "not_applicable"' in text, (+ f"{feature_id}/test_vertex_ai_gpt.py must report not_applicable while "+ "GCP Vertex AI does not offer the GPT-5.6 family."+ )+ assert "run_claude" not in text, (+ f"{feature_id}/test_vertex_ai_gpt.py must not drive the claude CLI; "+ "there is no GPT-5.6 route on Vertex AI to exercise."+ )++@pytest.mark.parametrize("feature_id", EXPECTED_FEATURE_IDS)def test_azure_test_file_drives_the_proxy(feature_id):"""Azure (Microsoft Foundry) hosts Anthropic Claude as of 2025-11-18,diff --cc tests/e2e/claude_code/_pr_gate_unit_tests/test_bash_tool_restrictions.pyindex a0402e15752,ebd6d436d71..c0d0c929e1a--- a/tests/e2e/claude_code/_pr_gate_unit_tests/test_bash_tool_restrictions.py+++ b/tests/e2e/claude_code/_pr_gate_unit_tests/test_bash_tool_restrictions.py@@@ -95,10 -79,8 +94,10 @@@ def test_bash_allow_rule_is_pinned_to_e"""The cell must pass `Bash(echo pong)` as the allow rule, not theunrestricted `Bash` value that was originally flagged."""text = cell.read_text()+ if _is_exempt_stub(text):+ returnassert '"Bash(echo pong)"' in text, (- f"{cell.relative_to(REPO_ROOT)} must restrict `--allowed-tools` to "+ f"{cell.relative_to(CLAUDE_CODE_DIR)} must restrict `--allowed-tools` to "f'`Bash(echo pong)` (exact-match pattern). Unrestricted `"Bash"` 'f"grants arbitrary host command execution to model-controlled "f"tool_use blocks, which can read `docker inspect compat-proxy` "@@@ -155,10 -137,8 +154,10 @@@ def test_bash_cell_uses_dontask_permissopposed to defaulting to "ask", which in headless mode wouldsucceed without ever surfacing the security issue)."""text = cell.read_text()+ if _is_exempt_stub(text):+ returnassert '"--permission-mode"' in text and '"dontAsk"' in text, (- f"{cell.relative_to(REPO_ROOT)} must pass `--permission-mode dontAsk` "+ f"{cell.relative_to(CLAUDE_CODE_DIR)} must pass `--permission-mode dontAsk` "f"alongside the `Bash(echo pong)` allow rule. Without dontAsk, "f"commands outside the allow rule fall back to the default ask-"f"mode behavior, which in `--print` (headless) mode is non-"@@@ -166,26 -146,17 +165,42 @@@)+def test_is_exempt_stub_accepts_not_applicable_stub():+ """A static not_applicable stub (no CLI driver, no tool grants) is+ outside the Bash pin's threat model and must be exempt — this is+ the shape of the `vertex_ai_gpt` cells."""+ text = 'compat_result.set({"status": "not_applicable", "reason": REASON})'+ assert _is_exempt_stub(text)+++def test_is_exempt_stub_rejects_cli_driving_cell():+ """Any cell that drives the CLI stays subject to the pins, whether+ or not it currently grants tools."""+ text = (+ "run_claude_models_parallel(models=MODELS, "+ 'extra_args=["--allowed-tools", "Bash(echo pong)"])'+ )+ assert not _is_exempt_stub(text)+++def test_is_exempt_stub_rejects_allowed_tools_without_visible_driver():+ """A cell that passes `--allowed-tools` while hiding its driver+ behind an indirection must not slip out of the pinned shape."""+ text = 'helper(extra_args=["--allowed-tools", "Bash"])'+ assert not _is_exempt_stub(text)+++++ def test_claude_code_dir_anchor_is_layout_independent() -> None:+ """CLAUDE_CODE_DIR must resolve to the `claude_code/` directory that+ contains this test file, regardless of how deep the repository is+ mounted. The previous anchor `Path(__file__).resolve().parents[4]`+ baked in the host layout (repo root sits four levels up) and broke+ when the suite runs inside the stage container, where tests/e2e/ is+ mounted at /app/e2e/ so `parents[4]` resolves to filesystem root and+ the BASH_FEATURE_DIRS assertion looks for `/tests/e2e/claude_code/+ tool_use`. Anchoring at `parents[1]` (the sibling of this file's+ parent) is the same directory in both layouts.+ """+ assert CLAUDE_CODE_DIR.name == "claude_code"+ assert CLAUDE_CODE_DIR.is_dir()+ assert (CLAUDE_CODE_DIR / "_pr_gate_unit_tests" / Path(__file__).name).is_file()diff --cc tests/e2e/claude_code/_pr_gate_unit_tests/test_compat_models.pyindex 00000000000,6614e75e2f4..ccfbe4c9083mode 000000,100644..100644--- a/tests/e2e/claude_code/_pr_gate_unit_tests/test_compat_models.py+++ b/tests/e2e/claude_code/_pr_gate_unit_tests/test_compat_models.py@@@ -1,0 -1,166 +1,167 @@@+ """Regression tests for the compat-model registration loader.++ The compat cells hardcode virtual model names like ``claude-sonnet-4-5``+ and expect them to be registered on the proxy before the cell runs. The+ session fixture in ``conftest.py`` reads ``test_config.yaml`` and POSTs+ those deployments via ``/model/new``. These tests pin the invariants+ that make that safe:++ - The yaml declares an entry for every virtual name a cell references -+ otherwise a cell probes a name the fixture never registered, and the+ cell hits an ``Invalid model name`` 400 that is much harder to trace.++ - The ``vertex_ai_*`` yaml keys get normalized to the ``vertex_*``+ pydantic-body names before ``LiteLLMParamsBody(**)`` sees them, so+ the vertex project/location aren't silently dropped by pydantic's+ ``extra="ignore"`` default.+ """++ from __future__ import annotations++ import re+ from pathlib import Path++ import pytest++ from claude_code._compat_models import (+ all_expected_model_names,+ load_all_deployments,+ )+++ CLAUDE_CODE_DIR = Path(__file__).resolve().parents[1]+++ def _cell_declared_model_names() -> frozenset[str]:- """Every ``"claude-*"`` model name a compat cell hardcodes in a- ``*_MODELS`` list. Uses a simple regex rather than importing every- cell because the cells depend on the harness which depends on env- the unit-test run does not have."""- pattern = re.compile(r'"(claude-[a-zA-Z0-9._-]+)"')++ """Every ``"claude-*"`` or ``"gpt-*"`` model name a compat cell++ hardcodes in a ``*_MODELS`` list. Uses a simple regex rather than++ importing every cell because the cells depend on the harness which++ depends on env the unit-test run does not have."""++ pattern = re.compile(r'"((?:claude|gpt)-[a-zA-Z0-9._-]+)"')+ found: set[str] = set()+ for path in CLAUDE_CODE_DIR.glob("*/test_*.py"):+ if path.parent.name.startswith("_"):+ continue+ for match in pattern.finditer(path.read_text()):+ name = match.group(1)+ # Skip upstream model references (they carry a version+ # suffix or the ``anthropic/`` provider prefix - we only+ # want proxy-side virtual names here).+ if "/" in name or "@" in name:+ continue+ found.add(name)+ return frozenset(found)+++ def test_yaml_covers_every_cell_declared_model_name() -> None:+ """Every ``"claude-..."`` string a cell probes must have a+ corresponding ``model_list`` entry in ``test_config.yaml``. A new+ cell that adds a probe for a name the yaml doesn't know fails this+ test - the alternative is a 400 at runtime that is much harder to+ diagnose."""+ yaml_names = all_expected_model_names()+ cell_names = _cell_declared_model_names()+ missing = cell_names - yaml_names+ assert not missing, (+ f"compat cells reference model names not declared in "+ f"test_config.yaml: {sorted(missing)}. Add a matching "+ f"model_list entry so the session fixture can register them."+ )+++ def test_yaml_has_no_unused_declarations() -> None:+ """Every declaration in ``test_config.yaml`` is referenced by at+ least one cell. A yaml entry no test exercises is dead+ configuration and drift-prone; delete it or add the cell."""+ yaml_names = all_expected_model_names()+ cell_names = _cell_declared_model_names()+ unused = yaml_names - cell_names+ assert not unused, (+ f"test_config.yaml declares model names no cell references: "+ f"{sorted(unused)}. Delete them or add the cell."+ )++-def test_load_returns_fifteen_deployments() -> None:- """The compat matrix is 3 tiers x 5 provider surfaces = 15. Pin the- count so a future edit to the yaml can't silently drop a tier."""- assert len(load_all_deployments()) == 15++def test_load_returns_twenty_four_deployments() -> None:++ """The compat matrix is 3 Claude tiers x 5 provider surfaces = 15,++ plus 3 GPT-5.6 tiers x 3 live provider columns = 9. Pin the count++ so a future edit to the yaml can't silently drop a tier."""++ assert len(load_all_deployments()) == 24+++ def test_deployments_are_hashable_and_frozen() -> None:+ """``CompatDeployment`` is frozen so tests cannot accidentally+ mutate the shared list mid-session."""+ d = load_all_deployments()[0]+ with pytest.raises((AttributeError, TypeError)):+ d.model_name = "mutated" # type: ignore[misc]+++ def test_vertex_yaml_keys_populate_pydantic_body() -> None:+ """The yaml spells vertex fields ``vertex_ai_project`` /+ ``vertex_ai_location`` but ``LiteLLMParamsBody`` names them+ ``vertex_project`` / ``vertex_location``. Without the alias+ normalization the pydantic body silently drops the yaml keys, and+ the deployment gets registered with no vertex project - a real+ incident the drift regressed twice historically."""+ all_deployments = load_all_deployments()+ vertex = [+ d for d in all_deployments if d.model_name.endswith("-vertex")+ ]+ assert vertex, "no vertex deployments found in yaml"+ for d in vertex:+ assert d.litellm_params.vertex_project, (+ f"{d.model_name} lost its vertex_project after normalization"+ )+ assert d.litellm_params.vertex_location, (+ f"{d.model_name} lost its vertex_location after normalization"+ )+++ def test_vertex_deployments_keep_use_in_pass_through() -> None:+ """Vertex passthrough cells need the deployment registered with+ ``use_in_pass_through: true`` so the proxy wires project/location+ credentials into the /vertex_ai passthrough router. ``LiteLLMParamsBody``+ defaults to ``extra="ignore"``, so a missing field on the body silently+ strips the yaml flag and every vertex passthrough cell fails at runtime+ with "No credentials found on proxy for project_name=..."."""+ vertex = [+ d+ for d in load_all_deployments()+ if d.model_name.endswith("-vertex")+ ]+ assert vertex, "no vertex deployments found in yaml"+ for d in vertex:+ assert d.litellm_params.use_in_pass_through is True, (+ f"{d.model_name} lost use_in_pass_through after load; "+ f"serialized body would be "+ f"{d.litellm_params.model_dump(exclude_none=True)}"+ )+++ def test_yaml_litellm_params_are_all_known_body_fields() -> None:+ """Every key under ``litellm_params`` in ``test_config.yaml`` must map+ to a ``LiteLLMParamsBody`` field (after the vertex alias rewrite).+ Without this pin, a new yaml flag can land in the fixture config and+ be silently dropped by pydantic before ``/model/new`` ever sees it."""+ import yaml+ from models import LiteLLMParamsBody++ from claude_code._compat_models import (+ CONFIG_PATH,+ _YAML_TO_PYDANTIC_ALIASES,+ )++ known = frozenset(LiteLLMParamsBody.model_fields)+ doc = yaml.safe_load(CONFIG_PATH.read_text())+ model_list = doc.get("model_list") or []+ unknown = tuple(+ (entry["model_name"], key)+ for entry in model_list+ for key in entry["litellm_params"]+ if _YAML_TO_PYDANTIC_ALIASES.get(key, key) not in known+ )+ assert not unknown, (+ f"test_config.yaml litellm_params keys not on LiteLLMParamsBody "+ f"(will be silently dropped at register time): {unknown}"+ )diff --cc tests/e2e/claude_code/test_config.yamlindex 9de26e26b9a,ba57ca4ccb7..cde46364011--- a/tests/e2e/claude_code/test_config.yaml+++ b/tests/e2e/claude_code/test_config.yaml@@@ -97,57 -117,11 +125,59 @@@ model_list- model_name: claude-opus-4-7-azurelitellm_params:model: azure_ai/claude-opus-4-7- api_base: os.environ/AZURE_FOUNDRY_API_BASE- api_key: os.environ/AZURE_FOUNDRY_API_KEY+ api_base: os.environ/AZURE_AI_API_BASE+ api_key: os.environ/AZURE_AI_API_KEY+ extra_headers:+ anthropic-beta: "context-1m-2025-08-07"+ # ---- OpenAI (GPT-5.6) ----+ - model_name: gpt-5-6-sol-openai+ litellm_params:+ model: openai/gpt-5.6-sol+ api_key: os.environ/OPENAI_API_KEY+ - model_name: gpt-5-6-terra-openai+ litellm_params:+ model: openai/gpt-5.6-terra+ api_key: os.environ/OPENAI_API_KEY+ - model_name: gpt-5-6-luna-openai+ litellm_params:+ model: openai/gpt-5.6-luna+ api_key: os.environ/OPENAI_API_KEY++ # ---- Azure OpenAI (GPT-5.6) ----+ - model_name: gpt-5-6-sol-azure-openai+ litellm_params:+ model: azure/gpt-5.6-sol+ api_base: os.environ/AZURE_OPENAI_API_BASE+ api_key: os.environ/AZURE_OPENAI_API_KEY+ - model_name: gpt-5-6-terra-azure-openai+ litellm_params:+ model: azure/gpt-5.6-terra+ api_base: os.environ/AZURE_OPENAI_API_BASE+ api_key: os.environ/AZURE_OPENAI_API_KEY+ - model_name: gpt-5-6-luna-azure-openai+ litellm_params:+ model: azure/gpt-5.6-luna+ api_base: os.environ/AZURE_OPENAI_API_BASE+ api_key: os.environ/AZURE_OPENAI_API_KEY++ # ---- Bedrock Mantle (GPT-5.6, Responses API) ----+ # Sol is only served from us-east-1 / us-east-2 as of 2026-07;+ # Terra and Luna additionally have us-west-2. One region keeps the+ # column comparable across tiers.+ - model_name: gpt-5-6-sol-bedrock-mantle+ litellm_params:+ model: bedrock_mantle/openai.gpt-5.6-sol+ aws_region_name: us-east-1+ - model_name: gpt-5-6-terra-bedrock-mantle+ litellm_params:+ model: bedrock_mantle/openai.gpt-5.6-terra+ aws_region_name: us-east-1+ - model_name: gpt-5-6-luna-bedrock-mantle+ litellm_params:+ model: bedrock_mantle/openai.gpt-5.6-luna+ aws_region_name: us-east-1+general_settings:# Claude Code sends provider-specific headers (e.g. anthropic-beta) we# want to forward verbatim to the upstream so the wire-shape under