Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(model-hub): prove mainstream OpenAI-compatible endpoints (#1732)

Maxc4c5a18ff80e
diff --git a/tests/scenarios/model_hub/test_model_hub_configured_route_scenarios.py b/tests/scenarios/model_hub/test_model_hub_configured_route_scenarios.py
index 4aa1affca..c6eb74ffc 100644
--- a/tests/scenarios/model_hub/test_model_hub_configured_route_scenarios.py
+++ b/tests/scenarios/model_hub/test_model_hub_configured_route_scenarios.py
@@ -520,6 +520,39 @@ def test_mh_protocol_003_manual_selection_requires_matching_response_proof(
assert mismatch_store.load().sources == []
assert mismatch_adapter.revoked == mismatch_adapter.provisioned_transient
+ ambiguous_store = MemoryModelHubStore(config_with_sources([]))
+ ambiguous_adapter = ModelHubScenarioAdapter(
+ observation=SourceObservation(
+ outcome=ObservationOutcome.AMBIGUOUS,
+ reachable=True,
+ authenticated=True,
+ protocol=None,
+ discovery=ObservationDiscovery.NOT_ATTEMPTED,
+ model_ids=(),
+ )
+ )
+ ambiguous_service = service_for(
+ tmp_path / "manual-ambiguous",
+ ambiguous_store,
+ ambiguous_adapter,
+ )
+ with pytest.raises(ModelHubError) as ambiguous:
+ asyncio.run(
+ ambiguous_service.create_source(
+ {
+ "kind": "api_key",
+ "vendor": "custom",
+ "display_name": "still-unproven",
+ "base_url": "https://relay.example/v1",
+ "key": "sk-scenario-unproven-manual",
+ "protocol": "openai_responses",
+ }
+ )
+ )
+ assert ambiguous.value.code == "discovery_failed"
+ assert ambiguous_store.load().sources == []
+ assert ambiguous_adapter.revoked == ambiguous_adapter.provisioned_transient
+
def test_mh_ac29_001_persisted_source_payload_round_trips_through_the_canonical_validator(
monkeypatch: pytest.MonkeyPatch,
diff --git a/tests/test_model_hub_l3.py b/tests/test_model_hub_l3.py
index dd6f261d2..d393e3b4c 100644
--- a/tests/test_model_hub_l3.py
+++ b/tests/test_model_hub_l3.py
@@ -97,6 +97,7 @@ from vibe.model_hub_runtime.adapter import (
_probe_protocol_response,
_PROTOCOL_OBSERVATION_TAXONOMY,
_ProtocolEvidence,
+ _ProtocolObservationShape,
_ProtocolProof,
)
from vibe.model_hub_runtime.client import EngineClientError, probe_models
@@ -4510,10 +4511,25 @@ def test_source_observation_reduces_the_order_at_the_first_authenticated_proof(
protocol=_ProtocolProof.PROVEN,
authentication=_AuthenticationEvidence.UNKNOWN,
)
+ generic_request_accepted = _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.ACCEPTED,
+ shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
+ )
unproven_unknown = _ProtocolEvidence(
protocol=_ProtocolProof.UNPROVEN,
authentication=_AuthenticationEvidence.UNKNOWN,
)
+ excluded_404 = _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.UNKNOWN,
+ shape=_ProtocolObservationShape.HTTP_404,
+ )
+ non_json = _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.UNKNOWN,
+ shape=_ProtocolObservationShape.NON_JSON,
+ )
hinted_order = tuple(reversed(SOURCE_PROTOCOLS))
@@ -4572,6 +4588,469 @@ def test_source_observation_reduces_the_order_at_the_first_authenticated_proof(
assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(hinted_order)
inventory_probe.assert_not_awaited()
+ pairwise_order = ("openai_chat", "openai_responses")
+
+ async def openai_pairwise_elimination(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] == "openai_chat":
+ return generic_request_accepted
+ if kwargs["protocol"] == "openai_responses":
+ return excluded_404
+ raise AssertionError(kwargs["protocol"])
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=openai_pairwise_elimination),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("deepseek-chat",)),
+ ) as inventory_probe,
+ ):
+ observed = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ pairwise_order,
+ )
+ )
+
+ assert observed.outcome.value == "observed"
+ assert observed.protocol == "openai_chat"
+ assert observed.model_ids == ("deepseek-chat",)
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(pairwise_order)
+ assert inventory_probe.await_args.kwargs["protocol"] == "openai_chat"
+
+ openai_family = {"openai_responses", "openai_chat"}
+
+ async def indistinguishable_openai_family(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] in openai_family:
+ return generic_request_accepted
+ return unproven_unknown
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=indistinguishable_openai_family),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("should-not-discover",)),
+ ) as inventory_probe,
+ ):
+ ambiguous = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
+ )
+
+ assert ambiguous.outcome.value == "ambiguous"
+ assert ambiguous.protocol is None
+ assert ambiguous.authenticated is True
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(SOURCE_PROTOCOLS)
+ inventory_probe.assert_not_awaited()
+
+ async def structured_unknown_sibling(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] == "openai_chat":
+ return generic_request_accepted
+ if kwargs["protocol"] == "openai_responses":
+ return unproven_unknown
+ return unproven_unknown
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=structured_unknown_sibling),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("should-not-discover",)),
+ ) as inventory_probe,
+ ):
+ ambiguous = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
+ )
+
+ assert ambiguous.outcome.value == "ambiguous"
+ assert ambiguous.protocol is None
+ assert ambiguous.authenticated is True
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(SOURCE_PROTOCOLS)
+ inventory_probe.assert_not_awaited()
+
+ async def anthropic_server_error_blocks_openai_pairwise(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] == "anthropic":
+ return proven_unknown
+ if kwargs["protocol"] == "openai_responses":
+ return generic_request_accepted
+ if kwargs["protocol"] == "openai_chat":
+ return excluded_404
+ raise AssertionError(kwargs["protocol"])
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=anthropic_server_error_blocks_openai_pairwise),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("should-not-discover",)),
+ ) as inventory_probe,
+ ):
+ ambiguous = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
+ )
+
+ assert ambiguous.outcome.value == "ambiguous"
+ assert ambiguous.protocol is None
+ assert ambiguous.authenticated is True
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(SOURCE_PROTOCOLS)
+ inventory_probe.assert_not_awaited()
+
+ timeout = EngineClientError("protocol observation timed out", error_type="timeout")
+
+ async def anthropic_timeout_blocks_openai_pairwise(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] == "anthropic":
+ raise timeout
+ if kwargs["protocol"] == "openai_responses":
+ return generic_request_accepted
+ if kwargs["protocol"] == "openai_chat":
+ return excluded_404
+ raise AssertionError(kwargs["protocol"])
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=anthropic_timeout_blocks_openai_pairwise),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("should-not-discover",)),
+ ) as inventory_probe,
+ ):
+ ambiguous = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
+ )
+
+ assert ambiguous.outcome.value == "ambiguous"
+ assert ambiguous.protocol is None
+ assert ambiguous.authenticated is True
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(SOURCE_PROTOCOLS)
+ inventory_probe.assert_not_awaited()
+
+ async def anthropic_competes_with_openai_pairwise(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] == "anthropic":
+ return generic_request_accepted
+ if kwargs["protocol"] == "openai_responses":
+ return generic_request_accepted
+ if kwargs["protocol"] == "openai_chat":
+ return excluded_404
+ raise AssertionError(kwargs["protocol"])
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=anthropic_competes_with_openai_pairwise),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("should-not-discover",)),
+ ) as inventory_probe,
+ ):
+ ambiguous = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
+ )
+
+ assert ambiguous.outcome.value == "ambiguous"
+ assert ambiguous.protocol is None
+ assert ambiguous.authenticated is True
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(SOURCE_PROTOCOLS)
+ inventory_probe.assert_not_awaited()
+
+ unproven_rejected = _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.REJECTED,
+ )
+
+ async def accepted_then_rejected_without_proof(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] == "anthropic":
+ return generic_request_accepted
+ if kwargs["protocol"] == "openai_responses":
+ return unproven_rejected
+ if kwargs["protocol"] == "openai_chat":
+ return unproven_unknown
+ raise AssertionError(kwargs["protocol"])
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=accepted_then_rejected_without_proof),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("should-not-discover",)),
+ ) as inventory_probe,
+ ):
+ ambiguous = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
+ )
+
+ assert ambiguous.outcome.value == "ambiguous"
+ assert ambiguous.protocol is None
+ assert ambiguous.authenticated is True
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(SOURCE_PROTOCOLS)
+ inventory_probe.assert_not_awaited()
+
+ async def rejected_anthropic_allows_openai_pairwise(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] == "anthropic":
+ return unproven_rejected
+ if kwargs["protocol"] == "openai_responses":
+ return excluded_404
+ if kwargs["protocol"] == "openai_chat":
+ return generic_request_accepted
+ raise AssertionError(kwargs["protocol"])
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=rejected_anthropic_allows_openai_pairwise),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("chat-only-model",)),
+ ) as inventory_probe,
+ ):
+ observed = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
+ )
+
+ assert observed.outcome.value == "observed"
+ assert observed.protocol == "openai_chat"
+ assert observed.authenticated is True
+ assert observed.model_ids == ("chat-only-model",)
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(SOURCE_PROTOCOLS)
+ assert inventory_probe.await_args.kwargs["protocol"] == "openai_chat"
+
+ transient_non_json = _parse_protocol_authenticated_evidence(
+ "openai_chat",
+ 502,
+ "<html>bad gateway</html>",
+ )
+ assert transient_non_json == _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.UNKNOWN,
+ )
+
+ async def transient_non_json_sibling_blocks_pairwise(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] == "anthropic":
+ return excluded_404
+ if kwargs["protocol"] == "openai_responses":
+ return generic_request_accepted
+ if kwargs["protocol"] == "openai_chat":
+ return transient_non_json
+ raise AssertionError(kwargs["protocol"])
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=transient_non_json_sibling_blocks_pairwise),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("should-not-discover",)),
+ ) as inventory_probe,
+ ):
+ ambiguous = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
+ )
+
+ assert ambiguous.outcome.value == "ambiguous"
+ assert ambiguous.protocol is None
+ assert ambiguous.authenticated is True
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(SOURCE_PROTOCOLS)
+ inventory_probe.assert_not_awaited()
+
+ async def anthropic_wrapperless_then_absent_openai(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] == "anthropic":
+ return generic_request_accepted
+ if kwargs["protocol"] == "openai_responses":
+ return excluded_404
+ if kwargs["protocol"] == "openai_chat":
+ return non_json
+ raise AssertionError(kwargs["protocol"])
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=anthropic_wrapperless_then_absent_openai),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("relay-model",)),
+ ) as inventory_probe,
+ ):
+ observed = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
+ )
+
+ assert observed.outcome.value == "observed"
+ assert observed.protocol == "anthropic"
+ assert observed.model_ids == ("relay-model",)
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(SOURCE_PROTOCOLS)
+ assert inventory_probe.await_args.kwargs["protocol"] == "anthropic"
+
+ async def anthropic_wrapperless_with_rejected_openai(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] == "anthropic":
+ return generic_request_accepted
+ if kwargs["protocol"] in openai_family:
+ return unproven_rejected
+ raise AssertionError(kwargs["protocol"])
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=anthropic_wrapperless_with_rejected_openai),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("anthropic-relay-model",)),
+ ) as inventory_probe,
+ ):
+ observed = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
+ )
+
+ assert observed.outcome.value == "observed"
+ assert observed.protocol == "anthropic"
+ assert observed.authenticated is True
+ assert observed.model_ids == ("anthropic-relay-model",)
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(SOURCE_PROTOCOLS)
+ assert inventory_probe.await_args.kwargs["protocol"] == "anthropic"
+
+ credential_param_rejected = _parse_protocol_authenticated_evidence(
+ "openai_responses",
+ 400,
+ json.dumps(
+ {
+ "error": {
+ "type": "invalid_request_error",
+ "param": "api_key",
+ }
+ }
+ ),
+ )
+ assert credential_param_rejected == _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.REJECTED,
+ )
+
+ async def credential_param_rejection_blocks_pairwise_proof(**kwargs) -> _ProtocolEvidence:
+ if kwargs["protocol"] == "anthropic":
+ return unproven_rejected
+ if kwargs["protocol"] == "openai_responses":
+ return credential_param_rejected
+ if kwargs["protocol"] == "openai_chat":
+ return excluded_404
+ raise AssertionError(kwargs["protocol"])
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(side_effect=credential_param_rejection_blocks_pairwise_proof),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("should-not-discover",)),
+ ) as inventory_probe,
+ ):
+ rejected = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
+ )
+
+ assert rejected.outcome.value == "authentication_failed"
+ assert rejected.protocol is None
+ assert rejected.authenticated is False
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == list(SOURCE_PROTOCOLS)
+ inventory_probe.assert_not_awaited()
+
+ with (
+ patch(
+ "vibe.model_hub_runtime.adapter._probe_protocol_response",
+ new=AsyncMock(return_value=generic_request_accepted),
+ ) as protocol_probe,
+ patch(
+ "vibe.model_hub_runtime.adapter.probe_models",
+ new=AsyncMock(return_value=("should-not-discover",)),
+ ) as inventory_probe,
+ ):
+ ambiguous = asyncio.run(
+ adapter.observe_source(
+ "openai",
+ base_url,
+ credential_ref,
+ ("anthropic",),
+ )
+ )
+
+ assert ambiguous.outcome.value == "ambiguous"
+ assert ambiguous.protocol is None
+ assert ambiguous.authenticated is True
+ assert [call.kwargs["protocol"] for call in protocol_probe.await_args_list] == ["anthropic"]
+ inventory_probe.assert_not_awaited()
+
async def shaped_server_failure(**kwargs) -> _ProtocolEvidence:
if kwargs["protocol"] == "anthropic":
body = {"type": "error", "error": {"type": "api_error"}}
@@ -4829,6 +5308,29 @@ def test_oauth_observation_uses_the_bound_auth_index_and_requires_response_proof
assert ambiguous.authenticated is None
+DEEPSEEK_AUTHENTICATION_ERROR_PAYLOAD = {
+ "error": {
+ "message": "Authentication Fails, Your api key: **** is invalid",
+ "type": "authentication_error",
+ "param": None,
+ "code": "invalid_request_error",
+ }
+}
+DEEPSEEK_MODEL_NOT_FOUND_PAYLOAD = {
+ "error": {
+ "type": "invalid_request_error",
+ "param": None,
+ "code": "model_not_found",
+ }
+}
+ANTHROPIC_RELAY_REQUEST_ERROR_PAYLOAD = {
+ "error": {
+ "message": "model is required",
+ "type": "invalid_request_error",
+ }
+}
+
+
@pytest.mark.parametrize(
("protocol", "success_body", "request_error_body", "auth_error_body"),
[
@@ -4901,9 +5403,52 @@ def test_protocol_evidence_parser_requires_candidate_specific_response_shapes(
) == _ProtocolEvidence(
protocol=_ProtocolProof.UNPROVEN,
authentication=_AuthenticationEvidence.UNKNOWN,
+ shape=_ProtocolObservationShape.UNSTRUCTURED,
)
+ ("status", "body", "expected"),
+ [
+ (
+ 400,
+ ANTHROPIC_RELAY_REQUEST_ERROR_PAYLOAD,
+ _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.ACCEPTED,
+ shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
+ ),
+ ),
+ (
+ 401,
+ {"error": {"type": "authentication_error"}},
+ _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.REJECTED,
+ ),
+ ),
+ (
+ 400,
+ {"error": {"type": "future_error"}},
+ _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.UNKNOWN,
+ ),
+ ),
+ ],
+)
+def test_anthropic_relay_openai_style_error_wrapper_preserves_canonical_semantics(
+ status: int,
+ body: dict,
+ expected: _ProtocolEvidence,
+) -> None:
+ assert _parse_protocol_authenticated_evidence(
+ "anthropic",
+ status,
+ json.dumps(body),
+ ) == expected
+
+
@pytest.mark.parametrize(
("protocol", "status", "body"),
[
@@ -4970,33 +5515,123 @@ def test_protocol_evidence_table_defaults_shaped_non_auth_rows_to_unknown(
@pytest.mark.parametrize(
- ("protocol", "body"),
+ ("protocol", "status", "body"),
[
(
"anthropic",
+ 404,
{"type": "error", "error": {"type": "not_found_error"}},
),
+ ],
+)
+def test_anthropic_protocol_evidence_table_accepts_authenticated_model_errors(
+ protocol: str,
+ status: int,
+ body: dict,
+) -> None:
+ assert _parse_protocol_authenticated_evidence(
+ protocol,
+ status,
+ json.dumps(body),
+ ) == _ProtocolEvidence(
+ protocol=_ProtocolProof.PROVEN,
+ authentication=_AuthenticationEvidence.ACCEPTED,
+ )
+
+
+ ("protocol", "status", "body"),
+ [
(
"openai_responses",
+ 404,
{"error": {"type": "invalid_request_error", "code": "model_not_found"}},
),
(
"openai_chat",
+ 404,
{"error": {"type": "invalid_request_error", "code": "model_not_found"}},
),
+ (
+ "openai_responses",
+ 400,
+ DEEPSEEK_MODEL_NOT_FOUND_PAYLOAD,
+ ),
+ (
+ "openai_chat",
+ 400,
+ DEEPSEEK_MODEL_NOT_FOUND_PAYLOAD,
+ ),
+ (
+ "openai_responses",
+ 422,
+ DEEPSEEK_MODEL_NOT_FOUND_PAYLOAD,
+ ),
+ (
+ "openai_chat",
+ 422,
+ DEEPSEEK_MODEL_NOT_FOUND_PAYLOAD,
+ ),
],
)
-def test_protocol_evidence_table_accepts_authenticated_model_errors(
+def test_openai_model_errors_without_family_param_record_accepted_but_unproven_evidence(
protocol: str,
+ status: int,
body: dict,
) -> None:
assert _parse_protocol_authenticated_evidence(
protocol,
- 404,
+ status,
json.dumps(body),
) == _ProtocolEvidence(
- protocol=_ProtocolProof.PROVEN,
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.ACCEPTED,
+ shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
+ )
+
+
[email protected]("protocol", ("openai_responses", "openai_chat"))
+def test_openai_request_error_without_family_param_records_accepted_but_unproven_evidence(
+ protocol: str,
+) -> None:
+ assert _parse_protocol_authenticated_evidence(
+ protocol,
+ 400,
+ json.dumps(
+ {
+ "error": {
+ "type": "invalid_request_error",
+ "param": None,
+ }
+ }
+ ),
+ ) == _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
authentication=_AuthenticationEvidence.ACCEPTED,
+ shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
+ )
+
+
[email protected]("protocol", SOURCE_PROTOCOLS)
[email protected]("status", (400, 422))
+def test_request_error_with_credential_param_is_rejected(
+ protocol: str,
+ status: int,
+) -> None:
+ assert _parse_protocol_authenticated_evidence(
+ protocol,
+ status,
+ json.dumps(
+ {
+ "error": {
+ "type": "invalid_request_error",
+ "param": "api_key",
+ }
+ }
+ ),
+ ) == _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.REJECTED,
)
@@ -5022,6 +5657,60 @@ def test_shared_openai_authentication_rejection_does_not_prove_a_protocol() -> N
)
[email protected]("protocol", ("openai_responses", "openai_chat"))
+def test_deepseek_authentication_rejection_with_null_param_stays_unproven(
+ protocol: str,
+) -> None:
+ assert _parse_protocol_authenticated_evidence(
+ protocol,
+ 401,
+ json.dumps(DEEPSEEK_AUTHENTICATION_ERROR_PAYLOAD),
+ ) == _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.REJECTED,
+ )
+
+
+def test_structured_but_unrecognized_openai_error_is_not_exclusion_evidence() -> None:
+ assert _parse_protocol_authenticated_evidence(
+ "openai_chat",
+ 400,
+ json.dumps({"error": {"type": "future_error"}}),
+ ) == _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.UNKNOWN,
+ )
+
+
+def test_request_error_404_and_non_json_responses_are_pairwise_exclusion_shapes() -> None:
+ assert _parse_protocol_authenticated_evidence(
+ "openai_responses",
+ 404,
+ json.dumps({}),
+ ) == _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.UNKNOWN,
+ shape=_ProtocolObservationShape.HTTP_404,
+ )
+ assert _parse_protocol_authenticated_evidence(
+ "openai_responses",
+ 400,
+ "<html>route not found</html>",
+ ) == _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.UNKNOWN,
+ shape=_ProtocolObservationShape.NON_JSON,
+ )
+ assert _parse_protocol_authenticated_evidence(
+ "openai_responses",
+ 502,
+ "<html>bad gateway</html>",
+ ) == _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.UNKNOWN,
+ )
+
+
def test_top_level_authentication_rejection_is_classified_without_forging_protocol() -> None:
body = json.dumps({"code": "INVALID_API_KEY", "message": "Invalid API key"})
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index fa09b35a7..569f5fcee 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -1273,7 +1273,7 @@
"retry": "Retry",
"undetermined": {
"title": "Connected and authenticated — but we cannot tell which interface it speaks",
- "detail": "The response shape matches no interface we know; choose a concrete interface and retry"
+ "detail": "This response shape matches no interface we know; choosing one only narrows the retry probe, and the endpoint still has to prove the interface in its response"
},
"protocol": {
"auto": "Auto detect",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 105c73e81..7fdf40f21 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -1273,7 +1273,7 @@
"retry": "重试",
"undetermined": {
"title": "连上了、也通过了鉴权 —— 但认不出它说哪种接口",
- "detail": "返回结构对不上任何一种已知接口,请选择一个明确类型后重试"
+ "detail": "这次返回结构对不上任何一种已知接口;手动选择只会缩小重试探测范围,仍要由该地址返回的响应把接口类型证明出来"
},
"protocol": {
"auto": "自动探测",
diff --git a/vibe/model_hub_runtime/adapter.py b/vibe/model_hub_runtime/adapter.py
index 2f6c9a67e..7727ae49e 100644
--- a/vibe/model_hub_runtime/adapter.py
+++ b/vibe/model_hub_runtime/adapter.py
@@ -79,10 +79,19 @@ class _AuthenticationEvidence(Enum):
UNKNOWN = "unknown"
+class _ProtocolObservationShape(Enum):
+ NONE = "none"
+ GENERIC_REQUEST_ERROR = "generic_request_error"
+ HTTP_404 = "http_404"
+ NON_JSON = "non_json"
+ UNSTRUCTURED = "unstructured"
+
+
@dataclass(frozen=True)
class _ProtocolEvidence:
protocol: _ProtocolProof
authentication: _AuthenticationEvidence
+ shape: _ProtocolObservationShape = _ProtocolObservationShape.NONE
@dataclass(frozen=True)
@@ -90,6 +99,7 @@ class _ProtocolEvidenceRule:
statuses: frozenset[int]
protocol: _ProtocolProof
authentication: _AuthenticationEvidence
+ shape: _ProtocolObservationShape = _ProtocolObservationShape.NONE
top_level_field: str | None = None
top_level_values: frozenset[str] = frozenset()
error_identifiers: frozenset[str] = frozenset()
@@ -174,6 +184,35 @@ _OPENAI_CHAT_PARAMS = frozenset(
"top_p",
}
)
+_OPENAI_FAMILY_PROTOCOLS = frozenset({"openai_responses", "openai_chat"})
+_OPENAI_FAMILY_PARAMS = _OPENAI_RESPONSES_PARAMS | _OPENAI_CHAT_PARAMS
+_CREDENTIAL_ERROR_PARAMS = frozenset(
+ {
+ "api_key",
+ "api-key",
+ "access_token",
+ "access-token",
+ "authorization",
+ "auth",
+ "auth_token",
+ "auth-token",
+ "bearer_token",
+ "bearer-token",
+ "token",
+ "x-api-key",
+ "x_api_key",
+ "x-auth-token",
+ "x_auth_token",
+ "x-token",
+ }
+)
+_PAIRWISE_EXCLUSION_SHAPES = frozenset(
+ {
+ _ProtocolObservationShape.HTTP_404,
+ _ProtocolObservationShape.NON_JSON,
+ _ProtocolObservationShape.UNSTRUCTURED,
+ }
+)
def _openai_evidence_rules(
@@ -196,10 +235,11 @@ def _openai_evidence_rules(
authentication=_AuthenticationEvidence.ACCEPTED,
),
_ProtocolEvidenceRule(
- statuses=frozenset({404}),
+ statuses=_REQUEST_ERROR_STATUSES,
error_identifiers=_MODEL_ERROR_IDENTIFIERS,
- protocol=_ProtocolProof.PROVEN,
+ protocol=_ProtocolProof.UNPROVEN,
authentication=_AuthenticationEvidence.ACCEPTED,
+ shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
),
_ProtocolEvidenceRule(
statuses=_AUTHENTICATION_ERROR_STATUSES,
@@ -302,6 +342,84 @@ _PROTOCOL_OBSERVATION_TAXONOMY = {
}
+def _error_identifiers(error: Mapping[str, Any]) -> frozenset[str]:
+ return frozenset(
+ value.strip().lower()
+ for value in (error.get("type"), error.get("code"))
+ if isinstance(value, str)
+ )
+
+
+def _error_param_name(error: Mapping[str, Any]) -> str | None:
+ value = error.get("param")
+ if not isinstance(value, str):
+ return None
+ normalized = value.strip().lower()
+ return normalized or None
+
+
+def _request_error_rejects_credential(
+ status: int,
+ error: Mapping[str, Any] | None,
+) -> bool:
+ return (
+ status in _REQUEST_ERROR_STATUSES
+ and isinstance(error, dict)
+ and _error_param_name(error) in _CREDENTIAL_ERROR_PARAMS
+ )
+
+
+def _payload_is_structured(payload: Mapping[str, Any]) -> bool:
+ return (
+ isinstance(payload.get("error"), dict)
+ or isinstance(payload.get("type"), str)
+ or isinstance(payload.get("code"), str)
+ or isinstance(payload.get("object"), str)
+ )
+
+
+def _anthropic_wrapperless_error_kind(
+ status: int,
+ payload: Mapping[str, Any],
+) -> str | None:
+ if "type" in payload:
+ return None
+ error = payload.get("error")
+ if not isinstance(error, dict):
+ return None
+ if _request_error_rejects_credential(status, error):
+ return "rejected"
+ identifiers = _error_identifiers(error)
+ if status in _REQUEST_ERROR_STATUSES and not (
+ _REQUEST_ERROR_IDENTIFIERS | _MODEL_ERROR_IDENTIFIERS
+ ).isdisjoint(identifiers):
+ return "accepted"
+ if status in _AUTHENTICATION_ERROR_STATUSES and not _AUTHENTICATION_ERROR_IDENTIFIERS.isdisjoint(identifiers):
+ return "rejected"
+ if status in _SERVER_ERROR_STATUSES and not _SERVER_ERROR_IDENTIFIERS.isdisjoint(identifiers):
+ return "unknown"
+ if status in _RATE_LIMIT_STATUSES and not _RATE_LIMIT_ERROR_IDENTIFIERS.isdisjoint(identifiers):
+ return "unknown"
+ return None
+
+
+def _default_unproven_shape(
+ *,
+ status: int,
+ payload: Mapping[str, Any] | None = None,
+ non_json: bool = False,
+) -> _ProtocolObservationShape:
+ if status == 404:
+ return _ProtocolObservationShape.HTTP_404
+ if status not in _REQUEST_ERROR_STATUSES:
+ return _ProtocolObservationShape.NONE
+ if non_json:
+ return _ProtocolObservationShape.NON_JSON
+ if payload is None or not _payload_is_structured(payload):
+ return _ProtocolObservationShape.UNSTRUCTURED
+ return _ProtocolObservationShape.NONE
+
+
def _parse_protocol_authenticated_evidence(
protocol: str,
status: int,
@@ -327,11 +445,13 @@ def _parse_protocol_authenticated_evidence(
return _ProtocolEvidence(
protocol=_ProtocolProof.UNPROVEN,
authentication=_AuthenticationEvidence.UNKNOWN,
+ shape=_default_unproven_shape(status=status, non_json=True),
)
if not isinstance(payload, dict):
return _ProtocolEvidence(
protocol=_ProtocolProof.UNPROVEN,
authentication=_AuthenticationEvidence.UNKNOWN,
+ shape=_default_unproven_shape(status=status),
)
top_level_identifiers = {
@@ -347,6 +467,31 @@ def _parse_protocol_authenticated_evidence(
protocol=_ProtocolProof.UNPROVEN,
authentication=_AuthenticationEvidence.REJECTED,
)
+ error = payload.get("error")
+ if _request_error_rejects_credential(status, error):
+ return _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.REJECTED,
+ )
+
+ if protocol == "anthropic":
+ wrapperless = _anthropic_wrapperless_error_kind(status, payload)
+ if wrapperless == "accepted":
+ return _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.ACCEPTED,
+ shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
+ )
+ if wrapperless == "rejected":
+ return _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.REJECTED,
+ )
+ if wrapperless == "unknown":
+ return _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.UNKNOWN,
+ )
taxonomy = _PROTOCOL_OBSERVATION_TAXONOMY.get(protocol)
for rule in taxonomy.evidence_rules if taxonomy is not None else ():
@@ -354,12 +499,30 @@ def _parse_protocol_authenticated_evidence(
return _ProtocolEvidence(
protocol=rule.protocol,
authentication=rule.authentication,
+ shape=rule.shape,
)
+ if protocol in _OPENAI_FAMILY_PROTOCOLS and status in _REQUEST_ERROR_STATUSES:
+ if isinstance(error, dict):
+ identifiers = _error_identifiers(error)
+ if (
+ not _REQUEST_ERROR_IDENTIFIERS.isdisjoint(identifiers)
+ and _AUTHENTICATION_ERROR_IDENTIFIERS.isdisjoint(identifiers)
+ and _error_param_name(error) not in _OPENAI_FAMILY_PARAMS
+ ):
+ return _ProtocolEvidence(
+ protocol=_ProtocolProof.UNPROVEN,
+ authentication=_AuthenticationEvidence.ACCEPTED,
+ shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
+ )
+ if _response_shape_proves_protocol(protocol, payload):
+ return _ProtocolEvidence(
+ protocol=_ProtocolProof.PROVEN,
+ authentication=_AuthenticationEvidence.UNKNOWN,
+ )
return _ProtocolEvidence(
- protocol=(
- _ProtocolProof.PROVEN if _response_shape_proves_protocol(protocol, payload) else _ProtocolProof.UNPROVEN
- ),
+ protocol=_ProtocolProof.UNPROVEN,
authentication=_AuthenticationEvidence.UNKNOWN,
+ shape=_default_unproven_shape(status=status, payload=payload),
)
@@ -437,7 +600,9 @@ def _response_shape_proves_protocol(
if protocol == "anthropic":
error = body.get("error")
return body.get("type") == "message" or (
- body.get("type") == "error" and isinstance(error, dict) and isinstance(error.get("type"), str)
+ body.get("type") == "error"
+ and isinstance(error, dict)
+ and isinstance(error.get("type"), str)
)
error = body.get("error")
if protocol == "openai_responses":
@@ -451,6 +616,96 @@ def _response_shape_proves_protocol(
return False
+def _openai_family_elimination_proof(
+ responses: Mapping[str, _ProtocolEvidence],
+ *,
+ considered_protocols: frozenset[str],
+ ruled_out_protocols: frozenset[str],
+) -> str | None:
+ """Prove one OpenAI-family protocol from the pair of responses, not from the URL.
+
+ A request-error row with matched identifiers but no family-distinctive
+ ``param`` proves only that one endpoint parsed the synthetic request with
+ authentication accepted. The sibling protocol becomes excluded only when its
+ own endpoint answers the same source with an unproven shape, so the proof is
+ carried by the response pair rather than by either request path alone. That
+ pairwise proof is valid only when every other probed protocol was already
+ ruled out for this source. A competing protocol can be ruled out by an
+ explicit authentication rejection or by a definitive request-error-shaped
+ exclusion. Transient upstream failures do not qualify.
+ """
+
+ if not {
+ protocol for protocol in considered_protocols if protocol not in _OPENAI_FAMILY_PROTOCOLS
+ }.issubset(ruled_out_protocols):
+ return None
+
+ candidate = responses.get("openai_responses")
+ sibling = responses.get("openai_chat")
+ if (
+ candidate is not None
+ and sibling is not None
+ and candidate.protocol is _ProtocolProof.UNPROVEN
+ and candidate.authentication is _AuthenticationEvidence.ACCEPTED
+ and candidate.shape is _ProtocolObservationShape.GENERIC_REQUEST_ERROR
+ and sibling.protocol is _ProtocolProof.UNPROVEN
+ and sibling.authentication is _AuthenticationEvidence.UNKNOWN
+ and sibling.shape in _PAIRWISE_EXCLUSION_SHAPES
+ ):
+ return "openai_responses"
+ if (
+ candidate is not None
+ and sibling is not None
+ and sibling.protocol is _ProtocolProof.UNPROVEN
+ and sibling.authentication is _AuthenticationEvidence.ACCEPTED
+ and sibling.shape is _ProtocolObservationShape.GENERIC_REQUEST_ERROR
+ and candidate.protocol is _ProtocolProof.UNPROVEN
+ and candidate.authentication is _AuthenticationEvidence.UNKNOWN
+ and candidate.shape in _PAIRWISE_EXCLUSION_SHAPES
+ ):
+ return "openai_chat"
+ return None
+
+
+def _pairwise_positive_exclusion(evidence: _ProtocolEvidence) -> bool:
+ return (
+ evidence.protocol is _ProtocolProof.UNPROVEN
+ and evidence.authentication is _AuthenticationEvidence.UNKNOWN
+ and evidence.shape in _PAIRWISE_EXCLUSION_SHAPES
+ )
+
+
+def _anthropic_wrapperless_elimination_proof(
+ responses: Mapping[str, _ProtocolEvidence],
+ *,
+ considered_protocols: frozenset[str],
+ ruled_out_protocols: frozenset[str],
+) -> str | None:
+ """Prove wrapperless Anthropic only from the complete response set.
+
+ A wrapperless ``{"error": {"type": ...}}`` request error still proves only
+ that the endpoint accepted the credential and parsed the synthetic request.
+ It becomes Anthropic evidence only when both OpenAI-family sibling probes
+ were actually part of this observation round and their own responses ruled
+ them out. The proof is therefore carried by the response set, not by the
+ ``/v1/messages`` path alone.
+ """
+
+ if not _OPENAI_FAMILY_PROTOCOLS.issubset(considered_protocols):
+ return None
+ if not _OPENAI_FAMILY_PROTOCOLS.issubset(ruled_out_protocols):
+ return None
+ candidate = responses.get("anthropic")
+ if (
+ candidate is not None
+ and candidate.protocol is _ProtocolProof.UNPROVEN
+ and candidate.authentication is _AuthenticationEvidence.ACCEPTED
+ and candidate.shape is _ProtocolObservationShape.GENERIC_REQUEST_ERROR
+ ):
+ return "anthropic"
+ return None
+
+
def _probe_oauth_protocol_response(
*,
client: EngineClient,
@@ -1217,6 +1472,9 @@ class CLIProxyEngineAdapter:
received_rejection = False
received_proven_unknown = False
received_unproven_response = False
+ received_accepted_unproven_response = False
+ response_evidence_by_protocol: dict[str, _ProtocolEvidence] = {}
+ ruled_out_protocols: set[str] = set()
for protocol in protocol_order:
if protocol not in SOURCE_PROTOCOLS:
raise EngineStateError("unsupported source protocol")
@@ -1242,26 +1500,34 @@ class CLIProxyEngineAdapter:
continue
if evidence.authentication is _AuthenticationEvidence.REJECTED:
received_rejection = True
+ ruled_out_protocols.add(protocol)
continue
+ proved_protocol: str | None = None
if evidence.protocol is _ProtocolProof.PROVEN:
if evidence.authentication is _AuthenticationEvidence.UNKNOWN:
received_proven_unknown = True
continue
+ proved_protocol = protocol
else:
received_unproven_response = True
+ if evidence.authentication is _AuthenticationEvidence.ACCEPTED:
+ received_accepted_unproven_response = True
+ if _pairwise_positive_exclusion(evidence):
+ ruled_out_protocols.add(protocol)
+ response_evidence_by_protocol[protocol] = evidence
continue
try:
if credential_kind == "api_key":
models = await probe_models(
vendor=normalized_vendor,
- protocol=protocol,
+ protocol=proved_protocol,
base_url=base_url,
secret=secret or "",
)
else:
models = await self.discover_models(
normalized_vendor,
- protocol,
+ proved_protocol,
None,
credential_ref,
)
@@ -1274,11 +1540,63 @@ class CLIProxyEngineAdapter:
outcome=ObservationOutcome.OBSERVED,
reachable=True,
authenticated=True,
- protocol=protocol,
+ protocol=proved_protocol,
discovery=discovery,
model_ids=tuple(models),
)
+ considered_protocols = frozenset(protocol_order)
+ proved_protocol = _openai_family_elimination_proof(
+ response_evidence_by_protocol,
+ considered_protocols=considered_protocols,
+ ruled_out_protocols=frozenset(ruled_out_protocols),
+ ) or _anthropic_wrapperless_elimination_proof(
+ response_evidence_by_protocol,
+ considered_protocols=considered_protocols,
+ ruled_out_protocols=frozenset(ruled_out_protocols),
+ )
+ if proved_protocol is not None:
+ try:
+ if credential_kind == "api_key":
+ models = await probe_models(
+ vendor=normalized_vendor,
+ protocol=proved_protocol,
+ base_url=base_url,
+ secret=secret or "",
+ )
+ else:
+ models = await self.discover_models(
+ normalized_vendor,
+ proved_protocol,
+ None,
+ credential_ref,
+ )
+ except (EngineClientError, ModelDiscoveryError):
+ discovery = ObservationDiscovery.FAILED
+ models = ()
+ else:
+ discovery = ObservationDiscovery.SUCCEEDED
+ return make_source_observation(
+ outcome=ObservationOutcome.OBSERVED,
+ reachable=True,
+ authenticated=True,
+ protocol=proved_protocol,
+ discovery=discovery,
+ model_ids=tuple(models),
+ )
+
+ if received_accepted_unproven_response:
+ # A shaped request error already proved the credential was accepted
+ # even when the response family never narrowed to one persisted
+ # protocol.
+ return make_source_observation(
+ outcome=ObservationOutcome.AMBIGUOUS,
+ reachable=True,
+ authenticated=True,
+ protocol=None,
+ discovery=ObservationDiscovery.NOT_ATTEMPTED,
+ model_ids=(),
+ )
if received_rejection:
return make_source_observation(
outcome=ObservationOutcome.AUTHENTICATION_FAILED,