Skip to main content

KernelHttpGateway

Struct KernelHttpGateway 

Source
pub struct KernelHttpGateway<C: KernelGatewayConfig> { /* private fields */ }
Expand description

Generic kernel gateway: reqwest transport + the pure translation in causa_protocol::translation composed with the shared error mapping table and control-plane wiring from crate::gateway_transport.

Media: an optional host-injected MediaResolver turns the frame’s fact-level references into inline payloads right before rendering — batch and stream share one resolution pass. Without a resolver, every reference degrades to its text placeholder.

Implementations§

Source§

impl<C: KernelGatewayConfig> KernelHttpGateway<C>

Source

pub fn new(api_key: impl Into<String>) -> Self

Build a gateway with the protocol’s default endpoint and configuration. Media resolution is absent until the host injects a resolver.

Source

pub fn with_base_url(self, base_url: impl Into<String>) -> Self

Point at a non-default host (test doubles, gateways). C::PATH is appended to the given base URL, which must carry its own version segment: https://api.anthropic.com/v1, https://api.openai.com/v1, or https://host/provider/v1 for a compatible provider. A base without a version segment is used as given.

Source

pub fn with_endpoint(self, endpoint: impl Into<String>) -> Self

Full endpoint override (host + path).

Source

pub fn with_http_client(self, http: Client) -> Self

Replace the HTTP client with one configured by the host.

The default client disables redirects and retries, and configures a connect timeout and idle read timeout without a total timeout. A supplied client’s transport policies remain host-owned: disable both for the same single-request guarantee. Note that a supplied client configured with its own .timeout(...) reintroduces a total request cap that cuts off long streaming or generation turns; total duration belongs to the CallControl deadline instead. Cancellation and deadlines remain enforced independently of the supplied client’s timeout settings.

Source

pub fn with_media_resolver(self, resolver: Arc<dyn MediaResolver>) -> Self

Inject the media resolver: the host’s asset table the gateway consults for every media reference in the frame.

Source

pub fn with_max_inline_media_bytes( self, kind: MediaKind, max_bytes: usize, ) -> Self

Override the inline media ceiling for one MediaKind, in decoded bytes. Each kind defaults to 5 MiB.

The ceiling constrains inline payloads only (MediaSource::Inline); remote URLs (MediaSource::Url) are neither limited nor fetched. An inline payload over its kind’s ceiling renders as the placeholder, like a resolver miss. The total size of a request is not checked; that is the provider’s limit.

Source

pub fn with_stream_limits(self, limits: StreamLimits) -> Self

Override the pure decoder’s framing, total-input, output and item budgets. Invalid limits are rejected before sending a streaming request.

Source§

impl KernelHttpGateway<AnthropicGatewayConfig>

Source

pub fn with_anthropic_version(self, version: impl Into<String>) -> Self

Override the anthropic-version header (default 2023-06-01).

Source

pub fn with_beta(self, value: impl Into<String>) -> Self

Append one extra anthropic-beta value for this gateway. Values are sent as one comma-separated anthropic-beta header, in the order listed, followed by the value an enabled option needs; nothing is sent by default and no model table decides headers.

Source

pub fn with_render_options(self, options: AnthropicRenderOptions) -> Self

Replace every render option at once, including any set earlier with the per-option setters (a later call wins either way). Wire consequences follow from the options: native_tool_changes still adds inline-tools-2026-09-15 to anthropic-beta. The value usually comes from host configuration, as which servers and models support an option is the host’s to decide.

Source

pub fn with_native_tool_changes(self, native: bool) -> Self

Render tool changes in place (default false).

tools stays at the context’s first tool change and each later change is sent at its position as tool_removal / tool_addition blocks, so a changed tool listing keeps the cached prefix and earlier thinking. The gateway adds the inline-tools-2026-09-15 beta value it needs. Off, every request carries the current tools in tools. Enable only for a server known to support it: a server without support may reject the request, or ignore the change so the model never sees the added tool.

Source§

impl KernelHttpGateway<OpenAiChatGatewayConfig>

Source

pub fn with_render_options(self, options: ChatRenderOptions) -> Self

Replace every render option at once, including any set earlier with the per-option setters (a later call wins either way). Wire consequences follow from the options. The value usually comes from host configuration, as which servers and models support an option is the host’s to decide.

Source

pub fn with_reasoning_content_replay(self, replay: bool) -> Self

Replay sealed reasoning_content message-level items (default true).

DeepSeek requires reasoning_content back on every request that carries tools; turning this off removes the key from the renderer’s own sealed items and changes nothing else. The choice is per gateway value, not per request: a host that needs both holds two gateways.

Source

pub fn with_max_tokens_field(self, field: ChatMaxTokensField) -> Self

Choose the request field that carries the output limit (default ChatMaxTokensField::MaxCompletionTokens).

Only the chosen field is sent. ChatMaxTokensField::MaxTokens is for a server that reads only the older max_tokens; a server that does not read the chosen field applies no limit and reports no error. The choice is per gateway value, not per request.

Source§

impl KernelHttpGateway<OpenAiResponsesGatewayConfig>

Source

pub fn with_render_options(self, options: ResponsesRenderOptions) -> Self

Replace every render option at once, including any set earlier with the per-option setters (a later call wins either way). Wire consequences follow from the options. The value usually comes from host configuration, as which servers and models support an option is the host’s to decide.

Source

pub fn with_encrypted_reasoning(self, include: bool) -> Self

Send include: ["reasoning.encrypted_content"] (default true).

Without it a reasoning item cannot be meaningfully replayed under store: false or zero data retention. The choice is per gateway value, not per request: a host that needs both holds two gateways.

Source

pub fn with_store(self, store: Option<bool>) -> Self

Render store; None omits the field (default Some(false), as Codex and pi-ai send it). The host owns the data-retention choice. The choice is per gateway value, not per request.

Source

pub fn with_additional_tools(self, additional_tools: bool) -> Self

Send added tools as additional_tools input items (default false).

tools stays at the context’s first tool change and each later addition is sent at its position, as Codex does, so the cached prefix survives it. A context in which a later change removes a tool or redefines one renders with the current tools in tools, as with this off. Enable only for a server known to support it: a server without support may reject the request, or ignore the change so the model never sees the added tool.

Trait Implementations§

Source§

impl<C: KernelGatewayConfig> Clone for KernelHttpGateway<C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: KernelGatewayConfig> Debug for KernelHttpGateway<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: KernelGatewayConfig> ModelGateway for KernelHttpGateway<C>

Source§

fn stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 ModelRequest, control: &'life2 CallControl, ) -> Pin<Box<dyn Future<Output = Result<ModelStream, ModelInvokeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Streams one logical output. Once any delta has been yielded, transparent retries are prohibited. The final Done alone supplies material for submission. Default implementation: degenerates to a single StreamDelta::Done after invoke — providers that never implemented streaming keep working through the same port; streaming providers override to expose real token increments.
Source§

fn invoke<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 ModelRequest, control: &'life2 CallControl, ) -> Pin<Box<dyn Future<Output = Result<ModelOutput, ModelInvokeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Runs one logical invocation, returning the assembled ModelOutput, or a classified ModelInvokeError. Cancellation and the deadline arrive through control.

Auto Trait Implementations§

§

impl<C> !RefUnwindSafe for KernelHttpGateway<C>

§

impl<C> !UnwindSafe for KernelHttpGateway<C>

§

impl<C> Forget for KernelHttpGateway<C>

§

impl<C> Freeze for KernelHttpGateway<C>
where C: Freeze,

§

impl<C> Move for KernelHttpGateway<C>

§

impl<C> Send for KernelHttpGateway<C>

§

impl<C> Sync for KernelHttpGateway<C>

§

impl<C> Unpin for KernelHttpGateway<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for KernelHttpGateway<C>
where C: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more