from collections import Counter from aiatlas.connectors.providers.openrouter import OpenRouterConnector, _display_name, _per_mtok from aiatlas.sdk.facts import Target from tests.conftest import claims_of, extract_from_fixture, fixture_path async def test_catalogue(): c = OpenRouterConnector() target = Target(url="https://openrouter.ai/api/v1/models", doc_type="catalogue", key="models") facts = await extract_from_fixture(c, target, fixture_path("openrouter", "models.json"), content_type="application/json") models = [e for e in facts.entities if e.entity_type == "model"] assert len(models) >= 300 and not any(e.identifiers.get("openrouter", "").startswith("~") for e in models) # alias rows skipped assert len(facts.prices) >= 150 sonnet = next(p for p in facts.prices if p.provider_model_id == "anthropic/claude-sonnet-4.5") assert sonnet.model.name == "Claude Sonnet 4.5" and sonnet.model.organization.name == "Anthropic" assert sonnet.provider.name == "Anthropic API" and sonnet.features["via"] == "openrouter" assert (sonnet.input_per_mtok, sonnet.output_per_mtok, sonnet.cached_input_per_mtok) == (3.0, 15.0, 0.3) # per-token strings × 1e6 claims = claims_of(facts, "Claude Sonnet 4.5") assert claims["context_length"] == 1_000_000 and claims["max_output_tokens"] == 64000 and claims["release_date"] == "2025-09-29" assert claims["modalities_input"] == ["image", "text"] and claims["file_input"] is True # "file" is not in the modality vocabulary assert "tools" in claims["supported_parameters"] and claims["tool_calling"] is True by_provider = Counter(p.provider.name for p in facts.prices) assert by_provider["OpenAI API"] >= 50 and by_provider["OpenRouter"] >= 50 # unknown vendors → aggregator variant = next(p for p in facts.prices if ":" in (p.provider_model_id or "")) assert "variant" in variant.features and ":" not in variant.model.identifiers["openrouter"] # variants share the model identity assert not any(p.input_per_mtok is not None and p.input_per_mtok < 0 for p in facts.prices) # dynamic "-1" prices skipped assert any("hf_repo" in e.identifiers for e in models) def test_helpers(): assert _display_name("Anthropic: Claude Sonnet 4.5", "anthropic") == "Claude Sonnet 4.5" assert _display_name("Sakana: Something", "sakana") == "Something" assert _per_mtok("0.000003") == 3.0 and _per_mtok("-1") == -1.0 and _per_mtok(None) is None