Skip to content

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]

fix(cli): decode codex debug models output as UTF-8

mateo-berric15f3e922891
diff --git a/litellm/proxy/client/cli/commands/agents.py b/litellm/proxy/client/cli/commands/agents.py
index decb520c3a0..15b111ff016 100644
--- a/litellm/proxy/client/cli/commands/agents.py
+++ b/litellm/proxy/client/cli/commands/agents.py
@@ -546,7 +546,7 @@ def _codex_debug_models(
env=dict(env),
stdin=subprocess.DEVNULL,
capture_output=True,
- text=True,
+ encoding="utf-8",
timeout=_CODEX_PREFLIGHT_TIMEOUT_SECONDS,
)
except (OSError, subprocess.TimeoutExpired) as e:
diff --git a/tests/test_litellm/proxy/client/cli/test_agents.py b/tests/test_litellm/proxy/client/cli/test_agents.py
index c437f4c12c5..f6f1c2fec3b 100644
--- a/tests/test_litellm/proxy/client/cli/test_agents.py
+++ b/tests/test_litellm/proxy/client/cli/test_agents.py
@@ -540,6 +540,22 @@ class TestCodexModelSync:
assert entries["gpt-5.4"]["upgrade"] == _STOCK_MODELS["gpt-5.4"]["upgrade"]
assert [entries["gpt-5.4"]["priority"], entries["gpt-5.6-terra"]["priority"]] == [0, 1]
+ def test_stock_catalog_is_decoded_as_utf8_regardless_of_locale(self, tmp_path):
+ description = "Modelo equilibrado para el trabajo diario, con acentos y ñ."
+ catalog = {"models": [{**_STOCK_MODELS["gpt-5.5"], "description": description}]}
+ stock = json.dumps(catalog, ensure_ascii=False).encode("utf-8")
+
+ def locale_bound_run(args, **kwargs):
+ if "model_catalog_json=" in str(args):
+ return subprocess.CompletedProcess(args, 0, "", "")
+ return subprocess.CompletedProcess(args, 0, stock.decode(kwargs.get("encoding") or "ascii"), "")
+
+ _, result = self._sync(self._listing(self._row("gpt-5.5")), tmp_path, run=locale_bound_run)
+
+ assert isinstance(result, ModelSyncArgs)
+ written = json.loads((tmp_path / "litellm-models.json").read_text(encoding="utf-8"))["models"]
+ assert [m["description"] for m in written] == [description]
+
def test_unparseable_stock_catalog_is_reported(self, tmp_path):
_, result = self._sync(self._listing(self._row("m")), tmp_path, run=_FakeRun(stock="not json"))
assert isinstance(result, ModelSyncSkipped)
@@ -708,7 +724,7 @@ class TestCodexModelSync:
assert options["env"] == {"CODEX_HOME": str(tmp_path)}
assert options["stdin"] is subprocess.DEVNULL
assert options["capture_output"] is True
- assert options["text"] is True
+ assert options["encoding"] == "utf-8"
assert options["timeout"] == 10
def test_codex_rejecting_the_catalog_skips_the_sync_and_keeps_the_file(self, tmp_path):