-
Notifications
You must be signed in to change notification settings - Fork 1
fix(discovery): route OpenRouter by model evidence #949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3cd0994
fix(discovery): route OpenRouter by model evidence
seonghobae 547dd6a
fix(discovery): preserve OpenRouter spend admission
seonghobae 99ef352
fix(discovery): revalidate OpenRouter paid routes
seonghobae dbe7564
fix(discovery): recover spend-blocked routes safely
seonghobae 826cda2
fix(discovery): preserve operator disable state
seonghobae 0fd0347
fix(discovery): keep spend block provenance stable
seonghobae 229752e
test: align OpenRouter fixtures with spend policy
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,7 +197,6 @@ def configured_gateway_source( | |
| list_url="https://openrouter.ai/api/v1/models?output_modalities=all", | ||
| chat_base_url="https://openrouter.ai/api/v1", | ||
| capabilities=("chat",), | ||
| evidence_only=True, | ||
| ), | ||
| ProviderModelSource( | ||
| provider_name="opencode_zen", | ||
|
|
@@ -285,6 +284,7 @@ class DiscoveredModel: | |
| privacy_policy_urls: tuple[str, ...] = () | ||
| zdr_capable: bool = False | ||
| evidence_only: bool = False | ||
| spend_admitted: bool = True | ||
|
|
||
|
|
||
| class ProviderDiscoveryError(RuntimeError): | ||
|
|
@@ -1279,13 +1279,23 @@ def discover_all_models( | |
| ) | ||
| except ProviderDiscoveryError as exc: | ||
| errors.append(exc) | ||
| # The OpenRouter catalog is evidence-only; its public ZDR endpoint supplies | ||
| # matching privacy evidence for discovered models from other providers. It | ||
| # is never selected as an inference upstream here. | ||
| return _apply_discovered_model_evidence( | ||
| # OpenRouter's authenticated catalog supplies routable account-model rows; | ||
| # its public ZDR endpoint adds route-specific privacy evidence without | ||
| # turning the whole provider account into either ZDR-only or non-serving. | ||
|
Comment on lines
+1282
to
+1284
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| routed = _apply_discovered_model_evidence( | ||
| _deduplicate_discovered_models(discovered), | ||
| _openrouter_zdr_model_ids(timeout=timeout), | ||
| ), errors | ||
| ) | ||
| if any( | ||
| source.provider_name == "openrouter" | ||
| and get_credential(source.credential_name) | ||
| for source in sources | ||
| ): | ||
| routed = apply_openrouter_spend_admission( | ||
| routed, | ||
| openrouter_paid_inference_available(timeout=timeout), | ||
| ) | ||
| return routed, errors | ||
|
|
||
|
|
||
| def openrouter_paid_inference_available( | ||
|
|
@@ -1321,6 +1331,24 @@ def openrouter_paid_inference_available( | |
| return None | ||
|
|
||
|
|
||
| def apply_openrouter_spend_admission( | ||
| discovered: Sequence[DiscoveredModel], | ||
| paid_available: bool | None, | ||
| ) -> list[DiscoveredModel]: | ||
| """Fail closed for paid OpenRouter rows without current credit evidence.""" | ||
| return [ | ||
| replace( | ||
| model, | ||
| spend_admitted=( | ||
| model.provider_name != "openrouter" | ||
| or model.is_free | ||
| or paid_available is True | ||
| ), | ||
| ) | ||
| for model in discovered | ||
| ] | ||
|
|
||
|
|
||
| _SLUG_RE = re.compile(r"[^a-z0-9]+") | ||
|
|
||
|
|
||
|
|
@@ -1367,8 +1395,10 @@ def is_routable_discovered_model(discovered: DiscoveredModel) -> bool: | |
| expose a media-only model with a generic identifier, so the model-name | ||
| heuristic is only a fallback for rows with no capability or modality data. | ||
| """ | ||
| return not discovered.evidence_only and is_discovered_chat_candidate( | ||
| discovered | ||
| return ( | ||
| not discovered.evidence_only | ||
| and discovered.spend_admitted | ||
| and is_discovered_chat_candidate(discovered) | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -1393,6 +1423,7 @@ def agent_from_discovered(discovered: DiscoveredModel, *, priority: int = 0) -> | |
| tags=( | ||
| "discovered", | ||
| *(("cost:free",) if discovered.is_free else ()), | ||
| *(("spend:blocked",) if not discovered.spend_admitted else ()), | ||
| *privacy_tags_for_discovered(discovered), | ||
| *discovered.capabilities, | ||
| *(f"capability:{value}" for value in discovered.capabilities), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,13 @@ publish the same fields through model metadata, but a logical model receives a | |
| value only when every deployment agrees. Thus free status never implies privacy, | ||
| and paid status never implies retention. | ||
|
|
||
| OpenRouter's authenticated catalog rows remain ordinary serving candidates. | ||
| The ZDR inventory qualifies only matching account-model routes when a request | ||
| requires ZDR; it does not make the entire OpenRouter account evidence-only and | ||
| does not exclude non-ZDR routes from ordinary requests. Missing or failed ZDR | ||
| evidence therefore fails closed only for `zdr_only` selection, not for general | ||
| inference. | ||
|
Comment on lines
+39
to
+44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| OpenAI catalog rows also retain OpenAI's official data-controls documentation | ||
| as policy evidence. Because approval and enablement are organization/project | ||
| settings that the Models API does not disclose, discovery leaves the actual ZDR | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.