mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Preserve Guardian request metadata with custom OpenAI base URLs (#57439)
## Why Custom OpenAI base URLs caused Codex backend authentication to lose Responses headers and Guardian metadata when the URL did not match a recognized backend route. ## What changed Apply model-scoped Responses headers, Guardian reviewer and classifier markers, and eligible ChatGPT parent credit requests based on the OpenAI provider and authentication configuration, regardless of the base URL. Keep API-key requests and other providers excluded from this behavior. ## Testing Extend coverage for custom `/v1` URLs and direct `/api/codex` endpoints with ChatGPT, header-based, and API-key authentication, including HTTP fallback and WebSocket requests. GitOrigin-RevId: cc4bb5b4a1a6596904ecf8965237c7a4f09e112b
This commit is contained in:
@@ -1337,11 +1337,7 @@ impl ModelClient {
|
||||
fn responses_headers(&self, auth: Option<&CodexAuth>, model: &str) -> ApiHeaderMap {
|
||||
self.codex_responses_headers
|
||||
.as_ref()
|
||||
.filter(|config| {
|
||||
config.model == model
|
||||
&& self.uses_codex_backend(auth)
|
||||
&& self.state.provider.info().supports_codex_backend_routes()
|
||||
})
|
||||
.filter(|config| config.model == model && self.uses_codex_backend(auth))
|
||||
.map(|config| config.headers.clone())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
@@ -1382,7 +1378,6 @@ impl ModelClient {
|
||||
Some(CodexAuth::Chatgpt(_) | CodexAuth::ChatgptAuthTokens(_))
|
||||
)
|
||||
&& self.uses_codex_backend(auth)
|
||||
&& self.state.provider.info().supports_codex_backend_routes()
|
||||
{
|
||||
metadata
|
||||
.get_or_insert_with(HashMap::new)
|
||||
|
||||
@@ -2097,7 +2097,7 @@ fn thread_responses_headers_are_scoped_to_model_and_backend_auth() {
|
||||
let chatgpt_auth = CodexAuth::create_dummy_chatgpt_auth_for_testing();
|
||||
let api_key_auth = CodexAuth::from_api_key("test-api-key");
|
||||
for (auth, model, expected) in [
|
||||
(Some(&chatgpt_auth), "selected-model", headers),
|
||||
(Some(&chatgpt_auth), "selected-model", headers.clone()),
|
||||
(Some(&chatgpt_auth), "other-model", http::HeaderMap::new()),
|
||||
(
|
||||
Some(&api_key_auth),
|
||||
@@ -2117,7 +2117,7 @@ fn thread_responses_headers_are_scoped_to_model_and_backend_auth() {
|
||||
);
|
||||
assert_eq!(
|
||||
model_client.responses_headers(Some(&chatgpt_auth), "selected-model"),
|
||||
http::HeaderMap::new(),
|
||||
headers,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,10 @@ use http::HeaderMap;
|
||||
|
||||
/// Seed in `StartThreadOptions::thread_extension_init` to supply Responses headers.
|
||||
///
|
||||
/// Applied only to the selected model with Codex backend auth and routing. The headers
|
||||
/// are sent on HTTP requests and WebSocket handshakes; changes require a new socket.
|
||||
/// Other provider endpoints and unrelated threads do not inherit these headers.
|
||||
/// Applied only to the selected model on the OpenAI provider with Codex backend
|
||||
/// auth, regardless of the base URL. The headers are sent on HTTP requests and
|
||||
/// WebSocket handshakes; changes require a new socket. Other providers and
|
||||
/// unrelated threads do not inherit these headers.
|
||||
#[derive(Clone)]
|
||||
pub struct CodexResponsesHeaders {
|
||||
pub model: String,
|
||||
|
||||
Reference in New Issue
Block a user