Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(cost): require exactly two non-empty segments in a passthrough id

Ghost Scripterbe43e7ca4e25
diff --git a/src/openhuman/platform/cost/route.rs b/src/openhuman/platform/cost/route.rs
index 91031e0728..7d342a308c 100644
--- a/src/openhuman/platform/cost/route.rs
+++ b/src/openhuman/platform/cost/route.rs
@@ -90,9 +90,18 @@ pub fn route_for_model(model: &str) -> CostRoute {
/// (`deepseek/deepseek-v4-flash`), never with this `openrouter/` qualifier, so
/// the two cannot be confused.
fn is_managed_passthrough_id(normalized: &str) -> bool {
- normalized
- .strip_prefix("openrouter/")
- .is_some_and(|rest| rest.split('/').filter(|seg| !seg.is_empty()).count() == 2)
+ let Some(rest) = normalized.strip_prefix("openrouter/") else {
+ return false;
+ };
+ // EXACTLY two non-empty segments. Filtering empties before counting would
+ // accept `openrouter/a//b` and `openrouter/a/b/`, which are not the
+ // passthrough shape; classifying a malformed id as managed would count it
+ // toward the managed cap on the strength of a typo.
+ let mut segments = rest.split('/');
+ match (segments.next(), segments.next(), segments.next()) {
+ (Some(author), Some(slug), None) => !author.is_empty() && !slug.is_empty(),
+ _ => false,
+ }
}
/// Lower-case, trim, and strip the decorations a model id can pick up on its
diff --git a/src/openhuman/platform/cost/route_tests.rs b/src/openhuman/platform/cost/route_tests.rs
index 8b278c8f57..9af44830d5 100644
--- a/src/openhuman/platform/cost/route_tests.rs
+++ b/src/openhuman/platform/cost/route_tests.rs
@@ -154,6 +154,11 @@ fn byok_openrouter_slugs_and_malformed_passthrough_ids_stay_byok() {
"openrouter/deepseek",
"openrouter/",
"openrouter/a/b/c",
+ // empty segments are not the passthrough shape either
+ "openrouter/a//b",
+ "openrouter/a/b/",
+ "openrouter//b",
+ "openrouter///",
] {
assert_eq!(route_for_model(model), CostRoute::Byok, "{model}");
}