pub struct ModelClientSession { /* private fields */ }Expand description
A turn-scoped streaming session created from a ModelClient.
The session establishes a Responses WebSocket connection lazily and reuses it across multiple requests within the turn. It also caches per-turn state:
- The last full request, so subsequent calls can reuse incremental websocket request payloads only when the current request is an incremental extension of the previous one.
- The
x-codex-turn-statesticky-routing token, which must be replayed for all requests within the same turn.
Create a fresh ModelClientSession for each Codex turn. Reusing it across turns would replay
the previous turn’s sticky-routing token into the next turn, which violates the client/server
contract and can cause routing bugs.
Implementations§
Source§impl ModelClientSession
impl ModelClientSession
Sourcepub async fn preconnect_websocket(
&mut self,
session_telemetry: &SessionTelemetry,
responses_metadata: &CodexResponsesMetadata,
) -> Result<(), ApiError>
pub async fn preconnect_websocket( &mut self, session_telemetry: &SessionTelemetry, responses_metadata: &CodexResponsesMetadata, ) -> Result<(), ApiError>
Opportunistically preconnects a websocket for this turn-scoped client session.
This performs only connection setup; it never sends prompt payloads.
pub async fn prewarm_websocket( &mut self, prompt: &Prompt, model_info: &ModelInfo, session_telemetry: &SessionTelemetry, effort: Option<ReasoningEffortConfig>, summary: ReasoningSummaryConfig, service_tier: Option<String>, responses_metadata: &CodexResponsesMetadata, ) -> Result<()>
Sourcepub async fn stream(
&mut self,
prompt: &Prompt,
model_info: &ModelInfo,
session_telemetry: &SessionTelemetry,
effort: Option<ReasoningEffortConfig>,
summary: ReasoningSummaryConfig,
service_tier: Option<String>,
responses_metadata: &CodexResponsesMetadata,
inference_trace: &InferenceTraceContext,
) -> Result<ResponseStream>
pub async fn stream( &mut self, prompt: &Prompt, model_info: &ModelInfo, session_telemetry: &SessionTelemetry, effort: Option<ReasoningEffortConfig>, summary: ReasoningSummaryConfig, service_tier: Option<String>, responses_metadata: &CodexResponsesMetadata, inference_trace: &InferenceTraceContext, ) -> Result<ResponseStream>
Streams a single model request within the current turn.
The caller is responsible for passing per-turn settings explicitly (model selection, reasoning settings, telemetry context, and turn metadata). This method will prefer the Responses WebSocket transport when the provider supports it and it remains healthy, and will fall back to the HTTP Responses API transport otherwise. The trace context may be enabled or disabled, but is always explicit so transport paths do not need separate trace/no-trace branches.
Trait Implementations§
Source§impl Drop for ModelClientSession
impl Drop for ModelClientSession
Auto Trait Implementations§
impl !Freeze for ModelClientSession
impl !RefUnwindSafe for ModelClientSession
impl !UnwindSafe for ModelClientSession
impl Send for ModelClientSession
impl Sync for ModelClientSession
impl Unpin for ModelClientSession
impl UnsafeUnpin for ModelClientSession
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<T> AsTypeStaticRegistered for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
impl<T> HasTyVTable for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request