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
fix(cli): write pi models.json atomically and hide lite pi from --help
ryan-crabbe-berrid3dc6f6b1232
diff --git a/litellm/proxy/client/cli/README.md b/litellm/proxy/client/cli/README.mdindex 66beecbd2e6..468b8d96123 100644--- a/litellm/proxy/client/cli/README.md+++ b/litellm/proxy/client/cli/README.md@@ -481,7 +481,7 @@ Each command resolves your LiteLLM key (logging in via SSO when none is stored aThe right variables are picked per agent. Claude Code gets `ANTHROPIC_BASE_URL` (the proxy root, so it appends `/v1/messages`) and `ANTHROPIC_AUTH_TOKEN`, with any stray `ANTHROPIC_API_KEY` cleared so the proxy token wins. Codex and OpenCode get `OPENAI_BASE_URL` (the proxy plus `/v1`) and `OPENAI_API_KEY`. Codex ignores `OPENAI_BASE_URL`, so it is additionally pointed at the proxy through a custom provider passed as `-c` config overrides (HTTP/SSE Responses transport, since the proxy does not speak the Responses WebSocket protocol).-pi ignores base-URL environment variables entirely, so `lite pi` wires it up differently: before handoff it fetches the models your key can use from the proxy's `/v1/models` (plus each model's context window and output cap from `/model_group/info`, when available) and syncs them into a `litellm` provider entry in pi's `~/.pi/agent/models.json` (honoring `PI_CODING_AGENT_DIR`), then starts pi on that provider's first model via an injected `--model litellm/<id>`. Only that one provider entry is rewritten; the rest of the file, including any other custom providers, is left alone. The entry references the key as `$LITELLM_PROXY_API_KEY`, which the wrapper exports for the session, so the token itself never lands on disk and plain `pi` outside the wrapper simply shows the litellm models as unavailable. Your own flags come after the injected pin, so `lite pi --model litellm/<other-id>` wins, and inside the TUI the `/model` picker lists every synced litellm model.+pi ignores base-URL environment variables entirely, so `lite pi` (kept out of the `lite --help` command listing for now, but fully functional) wires it up differently: before handoff it fetches the models your key can use from the proxy's `/v1/models` (plus each model's context window and output cap from `/model_group/info`, when available) and syncs them into a `litellm` provider entry in pi's `~/.pi/agent/models.json` (honoring `PI_CODING_AGENT_DIR`), then starts pi on that provider's first model via an injected `--model litellm/<id>`. Only that one provider entry is rewritten; the rest of the file, including any other custom providers, is left alone. The entry references the key as `$LITELLM_PROXY_API_KEY`, which the wrapper exports for the session, so the token itself never lands on disk and plain `pi` outside the wrapper simply shows the litellm models as unavailable. Your own flags come after the injected pin, so `lite pi --model litellm/<other-id>` wins, and inside the TUI the `/model` picker lists every synced litellm model.Options (these belong to the wrapper, so put them before the agent's own flags):diff --git a/litellm/proxy/client/cli/commands/agents.py b/litellm/proxy/client/cli/commands/agents.pyindex f55cf9893e7..ba410673ec9 100644--- a/litellm/proxy/client/cli/commands/agents.py+++ b/litellm/proxy/client/cli/commands/agents.py@@ -3,7 +3,7 @@ import shutilimport sysfrom collections.abc import Callable, Mapping, Sequencefrom types import MappingProxyType-from typing import Final+from typing import Final, TypeAliasimport clickimport requests@@ -43,6 +43,8 @@ _INSTALL_DOCS: Final[dict[str, str]] = {"pi": "https://pi.dev",}+_HIDDEN_AGENTS: Final = frozenset({"pi"})+CODEX_PROXY_PROVIDER: Final = "litellm"@@ -150,7 +152,9 @@ def prepare_pi(return ["--model", f"{PI_PROVIDER_NAME}/{ids[0]}"]-_PREPARERS: Final[dict[str, Callable[[str, str, Mapping[str, str]], Sequence[str]]]] = {+_Preparer: TypeAlias = Callable[[str, str, Mapping[str, str]], Sequence[str]]++_PREPARERS: Final[dict[str, _Preparer]] = {"pi": prepare_pi,}@@ -226,7 +230,7 @@ def run_agent(verify: Callable[[str, str], None] = verify_proxy_key,launcher: Callable[[str, Sequence[str], Mapping[str, str]], None] = _exec,reattach_terminal: Callable[[], None] | None = None,- preparers: Mapping[str, Callable[[str, str, Mapping[str, str]], Sequence[str]]] = MappingProxyType(_PREPARERS),+ preparers: Mapping[str, _Preparer] = MappingProxyType(_PREPARERS),) -> None:"""Validate, wire the environment, and hand off to the agent.@@ -311,6 +315,7 @@ def _make_agent_command(binary: str, display_name: str) -> click.Command:name=binary,context_settings={"ignore_unknown_options": True},short_help=f"Run {display_name} through your LiteLLM proxy",+ hidden=binary in _HIDDEN_AGENTS,)@click.option("--skip-verify", is_flag=True, default=False, help=_SKIP_VERIFY_HELP)@click.argument("args", nargs=-1, type=click.UNPROCESSED)diff --git a/litellm/proxy/client/cli/commands/pi.py b/litellm/proxy/client/cli/commands/pi.pyindex bd933874a10..668b803a33d 100644--- a/litellm/proxy/client/cli/commands/pi.py+++ b/litellm/proxy/client/cli/commands/pi.py@@ -156,9 +156,11 @@ def sync_models_json(**current,"providers": {**existing_providers, PI_PROVIDER_NAME: provider_block(base_url, model_ids, limits)},}+ staging: Final = path.with_name(path.name + ".tmp")try:path.parent.mkdir(parents=True, exist_ok=True)- path.write_text(json.dumps(updated, indent=2) + "\n")+ staging.write_text(json.dumps(updated, indent=2) + "\n")+ staging.replace(path)except OSError as e:return PiSyncError(f"Could not write {path}: {e}")return Nonediff --git a/tests/test_litellm/proxy/client/cli/test_agents.py b/tests/test_litellm/proxy/client/cli/test_agents.pyindex fad0d3842fa..99b2ff234e2 100644--- a/tests/test_litellm/proxy/client/cli/test_agents.py+++ b/tests/test_litellm/proxy/client/cli/test_agents.py@@ -466,6 +466,10 @@ class TestAgentCommands:def test_one_command_per_known_agent(self):assert {c.name for c in agent_commands()} == {"claude", "codex", "opencode", "pi"}+ def test_pi_is_hidden_from_help_but_still_registered(self):+ hidden_by_name = {c.name: c.hidden for c in agent_commands()}+ assert hidden_by_name == {"claude": False, "codex": False, "opencode": False, "pi": True}+def test_claude_launches_with_stored_key_and_forwards_args(self):captured = {}diff --git a/tests/test_litellm/proxy/client/cli/test_pi.py b/tests/test_litellm/proxy/client/cli/test_pi.pyindex 99ed2734b76..ee3222a77e3 100644--- a/tests/test_litellm/proxy/client/cli/test_pi.py+++ b/tests/test_litellm/proxy/client/cli/test_pi.py@@ -174,6 +174,11 @@ class TestSyncModelsJson:assert written["providers"]["litellm"]["baseUrl"] == "http://localhost:4000/v1"assert written["providers"]["litellm"]["models"] == [{"id": "m-1"}]+ def test_write_leaves_no_staging_file_behind(self, tmp_path):+ path = tmp_path / "models.json"+ assert sync_models_json(path, "http://localhost:4000", ("m-1",)) is None+ assert [p.name for p in tmp_path.iterdir()] == ["models.json"]+def test_invalid_json_is_a_value_and_file_untouched(self, tmp_path):path = tmp_path / "models.json"path.write_text("{not json")