Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/src/content/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,30 @@ Proxy URLs may use `http`, `https`, `socks4`, `socks4a`, `socks5`, or `socks5h`.
`CCP_USER_AGENT` is the fallback when a Codex or Kimi provider-specific user-agent is absent. Prefer `CCP_CODEX_USER_AGENT` or `CCP_KIMI_USER_AGENT` in durable configuration.

Endpoint and client identity overrides can break provider compatibility. Use defaults unless a controlled integration or focused diagnostic requires an override.

## Claude model overrides

Map exact Claude model IDs to Codex model IDs in `config.json`:

```json
{
"modelOverrides": {
"claude-fable-5-2": "gpt-6-astra",
"claude-opus-5-5": "gpt-6.1-sol",
"claude-sonnet-5-5": "gpt-6.1-terra",
"claude-haiku-5-5": "gpt-6-luna"
}
}
```

Keys must start with `claude-` and match exactly after the existing `[1m]`
normalization. Explicit mappings route to Codex even with Kimi alias/session
routing, and take precedence over `codex.model` / `CCP_CODEX_MODEL`.
Unmapped requests retain existing behavior. Fable 5.2 defaults to GPT-6 Astra
when routed to Codex. Mappings also apply to Chat Completions and native Responses.
Targets must be registered Codex IDs (built-in or API-supported local Codex
catalog entries); supported `-fast` / `-ultrafast` suffixes work as usual.
Mappings are not recursive. Empty or unsupported targets return HTTP 400;
unknown unmapped IDs remain rejected. Non-Claude keys are ignored.
New Claude IDs need only a configuration entry. Backend account access is still
required; recognizing an ID locally does not grant access to that model.
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct FileConfig {
pub alias_provider: Option<String>,
#[serde(rename = "autoReviewModel")]
pub auto_review_model: Option<String>,
#[serde(default, rename = "modelOverrides")]
pub model_overrides: HashMap<String, String>,
pub log: Option<FileLog>,
pub kimi: Option<KimiConfig>,
pub codex: Option<CodexConfig>,
Expand Down Expand Up @@ -873,6 +875,17 @@ pub fn codex_reasoning_summary() -> Option<String> {
None
}

/// Exact Claude ID aliases to Codex targets; unknown targets are rejected by
/// the provider allowlist. Do not recursively resolve user mappings.
pub fn model_override(model: &str) -> Option<String> {
if !model.starts_with("claude-") {
return None;
}
read_file_config(&paths::config_dir())?
.model_overrides
.remove(model)
}

pub fn codex_model() -> Option<String> {
let env: HashMap<_, _> = std::env::vars().collect();
if let Some(raw) = env.get("CCP_CODEX_MODEL") {
Expand Down
8 changes: 8 additions & 0 deletions src/providers/codex/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ fn shape_native_request(body: &mut Value, full_lane: bool) -> Result<NativeResol
}

fn resolve_native_model(requested: &str) -> (String, Option<ServiceTier>) {
let normalized = crate::registry::normalize_incoming_model(requested);
let requested = normalized.as_str();
if let Some(target) = config::model_override(requested) {
return match split_tier_suffix(&target) {
Some((base, tier)) => (base.to_string(), Some(tier)),
None => (target, None),
};
}
let (requested, service_tier) = match split_tier_suffix(requested) {
Some((base, tier)) => (base, Some(tier)),
None => (requested, None),
Expand Down
15 changes: 15 additions & 0 deletions src/providers/codex/translate/model_allowlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub const MODEL_ALIASES: &[(&str, &str)] = &[
("claude-opus-5-5", "gpt-6-sol"),
("fable", "gpt-6-sol"),
("claude-fable-5", "gpt-6-sol"),
("claude-fable-5-2", "gpt-6-astra"),
];

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -140,6 +141,9 @@ pub fn resolve_model_request_with_config_override(
model: &str,
apply_config_override: bool,
) -> ResolvedModel {
if let Some(target) = config::model_override(model) {
return resolve_tier_model_alias(&target);
}
let override_model = apply_config_override.then(config::codex_model).flatten();
resolve_with_model_override(model, override_model.as_deref())
}
Expand Down Expand Up @@ -257,6 +261,17 @@ pub fn is_valid_model_for_codex(model: &str) -> bool {
mod tests {
use super::*;

#[test]
fn fable_52_and_unknown_models() {
assert_eq!(
resolve_with_model_override("claude-fable-5-2", None).model,
"gpt-6-astra"
);
assert!(is_valid_model_for_codex("claude-fable-5-2"));
let unknown = resolve_with_model_override("claude-unknown", None);
assert!(assert_allowed_model(&unknown.model).is_err());
}

#[test]
fn haiku_resolves_to_luna() {
let r = resolve_model_request("haiku");
Expand Down
4 changes: 4 additions & 0 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub const ANTHROPIC_STYLE_ALIASES: &[&str] = &[
"claude-opus-5-5",
"fable",
"claude-fable-5",
"claude-fable-5-2",
];

pub const CURSOR_PREFIXES: &[&str] = &["cursor:", "cursor-plan:", "cursor-ask:"];
Expand Down Expand Up @@ -183,6 +184,9 @@ impl Registry {
session_affinity: Option<&AliasProvider>,
) -> Option<Arc<dyn Provider>> {
let normalized = normalize_incoming_model(raw_model);
if crate::config::model_override(&normalized).is_some() {
return self.handlers.get("codex").cloned();
}
if is_anthropic_alias(&normalized) {
let target = session_affinity.unwrap_or(&self.alias_provider);
return self.handlers.get(target.as_str()).cloned();
Expand Down
107 changes: 94 additions & 13 deletions tests/codex_model_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,22 @@ async fn catalog_drives_discovery_routing_tiers_and_lanes_in_actual_process() {
let reservation = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
let port = reservation.local_addr().unwrap().port();
drop(reservation);
let mut proxy = Proxy(
command(&dir)
.args(["serve", "--no-monitor", "--port", &port.to_string()])
.env(
"CCP_CODEX_BASE_URL",
format!("http://{upstream_addr}/responses"),
)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.unwrap(),
);
let spawn_proxy = || {
Proxy(
command(&dir)
.args(["serve", "--no-monitor", "--port", &port.to_string()])
.env(
"CCP_CODEX_BASE_URL",
format!("http://{upstream_addr}/responses"),
)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.unwrap(),
)
};
let mut proxy = spawn_proxy();
let client = reqwest::Client::builder()
.no_proxy()
.timeout(Duration::from_secs(5))
Expand Down Expand Up @@ -215,6 +218,84 @@ async fn catalog_drives_discovery_routing_tiers_and_lanes_in_actual_process() {
assert!(headers.contains_key("x-openai-internal-codex-responses-lite"));
assert!(body.get("client_metadata").is_some());
}
// Exact Claude overrides select Codex despite Kimi routing and the global
// model setting, and retain the target tier/lane across all API adapters.
std::fs::write(
dir.path().join("config.json"),
json!({"aliasProvider":"kimi", "codex":{"model":"gpt-5.4"},
"modelOverrides":{
"claude-fable-5-2":"gpt-6-astra-ultrafast",
"claude-future-test":"gpt-test-future-fast",
"claude-opus-5-5":"gpt-6.1-sol",
"claude-sonnet-5-5":"gpt-6.1-terra",
"claude-haiku-5-5":"gpt-6-luna",
"claude-invalid":"gpt-nonexistent",
"claude-empty":"",
"claude-chain":"claude-fable-5-2"
}})
.to_string(),
)
.unwrap();
// aliasProvider is loaded at startup, so restart after changing it.
proxy.0.kill().unwrap();
proxy.0.wait().unwrap();
proxy = spawn_proxy();
let mut ready = false;
for _ in 0..150 {
assert!(proxy.0.try_wait().unwrap().is_none(), "proxy exited");
if client.get(format!("{url}/healthz")).send().await.is_ok() {
ready = true;
break;
}
tokio::time::sleep(Duration::from_millis(50)).await;
}
assert!(ready, "proxy did not restart");
for (requested, target, tier) in [
("claude-fable-5-2[1m]", "gpt-6-astra", Some("ultrafast")),
("claude-future-test", "gpt-test-future", Some("priority")),
("claude-opus-5-5", "gpt-6.1-sol", None),
("claude-sonnet-5-5", "gpt-6.1-terra", None),
("claude-haiku-5-5", "gpt-6-luna", None),
] {
for route in ["/v1/messages", "/v1/chat/completions", "/v1/responses"] {
let mut request = if route == "/v1/responses" {
json!({"model":requested,"input":"synthetic"})
} else {
json!({"model":requested,"max_tokens":64,"messages":[{"role":"user","content":"synthetic"}]})
};
if route == "/v1/chat/completions" {
request.as_object_mut().unwrap().remove("max_tokens");
}
let response = client
.post(format!("{url}{route}"))
.json(&request)
.send()
.await
.unwrap();
let status = response.status();
let text = response.text().await.unwrap();
assert!(status.is_success(), "{requested} {route}: {status} {text}");
let (headers, body) = tokio::time::timeout(Duration::from_secs(5), rx.recv())
.await
.unwrap()
.unwrap();
assert_eq!(body["model"], target);
assert_eq!(body.get("service_tier").and_then(Value::as_str), tier);
assert!(headers.contains_key("x-openai-internal-codex-responses-lite"));
}
}
for model in [
"claude-invalid",
"claude-empty",
"claude-chain",
"claude-unknown",
] {
let response = client.post(format!("{url}/v1/messages"))
.json(&json!({"model":model,"max_tokens":64,"messages":[{"role":"user","content":"synthetic"}]}))
.send().await.unwrap();
assert_eq!(response.status(), 400, "{model}");
assert!(rx.try_recv().is_err(), "invalid model reached upstream");
}
for full_lane in [false, true] {
std::fs::write(
dir.path().join("config.json"),
Expand Down