Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

fix(data): name the real endpoint on an Anthropic judge/provider failure, not --base-url (#1370)

Siddhardha Nanda77f4ee5e1480
diff --git a/changelog.d/0.75.1/1370.fixed.md b/changelog.d/0.75.1/1370.fixed.md
new file mode 100644
index 00000000..cda87818
--- /dev/null
+++ b/changelog.d/0.75.1/1370.fixed.md
@@ -0,0 +1,13 @@
+- **A failed Anthropic judge/provider call blamed `--judge-base-url` /
+ `--base-url` for the failure, though Anthropic ignores that flag entirely
+ (#1340 by @SID-6921 in #1370).** `soup data forge --judge-provider
+ anthropic --judge-base-url <x>` and `soup data recipe --provider anthropic
+ --base-url <x>` both named `<x>` in the terminal error and, for the recipe
+ path, in `.checkpoint.json`'s `failed_reason` -- but the API key comes from
+ `ANTHROPIC_API_KEY` only, and every call actually goes to
+ `https://api.anthropic.com/v1/messages` regardless of what `base_url` was,
+ so the message pointed at a host that was never contacted. Both callers
+ route through one shared label helper, which now returns the real
+ Anthropic origin whenever the provider is Anthropic, ignoring `base_url`;
+ `ollama` / `vllm` labels are unaffected since those providers do forward
+ `base_url` to the request.
diff --git a/src/soup_cli/utils/data_forge.py b/src/soup_cli/utils/data_forge.py
index 8d788bf1..5a469d8a 100644
--- a/src/soup_cli/utils/data_forge.py
+++ b/src/soup_cli/utils/data_forge.py
@@ -572,6 +572,11 @@ JUDGE_PROVIDERS: frozenset[str] = frozenset({"ollama", "anthropic", "vllm"})
_OLLAMA_DEFAULT_URL = "http://localhost:11434"
_VLLM_DEFAULT_URL = "http://localhost:8000"
+# Anthropic ignores --judge-base-url / --base-url (API key from env var
+# only); this is the one and only endpoint ever called, so failure messages
+# must name it rather than whatever base_url the caller happened to pass.
+_ANTHROPIC_MESSAGES_URL = "https://api.anthropic.com/v1/messages"
+
class ProviderCallError(RuntimeError):
"""A live provider request failed before producing a valid completion."""
@@ -711,7 +716,7 @@ def make_judge_provider_fn(
return _failed("anthropic provider prompt must be a string")
try:
resp = httpx.post(
- "https://api.anthropic.com/v1/messages",
+ _ANTHROPIC_MESSAGES_URL,
headers={
"x-api-key": api_key,
"anthropic-version": "2023-06-01",
diff --git a/src/soup_cli/utils/recipe_run.py b/src/soup_cli/utils/recipe_run.py
index 80afc7de..b7aedf6f 100644
--- a/src/soup_cli/utils/recipe_run.py
+++ b/src/soup_cli/utils/recipe_run.py
@@ -56,7 +56,17 @@ class _ProviderNodeResult:
def _provider_endpoint_label(provider: Optional[str], base_url: Optional[str]) -> str:
- """Return a credential-free origin label for provider failure messages."""
+ """Return a credential-free origin label for provider failure messages.
+
+ Anthropic ignores ``base_url`` -- ``make_judge_provider_fn`` always posts
+ to ``_ANTHROPIC_MESSAGES_URL`` regardless of what the caller passed, so
+ labelling by ``base_url`` for that provider named a host that was never
+ contacted (#1340).
+ """
+ if provider is not None and provider.strip().lower() == "anthropic":
+ from soup_cli.utils.data_forge import _ANTHROPIC_MESSAGES_URL
+
+ return urlsplit(_ANTHROPIC_MESSAGES_URL)._replace(path="", query="", fragment="").geturl()
if base_url is None:
return f"{provider or 'provider'} default endpoint"
try:
diff --git a/tests/test_issue1221_forge_judge_failures.py b/tests/test_issue1221_forge_judge_failures.py
index 2c4ec152..bd5aae8b 100644
--- a/tests/test_issue1221_forge_judge_failures.py
+++ b/tests/test_issue1221_forge_judge_failures.py
@@ -299,6 +299,35 @@ def test_anthropic_failures_exit_nonzero(
assert first_error in output
+def test_anthropic_failure_names_the_real_endpoint_not_the_given_base_url(
+ tmp_path, monkeypatch
+) -> None:
+ """#1340: --judge-base-url is accepted for anthropic and --help says it
+ is ignored, but the failure message repeated it anyway -- every call
+ actually goes to https://api.anthropic.com, not the given base_url."""
+ import httpx
+
+ posted: list[str] = []
+
+ def _record(url, *_args, **_kwargs):
+ posted.append(url)
+ return _AnthropicResponse(500)
+
+ monkeypatch.setenv("ANTHROPIC_API_KEY", "synthetic-test-value")
+ monkeypatch.setattr(httpx, "post", _record)
+ given_base_url = "http://127.0.0.1:9"
+ result = _run_forge(
+ tmp_path, monkeypatch,
+ "--judge-provider", "anthropic", "--judge-base-url", given_base_url,
+ )
+ output = _terminal_text(result)
+
+ assert result.exit_code == 1, output
+ assert set(posted) == {"https://api.anthropic.com/v1/messages"}
+ assert "--judge-provider anthropic (https://api.anthropic.com)" in output
+ assert given_base_url not in output
+
+
def test_anthropic_partial_outage_keeps_successful_rows(tmp_path, monkeypatch) -> None:
import httpx
diff --git a/tests/test_issue817_recipe_provider.py b/tests/test_issue817_recipe_provider.py
index 01b2ce39..f08c4be6 100644
--- a/tests/test_issue817_recipe_provider.py
+++ b/tests/test_issue817_recipe_provider.py
@@ -551,3 +551,94 @@ def test_provider_failure_endpoint_label_omits_credentials_path_and_query() -> N
)
== "http://localhost:11434"
)
+
+
[email protected]("provider_name", ["anthropic", "Anthropic", "ANTHROPIC"])
+def test_provider_failure_endpoint_label_ignores_anthropic_base_url(
+ provider_name: str,
+) -> None:
+ """#1340: Anthropic ignores --judge-base-url / --base-url entirely (API key
+ from env var only, make_judge_provider_fn always posts to the same URL),
+ so a failure message built from the given base_url named a host that was
+ never contacted. The label must name the endpoint actually called instead,
+ whatever case or base_url the caller passed."""
+ from soup_cli.utils.recipe_run import _provider_endpoint_label
+
+ assert (
+ _provider_endpoint_label(provider_name, "http://127.0.0.1:9")
+ == "https://api.anthropic.com"
+ )
+
+
+def test_provider_failure_endpoint_label_anthropic_without_base_url_names_origin() -> None:
+ """Before #1340 this label read 'anthropic default endpoint'; it now names
+ the origin every Anthropic call goes to, with or without a base URL."""
+ from soup_cli.utils.recipe_run import _provider_endpoint_label
+
+ assert _provider_endpoint_label("anthropic", None) == "https://api.anthropic.com"
+
+
+ ("provider_name", "base_url"),
+ [("ollama", "http://127.0.0.1:9"), ("vllm", "http://127.0.0.1:9")],
+)
+def test_provider_failure_endpoint_label_non_anthropic_still_uses_base_url(
+ provider_name: str, base_url: str
+) -> None:
+ """Control: only Anthropic ignores base_url -- ollama/vllm callers do
+ pass it through to httpx.post, so their failure messages must keep
+ naming the endpoint the caller actually gave."""
+ from soup_cli.utils.recipe_run import _provider_endpoint_label
+
+ assert _provider_endpoint_label(provider_name, base_url) == base_url
+
+
+def test_recipe_cli_anthropic_failure_names_the_real_endpoint_not_base_url(
+ tmp_path: Path,
+ monkeypatch,
+) -> None:
+ """#1340: soup data recipe --provider anthropic --base-url <x> failed with
+ a message and a .checkpoint.json['failed_reason'] naming <x>, even though
+ every call actually went to https://api.anthropic.com."""
+ import httpx
+
+ from soup_cli.cli import app
+
+ monkeypatch.chdir(tmp_path)
+ monkeypatch.setenv("ANTHROPIC_API_KEY", "synthetic-test-value")
+
+ class _FailingResponse:
+ status_code = 500
+
+ def json(self) -> dict:
+ return {"error": "stub"}
+
+ posted: list[str] = []
+
+ def _record(url, *_args, **_kwargs):
+ posted.append(url)
+ return _FailingResponse()
+
+ monkeypatch.setattr(httpx, "post", _record)
+ recipe_path = _write_single_provider_recipe(tmp_path, kind="llm_text")
+ given_base_url = "http://127.0.0.1:9"
+
+ result = CliRunner().invoke(
+ app,
+ [
+ "data", "recipe", str(recipe_path),
+ "--execute", "--output", "out",
+ "--provider", "anthropic",
+ "--base-url", given_base_url,
+ ],
+ )
+
+ output = _terminal_text(result)
+ assert result.exit_code == 1, (output, repr(result.exception))
+ assert set(posted) == {"https://api.anthropic.com/v1/messages"}
+ assert "all 2 provider calls failed for https://api.anthropic.com" in output
+ assert given_base_url not in output
+ checkpoint = json.loads((tmp_path / "out" / ".checkpoint.json").read_text())
+ assert checkpoint["status"] == "failed"
+ assert "https://api.anthropic.com" in checkpoint["failed_reason"]
+ assert given_base_url not in checkpoint["failed_reason"]