Add OpenRouter platform: wire-served metadata (provider 8)
The 11th registry row and the first THIRD-PARTY wire_serves_metadata=true provider: id "openrouter", OPENROUTER_API_KEY > auth.json "openrouter" scope, https://openrouter.ai/api/v1 (note /api/v1) with KIGI_OPENROUTER_BASE_URL override, Bearer, OpenAI listing + ChatCompletions + Passthrough. OpenRouter's public /models serves context_length for every model (verified live: 340/340), so it needs NO enrichment: models_dev_id=None, wire_serves_metadata=true, restrict_to_enriched=false. An OpenRouter-only user makes zero models.dev calls; context comes straight from the listing. Slashed ids (anthropic/claude-opus-4.8) round-trip through the managed key via the first-slash split; the native id rides the wire. The e2e pins all of this with the models.dev refresh disabled. Review-confirmed defect fixed (and independently re-verified with live curls): OpenRouter's /models is PUBLIC — GET /models returns 200 for ANY key — so login key-validation would false-accept a bad key, deferring the failure to the first chat 401. New spec field key_validation_path lets a public-listing platform validate against an auth-requiring endpoint; OpenRouter uses /key (401s for bad keys). Reusable for Vercel (also public). Tests pin the /key validation and no regression to the default /models path. Gate caught a fixture regression: the kimi_import test used openrouter.ai to represent a CUSTOM provider, which now correctly dedupes to the builtin OpenRouter — moved the fixture to a reserved llm.example.test host that no future platform can shadow.
This commit is contained in:
@@ -1505,6 +1505,98 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// OpenRouter-cycle e2e: wire_serves_metadata=true — the listing itself
|
||||
/// carries `context_length`, so context comes from the WIRE with NO
|
||||
/// enrichment fetch and NO restriction (all models kept). The models.dev
|
||||
/// refresh is disabled to prove it is never consulted. Slashed ids
|
||||
/// round-trip; Passthrough dialect.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[serial_test::serial]
|
||||
async fn openrouter_wire_metadata_needs_no_enrichment_and_keeps_all() {
|
||||
let platform_server = wiremock::MockServer::start().await;
|
||||
wiremock::Mock::given(wiremock::matchers::method("GET"))
|
||||
.and(wiremock::matchers::path("/models"))
|
||||
.and(wiremock::matchers::header("Authorization", "Bearer or-1"))
|
||||
.respond_with(wiremock::ResponseTemplate::new(200).set_body_json(
|
||||
serde_json::json!({ "data": [
|
||||
{ "id": "anthropic/claude-opus-4.8", "context_length": 1000000,
|
||||
"supported_parameters": ["reasoning_effort", "tools"] },
|
||||
{ "id": "openai/gpt-5.5", "context_length": 400000,
|
||||
"supported_parameters": ["tools"] }
|
||||
]}),
|
||||
))
|
||||
.expect(1)
|
||||
.mount(&platform_server)
|
||||
.await;
|
||||
let cache_dir = tempfile::tempdir().unwrap();
|
||||
let _base = kigi_test_support::EnvGuard::set(
|
||||
kigi_models::OPENROUTER_BASE_URL_ENV,
|
||||
platform_server.uri(),
|
||||
);
|
||||
// Kill switch: proves enrichment is never fetched for a wire-served
|
||||
// platform (any attempt would need this URL).
|
||||
let _mdev = kigi_test_support::EnvGuard::set(
|
||||
crate::agent::enrichment_fetch::MODELS_DEV_URL_ENV,
|
||||
"0",
|
||||
);
|
||||
let _mdev_cache = kigi_test_support::EnvGuard::set(
|
||||
crate::agent::enrichment_fetch::MODELS_DEV_CACHE_DIR_ENV,
|
||||
cache_dir.path(),
|
||||
);
|
||||
let endpoints = crate::agent::config::EndpointsConfig::default();
|
||||
let keys = crate::agent::models::PlatformApiKeys::test_single(
|
||||
kigi_models::PlatformId::OpenRouter,
|
||||
"or-1",
|
||||
);
|
||||
let result = tokio::task::spawn_blocking(move || {
|
||||
fetch_platform_models_blocking(&endpoints, None, &keys)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
.expect("fetch must succeed");
|
||||
assert_eq!(
|
||||
result
|
||||
.models
|
||||
.iter()
|
||||
.map(|m| m.id.as_deref().unwrap_or_default())
|
||||
.collect::<Vec<_>>(),
|
||||
vec![
|
||||
"openrouter/anthropic/claude-opus-4.8",
|
||||
"openrouter/openai/gpt-5.5"
|
||||
],
|
||||
"no restriction — all listed models kept; slashed ids in the key"
|
||||
);
|
||||
let opus = &result.models[0];
|
||||
assert_eq!(
|
||||
opus.context_window.get(),
|
||||
1_000_000,
|
||||
"context window comes from the wire listing, not enrichment"
|
||||
);
|
||||
assert_eq!(
|
||||
opus.model, "anthropic/claude-opus-4.8",
|
||||
"the native slashed id rides the wire"
|
||||
);
|
||||
assert_eq!(
|
||||
kigi_models::parse_managed_model_key(opus.id.as_deref().unwrap()),
|
||||
Some((
|
||||
kigi_models::PlatformId::OpenRouter,
|
||||
"anthropic/claude-opus-4.8"
|
||||
))
|
||||
);
|
||||
let model_entry = crate::agent::config::ModelEntry::from_config_entry(opus);
|
||||
let creds = crate::agent::config::ResolvedCredentials {
|
||||
api_key: Some("or-1".into()),
|
||||
base_url: opus.base_url.clone(),
|
||||
auth_type: kigi_chat_state::AuthType::ApiKey,
|
||||
auth_scheme: Default::default(),
|
||||
};
|
||||
let cfg = crate::agent::config::sampling_config_for_model(&model_entry, creds, None);
|
||||
assert_eq!(
|
||||
cfg.chat_compat,
|
||||
kigi_sampling_types::ChatCompat::Passthrough
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_env_keys_parses_strings_and_rejects_non_strings() {
|
||||
use crate::agent::config::EnvKeys;
|
||||
|
||||
Reference in New Issue
Block a user