pub trait LLMProvider: Send + Sync {
Show 30 methods
// Required methods
fn name(&self) -> &str;
fn generate<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMResponse, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn supported_models(&self) -> Vec<String>;
fn validate_request(&self, request: &LLMRequest) -> Result<(), LLMError>;
// Provided methods
fn backend_kind(&self) -> BackendKind { ... }
fn supports_streaming(&self) -> bool { ... }
fn supports_non_streaming(&self, _model: &str) -> bool { ... }
fn supports_reasoning(&self, _model: &str) -> bool { ... }
fn supports_reasoning_effort(&self, _model: &str) -> bool { ... }
fn supported_reasoning_efforts(
&self,
model: &str,
) -> &'static [&'static str] { ... }
fn sampling_overrides(&self, _model: &str) -> SamplingOverrides { ... }
fn supports_tools(&self, _model: &str) -> bool { ... }
fn supports_parallel_tool_config(&self, _model: &str) -> bool { ... }
fn supports_structured_output(&self, _model: &str) -> bool { ... }
fn supports_context_caching(&self, _model: &str) -> bool { ... }
fn supports_vision(&self, _model: &str) -> bool { ... }
fn supports_responses_compaction(&self, _model: &str) -> bool { ... }
fn supports_native_allowed_tools(&self, _model: &str) -> bool { ... }
fn supports_context_edits(&self, _model: &str) -> bool { ... }
fn supports_turn_scoped_system_messages(&self, _model: &str) -> bool { ... }
fn supports_manual_openai_compaction(&self, _model: &str) -> bool { ... }
fn supports_native_inline_compaction(&self, _model: &str) -> bool { ... }
fn manual_openai_compaction_unavailable_message(
&self,
model: &str,
) -> String { ... }
fn effective_context_size(&self, model: &str) -> usize { ... }
fn compact_history<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_model: &'life1 str,
_history: &'life2 [Message],
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn compact_history_with_options<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_model: &'life1 str,
_history: &'life2 [Message],
_options: &'life3 ResponsesCompactionOptions,
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
fn stream<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMStream, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn stream_normalized<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMNormalizedStream, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn start_copilot_prompt_session<'a>(
&'a self,
_request: LLMRequest,
_tools: &'a [ToolDefinition],
) -> Option<CopilotPromptSessionFuture<'a>> { ... }
fn get_balance<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<BalanceInfo>, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Universal LLM provider trait
Required Methods§
Sourcefn generate<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMResponse, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn generate<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMResponse, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Generate completion
Sourcefn supported_models(&self) -> Vec<String>
fn supported_models(&self) -> Vec<String>
Get supported models
Sourcefn validate_request(&self, request: &LLMRequest) -> Result<(), LLMError>
fn validate_request(&self, request: &LLMRequest) -> Result<(), LLMError>
Validate request for this provider
Provided Methods§
Sourcefn backend_kind(&self) -> BackendKind
fn backend_kind(&self) -> BackendKind
The canonical backend kind for this provider.
Defaults to matching on name() against the
well-known provider names. Providers should override this when their
name does not match the canonical mapping (e.g., dynamic names).
Sourcefn supports_streaming(&self) -> bool
fn supports_streaming(&self) -> bool
Whether the provider has native streaming support
Sourcefn supports_non_streaming(&self, _model: &str) -> bool
fn supports_non_streaming(&self, _model: &str) -> bool
Whether the provider can service non-streaming generation requests for the model.
Sourcefn supports_reasoning(&self, _model: &str) -> bool
fn supports_reasoning(&self, _model: &str) -> bool
Whether the provider surfaces structured reasoning traces for the given model
Sourcefn supports_reasoning_effort(&self, _model: &str) -> bool
fn supports_reasoning_effort(&self, _model: &str) -> bool
Whether the provider accepts configurable reasoning effort for the model
Sourcefn supported_reasoning_efforts(&self, model: &str) -> &'static [&'static str]
fn supported_reasoning_efforts(&self, model: &str) -> &'static [&'static str]
Exact levels accepted by this route; providers may override catalog metadata.
Sourcefn sampling_overrides(&self, _model: &str) -> SamplingOverrides
fn sampling_overrides(&self, _model: &str) -> SamplingOverrides
Provider/model-specific sampling parameter overrides.
Custom-provider profiles may pin exact sampling values per model; every
field defaults to None, meaning the agent loop’s global config value
applies unchanged.
Sourcefn supports_tools(&self, _model: &str) -> bool
fn supports_tools(&self, _model: &str) -> bool
Whether the provider supports structured tool calling for the given model
Sourcefn supports_parallel_tool_config(&self, _model: &str) -> bool
fn supports_parallel_tool_config(&self, _model: &str) -> bool
Whether the provider understands parallel tool configuration payloads
Sourcefn supports_structured_output(&self, _model: &str) -> bool
fn supports_structured_output(&self, _model: &str) -> bool
Whether the provider supports structured output (JSON schema guarantees)
Sourcefn supports_context_caching(&self, _model: &str) -> bool
fn supports_context_caching(&self, _model: &str) -> bool
Whether the provider supports prompt/context caching
Sourcefn supports_vision(&self, _model: &str) -> bool
fn supports_vision(&self, _model: &str) -> bool
Whether the provider supports vision (image analysis) for given model
Sourcefn supports_responses_compaction(&self, _model: &str) -> bool
fn supports_responses_compaction(&self, _model: &str) -> bool
Whether the provider supports Responses API server-side compaction.
Sourcefn supports_native_allowed_tools(&self, _model: &str) -> bool
fn supports_native_allowed_tools(&self, _model: &str) -> bool
Whether the request path can enforce a provider-native allowed_tools subset.
Sourcefn supports_context_edits(&self, _model: &str) -> bool
fn supports_context_edits(&self, _model: &str) -> bool
Whether the provider supports provider-native context editing such as tool-result clearing.
Sourcefn supports_turn_scoped_system_messages(&self, _model: &str) -> bool
fn supports_turn_scoped_system_messages(&self, _model: &str) -> bool
Whether the selected provider/model can carry Anthropic’s native turn-scoped system-message lifecycle field on the wire.
This is intentionally narrower than Self::supports_context_edits: a
provider can expose Anthropic-shaped requests without supporting the
clear_at field, and a provider name does not necessarily identify the
wire protocol for every model. The runtime keeps the typed marker in
canonical history either way, translating it to an ordinary system or
history directive when this capability is false.
Sourcefn supports_manual_openai_compaction(&self, _model: &str) -> bool
fn supports_manual_openai_compaction(&self, _model: &str) -> bool
Whether the provider supports the interactive manual /compact command path.
This is narrower than general Responses compaction support and may exclude compatible endpoints that do not match VT Code’s native OpenAI UX contract.
Sourcefn supports_native_inline_compaction(&self, _model: &str) -> bool
fn supports_native_inline_compaction(&self, _model: &str) -> bool
Whether the provider supports threshold-triggered inline compaction via
request fields (Anthropic compact_20260112).
This is distinct from supports_responses_compaction,
which is overloaded: OpenAI-compatible endpoints report it for their
standalone /responses/compact endpoint while Anthropic reports it for
inline compaction. Only the latter can be driven through generate with a
compact_20260112 context-management edit, so the unified compaction
dispatch uses this method (not the overloaded flag) to pick the
NativeInline strategy and avoid sending an Anthropic-specific payload to
an OpenAI-compatible endpoint (which would only be rejected and fall back
to local summarization anyway).
Explain why the --native-only manual /compact path is unavailable.
This message only surfaces when the user explicitly passes --native-only
and the provider does not expose a native server-side compaction endpoint.
The plain /compact command is provider-agnostic and always falls back to
local summarization, so it is never refused on capability grounds.
Sourcefn effective_context_size(&self, model: &str) -> usize
fn effective_context_size(&self, model: &str) -> usize
Get the effective context window size for a model.
Curated catalog capacity is the default for providers that do not have a narrower route-specific limit. Adapters with an explicit endpoint ceiling can still override this method and keep that ceiling intact.
Sourcefn compact_history<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_model: &'life1 str,
_history: &'life2 [Message],
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn compact_history<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_model: &'life1 str,
_history: &'life2 [Message],
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Compact conversation history using provider-native Responses /compact
support when available.
Sourcefn compact_history_with_options<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_model: &'life1 str,
_history: &'life2 [Message],
_options: &'life3 ResponsesCompactionOptions,
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn compact_history_with_options<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_model: &'life1 str,
_history: &'life2 [Message],
_options: &'life3 ResponsesCompactionOptions,
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Compact conversation history with standalone Responses compaction options.
Sourcefn stream<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMStream, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMStream, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream completion (optional)
Sourcefn stream_normalized<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMNormalizedStream, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream_normalized<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMNormalizedStream, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Normalized streaming contract layered on top of the legacy provider stream.
Sourcefn start_copilot_prompt_session<'a>(
&'a self,
_request: LLMRequest,
_tools: &'a [ToolDefinition],
) -> Option<CopilotPromptSessionFuture<'a>>
fn start_copilot_prompt_session<'a>( &'a self, _request: LLMRequest, _tools: &'a [ToolDefinition], ) -> Option<CopilotPromptSessionFuture<'a>>
Provider-specific streaming path that can service interactive runtime requests while the stream is active. Copilot uses this to bridge ACP tool calls and permission prompts back into VT Code’s turn runtime.
Sourcefn get_balance<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<BalanceInfo>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_balance<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<BalanceInfo>, LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Fetch account balance for this provider, if supported.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl LLMProvider for AnthropicProvider
impl LLMProvider for ContextWindowProvider
impl LLMProvider for CopilotProvider
impl LLMProvider for CustomProviderBackendRouter
impl LLMProvider for DeepSeekProvider
impl LLMProvider for EvolinkProvider
impl LLMProvider for GeminiProvider
impl LLMProvider for HuggingFaceProvider
impl LLMProvider for LlamaCppProvider
impl LLMProvider for LmStudioProvider
impl LLMProvider for MergeGatewayProvider
Stable opaque session identity for Merge Gateway cache-aware routing.