pub trait ProtocolHandler: Send + Sync {
// Required methods
fn endpoint_path(&self) -> &str;
fn auth_headers(&self, api_key: &str) -> Vec<(String, String)>;
fn build_request_body(&self, req: &ApiRequest) -> Value;
fn parse_response(&self, body: &str) -> Result<ApiResponse, InferenceError>;
fn parse_stream_event(
&self,
event_type: &str,
data: &str,
) -> Vec<StreamEvent>;
fn build_messages(
&self,
messages: &[Message],
prompt: &str,
context: Option<&str>,
images: Option<&[ContentBlock]>,
) -> (Vec<Value>, Option<String>);
fn build_tools(&self, tools: &[Value]) -> Vec<Value>;
// Provided methods
fn supports_streaming(&self) -> bool { ... }
fn supports_thinking(&self) -> bool { ... }
fn supports_video(&self) -> bool { ... }
fn supports_audio(&self) -> bool { ... }
fn protocol_name(&self) -> &'static str { ... }
}Expand description
Protocol handler trait — each provider implements this.
Required Methods§
Sourcefn endpoint_path(&self) -> &str
fn endpoint_path(&self) -> &str
URL path for the API endpoint (appended to the base URL).
Sourcefn auth_headers(&self, api_key: &str) -> Vec<(String, String)>
fn auth_headers(&self, api_key: &str) -> Vec<(String, String)>
Build HTTP headers for authentication.
Sourcefn build_request_body(&self, req: &ApiRequest) -> Value
fn build_request_body(&self, req: &ApiRequest) -> Value
Build the JSON request body from unified ApiRequest.
Sourcefn parse_response(&self, body: &str) -> Result<ApiResponse, InferenceError>
fn parse_response(&self, body: &str) -> Result<ApiResponse, InferenceError>
Parse a complete (non-streaming) response body into ApiResponse.
Sourcefn parse_stream_event(&self, event_type: &str, data: &str) -> Vec<StreamEvent>
fn parse_stream_event(&self, event_type: &str, data: &str) -> Vec<StreamEvent>
Parse a single SSE line into StreamEvents (for streaming responses). Returns multiple events when a single SSE chunk contains multiple tool calls.
Sourcefn build_messages(
&self,
messages: &[Message],
prompt: &str,
context: Option<&str>,
images: Option<&[ContentBlock]>,
) -> (Vec<Value>, Option<String>)
fn build_messages( &self, messages: &[Message], prompt: &str, context: Option<&str>, images: Option<&[ContentBlock]>, ) -> (Vec<Value>, Option<String>)
Convert conversation Messages to this protocol’s message format.
Sourcefn build_tools(&self, tools: &[Value]) -> Vec<Value>
fn build_tools(&self, tools: &[Value]) -> Vec<Value>
Convert tool definitions to this protocol’s format.
Provided Methods§
Sourcefn supports_streaming(&self) -> bool
fn supports_streaming(&self) -> bool
Whether this protocol supports streaming.
Sourcefn supports_thinking(&self) -> bool
fn supports_thinking(&self) -> bool
Whether this protocol supports extended thinking.
Sourcefn supports_video(&self) -> bool
fn supports_video(&self) -> bool
Whether this protocol accepts video content blocks natively on
the generation endpoint. Defaults to false. When a request
carries a video block and the selected protocol returns
false, RemoteBackend::execute_request rejects the call
with InferenceError::UnsupportedMode rather than silently
downgrading the video to a text placeholder.
Sourcefn supports_audio(&self) -> bool
fn supports_audio(&self) -> bool
Whether this protocol accepts audio content blocks natively.
Same contract as [supports_video] — false means the remote
backend pre-check returns UnsupportedMode instead of
silently stringifying the audio reference.
Sourcefn protocol_name(&self) -> &'static str
fn protocol_name(&self) -> &'static str
Backend identifier used in UnsupportedMode error messages.
Handlers override to something recognizable (e.g. “openai”,
“anthropic-messages-v1”).