Skip to main content

Module llm

Module llm 

Source
Expand description

LLM wire types — request / response structures and the LlmProvider trait.

This module defines everything needed to communicate with an LLM backend: the provider trait, completion requests and responses, streaming events, model capabilities, and multimodal support (audio, images, video).

§Key types

TypeRole
LlmProviderTrait implemented by each LLM backend (OpenRouter, Anthropic, Ollama…)
CompletionRequestSingle completion request sent to a provider
CompletionResponseNon-streaming response wrapper
StreamEventIncremental events from the provider’s stream
CompletionStreamAlias for Pin<Box<dyn Stream<Item = Result<StreamEvent>>>>
FinishReasonWhy generation stopped (stop, length, tool_calls, content_filter)
ToolDefinitionOpenAI-compatible JSON schema for tool calling
ModelCapabilitiesFeature flags (tool_calling, images, reasoning, audio…)
TokenUsageToken consumption reported by the provider
ModalityOutput modality: text, audio, or image
TtsRequest, SttRequest, VideoGenRequestMultimodal operation requests

Structs§

AudioOutputConfig
Configuration for audio output in multimodal completions.
CompletionRequest
A single completion request sent to an LLM provider.
CompletionResponse
Non-streaming completion response wrapper.
FrameImage
An image used as a frame reference in video generation.
ImageEditRequest
Parameters for editing one or more images.
ImageGenConfig
Configuration for image generation requests.
ImageGenRequest
Parameters for generating an image via a generative model.
ImageModelCapabilities
Image capability metadata, when provided in a model catalog.
ModelCapabilities
Feature flags describing what a model supports.
ModelInfo
Metadata about an available LLM model, including capabilities, pricing, and context window.
ModelPricing
Pricing information for a model, including input/output token costs and caching discounts.
NativeCompaction
A provider-issued context window to replay without editing its contents.
ReferencePricing
Reference token rates from a separately identified source.
SttRequest
Parameters for a speech-to-text (transcription) request.
TokenUsage
Token usage counts for a single completion request or turn.
ToolDefinition
OpenAI-compatible JSON schema for a tool exposed to the LLM.
TtsRequest
Parameters for a text-to-speech request.
VideoGenRequest
Parameters for generating a video from text prompts or image frames.
Voice
A voice available for text-to-speech generation.

Enums§

AudioFormat
Output audio format for TTS responses.
FinishReason
Why the LLM stopped generating (used in stream and non-stream responses).
ImageOutputFormat
Image format requested from a provider.
Modality
Output modality requested in a completion.
ModelCategory
High-level category for filtering models by use-case.
ReferencePricingSource
Source of a model’s reference rates.
StreamEvent
Events emitted incrementally by the provider’s stream.

Traits§

LlmProvider
Trait implemented by each LLM backend (OpenRouter, Anthropic, Ollama, etc.).

Functions§

mime_from_extension
Infer MIME type from a file path’s extension.

Type Aliases§

CompletionStream
Type alias for a stream of completion events from an LLM provider.
ProviderRegistry
Shared registry mapping each crate::model::Provider to its concrete instance.