Add Cerebras platform + generalize StrictOpenAi dialect (provider 10)

The 13th registry row: id "cerebras", CEREBRAS_API_KEY > auth.json
"cerebras" scope, https://api.cerebras.ai/v1 with KIGI_CEREBRAS_BASE_URL
override, Bearer, ChatCompletions, enrichment-backed metadata
(models_dev_id cerebras).

Cerebras' catalog is all chat LLMs (no embedding/tts pollution) and its
/models is minimal (ids only), so restrict_to_enriched=FALSE: keep every
live model, enrich the known ones (context + effort menus low/medium/high),
unknown ones keep the default context. The e2e pins this enrich-without-
restrict path (new — prior enrichment providers all used restrict=true).

Review caught a likely-DOA defect: Cerebras uses strict
additionalProperties:false validation (confirmed 400-rejecting store,
maxTokens, thinking, nested reasoning_content), and stream_options is not
in its schema — so Passthrough (which keeps the stream_options.include_usage
kigi injects on every streaming request) would very likely 400 all
streaming. Generalized ChatCompat::Mistral -> ChatCompat::StrictOpenAi
(serde alias "mistral" keeps pre-rename persisted sessions loading), which
strips stream_options + private fields for any strict OpenAI-compat
validator; both Mistral and Cerebras now map to it. Future strict-validator
candidates (NVIDIA/Azure/Xiaomi/OpenCode) noted for the same check.

reasoning_effort (incl. "none") passes through; /v1/models requires auth
so key validation works; console cloud.cerebras.ai.
This commit is contained in:
2026-07-21 14:04:34 -04:00
parent 0a147bd8a5
commit f825132983
7 changed files with 205 additions and 23 deletions
@@ -1304,8 +1304,8 @@ mod tests {
let cfg = crate::agent::config::sampling_config_for_model(&model_entry, creds, None);
assert_eq!(
cfg.chat_compat,
kigi_sampling_types::ChatCompat::Mistral,
"mistral entries must map to the Mistral dialect (stream_options strip)"
kigi_sampling_types::ChatCompat::StrictOpenAi,
"mistral entries use the StrictOpenAi dialect (stream_options strip)"
);
}
@@ -1695,6 +1695,116 @@ mod tests {
);
}
/// Cerebras-cycle e2e: enrich WITHOUT restrict (the unpolluted-catalog
/// path). A minimal listing (bare ids, no context) → every live model is
/// kept; the enrichment-known one gains context + an effort menu, the
/// unknown one keeps the default context. Passthrough dialect.
#[tokio::test(flavor = "multi_thread")]
#[serial_test::serial]
async fn cerebras_enriches_without_restrict_keeping_all_models() {
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 cb-1"))
.respond_with(wiremock::ResponseTemplate::new(200).set_body_json(
// Minimal Cerebras listing: ids only, no context.
serde_json::json!({ "data": [
{ "id": "gpt-oss-120b", "object": "model" },
{ "id": "brand-new-cerebras-model", "object": "model" }
]}),
))
.expect(1)
.mount(&platform_server)
.await;
let modelsdev_server = wiremock::MockServer::start().await;
wiremock::Mock::given(wiremock::matchers::method("GET"))
.and(wiremock::matchers::path("/api.json"))
.respond_with(wiremock::ResponseTemplate::new(200).set_body_json(
serde_json::json!({ "cerebras": { "models": {
"gpt-oss-120b": {
"limit": {"context": 131072, "output": 40960},
"reasoning": true,
"reasoning_options": [
{"type": "effort", "values": ["low", "medium", "high"]}
],
"tool_call": true
}
}}}),
))
.expect(1)
.mount(&modelsdev_server)
.await;
let cache_dir = tempfile::tempdir().unwrap();
let _base = kigi_test_support::EnvGuard::set(
kigi_models::CEREBRAS_BASE_URL_ENV,
platform_server.uri(),
);
let _mdev = kigi_test_support::EnvGuard::set(
crate::agent::enrichment_fetch::MODELS_DEV_URL_ENV,
format!("{}/api.json", modelsdev_server.uri()),
);
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::Cerebras,
"cb-1",
);
let result = tokio::task::spawn_blocking(move || {
fetch_platform_models_blocking(&endpoints, None, &keys)
})
.await
.unwrap()
.expect("fetch must succeed");
// restrict=false → BOTH the known and the unknown model are kept.
assert_eq!(
result
.models
.iter()
.map(|m| m.id.as_deref().unwrap_or_default())
.collect::<Vec<_>>(),
vec!["cerebras/gpt-oss-120b", "cerebras/brand-new-cerebras-model"],
"enrich-without-restrict keeps every live model"
);
let known = &result.models[0];
assert_eq!(known.context_window.get(), 131_072, "known model enriched");
assert_eq!(known.max_completion_tokens, Some(40_960));
assert!(
known.supports_reasoning_effort,
"enrichment effort menu → selectable levels"
);
assert_eq!(
known
.reasoning_efforts
.iter()
.map(|o| o.id.as_str())
.collect::<Vec<_>>(),
vec!["low", "medium", "high"],
"effort menu comes from enrichment"
);
let unknown = &result.models[1];
assert_eq!(
unknown.context_window.get(),
DEFAULT_CONTEXT_WINDOW,
"an enrichment-unknown model keeps the default context (not dropped)"
);
let model_entry = crate::agent::config::ModelEntry::from_config_entry(known);
let creds = crate::agent::config::ResolvedCredentials {
api_key: Some("cb-1".into()),
base_url: known.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::StrictOpenAi,
"Cerebras uses the StrictOpenAi dialect (strict validator strips stream_options)"
);
}
#[test]
fn get_env_keys_parses_strings_and_rejects_non_strings() {
use crate::agent::config::EnvKeys;