mirror of
https://github.com/openai/codex.git
synced 2026-10-19 17:28:46 +00:00
core: route realtime and memories through HTTP client factory (#31362)
## Why `ModelClient` already carries the `HttpClientFactory` resolved from session configuration, but realtime call creation and memory summarization still constructed the legacy default client directly. Consequently, those first-party API requests could ignore `features.respect_system_proxy` even when Responses traffic honored it. These are the final direct default-client constructions in `core/src/client.rs`, so they form one small migration unit on top of #31361. ## What changed - Generalize `build_responses_transport` to `build_api_transport`. - Route realtime call creation through the helper using the selected provider and `/realtime/calls` destination. - Route `/memories/trace_summarize` through the same helper. - Remove the now-unused direct `build_reqwest_client` import. ## Review guide 1. The helper rename at the bottom of `core/src/client.rs` is mechanical and keeps existing Responses behavior unchanged. 2. The realtime call path computes the route from the final provider, including `api_provider_override`. 3. The memories path supplies its existing endpoint to the same API route class. ## Validation - `cargo check --tests -p codex-core` - `just fix -p codex-core` ## Follow-up Direct HTTP clients outside `ModelClient` remain separate migration slices. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/openai/codex/pull/31362). * #31637 * #31431 * #31363 * __->__ #31362
This commit is contained in:
@@ -70,7 +70,6 @@ use codex_login::CodexAuth;
|
||||
use codex_login::RefreshTokenError;
|
||||
use codex_login::UnauthorizedRecovery;
|
||||
use codex_login::default_client::build_default_reqwest_client_for_route;
|
||||
use codex_login::default_client::build_reqwest_client;
|
||||
use codex_otel::SessionTelemetry;
|
||||
use codex_otel::current_span_w3c_trace_context;
|
||||
use codex_protocol::auth::AuthMode;
|
||||
@@ -155,6 +154,7 @@ const WS_REQUEST_HEADER_RESPONSES_LITE_CLIENT_METADATA_KEY: &str =
|
||||
const RESPONSES_WEBSOCKETS_V2_BETA_HEADER_VALUE: &str = "responses_websockets=2026-02-06";
|
||||
const X_OPENAI_INTERNAL_CODEX_RESPONSES_LITE_HEADER: &str =
|
||||
"x-openai-internal-codex-responses-lite";
|
||||
const REALTIME_CALLS_ENDPOINT: &str = "/realtime/calls";
|
||||
const RESPONSES_ENDPOINT: &str = "/responses";
|
||||
const RESPONSES_COMPACT_ENDPOINT: &str = "/responses/compact";
|
||||
// `/responses/compact` is unary, so the timeout covers the full response rather than one idle
|
||||
@@ -549,7 +549,7 @@ impl ModelClient {
|
||||
}
|
||||
let client_setup = self.current_client_setup().await?;
|
||||
let transport =
|
||||
self.build_responses_transport(&client_setup.api_provider, RESPONSES_COMPACT_ENDPOINT)?;
|
||||
self.build_api_transport(&client_setup.api_provider, RESPONSES_COMPACT_ENDPOINT)?;
|
||||
let request_telemetry = Self::build_request_telemetry(
|
||||
session_telemetry,
|
||||
AuthRequestTelemetryContext::new(
|
||||
@@ -651,8 +651,8 @@ impl ModelClient {
|
||||
sideband_headers.extend(sideband_websocket_auth_headers(
|
||||
client_setup.api_auth.as_ref(),
|
||||
));
|
||||
let transport = ReqwestTransport::new(build_reqwest_client());
|
||||
let api_provider = api_provider_override.unwrap_or(client_setup.api_provider);
|
||||
let transport = self.build_api_transport(&api_provider, REALTIME_CALLS_ENDPOINT)?;
|
||||
let response = ApiRealtimeCallClient::new(transport, api_provider, client_setup.api_auth)
|
||||
.create_with_session_and_headers(sdp, session_config, extra_headers)
|
||||
.await
|
||||
@@ -682,7 +682,8 @@ impl ModelClient {
|
||||
}
|
||||
|
||||
let client_setup = self.current_client_setup().await?;
|
||||
let transport = ReqwestTransport::new(build_reqwest_client());
|
||||
let transport =
|
||||
self.build_api_transport(&client_setup.api_provider, MEMORIES_SUMMARIZE_ENDPOINT)?;
|
||||
let request_telemetry = Self::build_request_telemetry(
|
||||
session_telemetry,
|
||||
AuthRequestTelemetryContext::new(
|
||||
@@ -961,7 +962,7 @@ impl ModelClient {
|
||||
})
|
||||
}
|
||||
|
||||
fn build_responses_transport(
|
||||
fn build_api_transport(
|
||||
&self,
|
||||
api_provider: &ApiProvider,
|
||||
endpoint: &str,
|
||||
@@ -1413,7 +1414,7 @@ impl ModelClientSession {
|
||||
let client_setup = self.client.current_client_setup().await?;
|
||||
let transport = self
|
||||
.client
|
||||
.build_responses_transport(&client_setup.api_provider, RESPONSES_ENDPOINT)?;
|
||||
.build_api_transport(&client_setup.api_provider, RESPONSES_ENDPOINT)?;
|
||||
let request_auth_context = AuthRequestTelemetryContext::new(
|
||||
client_setup.auth.as_ref().map(CodexAuth::auth_mode),
|
||||
client_setup.api_auth.as_ref(),
|
||||
|
||||
Reference in New Issue
Block a user