pub enum UserContent {
Text {
text: String,
},
ImageUrl {
image_url: ImageUrl,
},
File {
file: FileContent,
},
InputAudio {
input_audio: InputAudio,
},
VideoUrl {
video_url: VideoUrlContent,
},
}Expand description
User content types supported by OpenRouter.
OpenRouter uses different content type structures than OpenAI’s Chat Completions API, particularly for file/document, audio, and video content. This enum matches OpenRouter’s API specification.
§Supported Content Types
- Text: Plain text content
- ImageUrl: Images via URL or base64 data URI
- File: PDF documents and other files via URL or base64 data URI
- InputAudio: Base64-encoded audio files (supported formats vary by model)
- VideoUrl: Videos via URL or base64 data URI
§Example
use rig::providers::openrouter::UserContent;
// Text content
let text = UserContent::text("Hello, world!");
// Image from URL
let image = UserContent::image_url("https://example.com/image.png");
// PDF from URL
let pdf = UserContent::file_url("https://example.com/document.pdf", Some("document.pdf".to_string()));
// Audio from base64
use rig::completion::message::AudioMediaType;
let audio = UserContent::audio_base64("base64data", AudioMediaType::WAV);
// Video from URL
let video = UserContent::video_url("https://example.com/video.mp4");
// Video from base64
use rig::completion::message::VideoMediaType;
let video = UserContent::video_base64("base64data", VideoMediaType::MP4);Variants§
Text
Plain text content
ImageUrl
Image content (URL or base64 data URI)
Supports: image/png, image/jpeg, image/webp, image/gif
File
File content (for PDFs and other documents)
Uses file_data field which accepts either a publicly accessible URL
or base64-encoded content as a data URI.
Fields
file: FileContentInputAudio
Audio content (base64-encoded only; URLs are not supported for audio)
Supported formats vary by model.
Fields
input_audio: InputAudioVideoUrl
Video content (URL or base64 data URI)
Supports: video/mp4, video/mpeg, video/mov, video/webm. URL support varies by provider.
Fields
video_url: VideoUrlContentImplementations§
Source§impl UserContent
impl UserContent
Sourcepub fn image_url_with_detail(
url: impl Into<String>,
detail: ImageDetail,
) -> Self
pub fn image_url_with_detail( url: impl Into<String>, detail: ImageDetail, ) -> Self
Create image content from URL with detail level
Sourcepub fn image_base64(
data: impl Into<String>,
mime_type: &str,
detail: Option<ImageDetail>,
) -> Self
pub fn image_base64( data: impl Into<String>, mime_type: &str, detail: Option<ImageDetail>, ) -> Self
Create image content from base64 data
§Arguments
data- Base64-encoded image datamime_type- MIME type (e.g., “image/png”, “image/jpeg”)detail- Optional detail level for image processing
Sourcepub fn file_url(url: impl Into<String>, filename: Option<String>) -> Self
pub fn file_url(url: impl Into<String>, filename: Option<String>) -> Self
Create file content from URL
§Arguments
url- URL to the file (must be publicly accessible)filename- Optional filename for the document
Sourcepub fn file_base64(
data: impl Into<String>,
mime_type: &str,
filename: Option<String>,
) -> Self
pub fn file_base64( data: impl Into<String>, mime_type: &str, filename: Option<String>, ) -> Self
Create file content from base64 data
§Arguments
data- Base64-encoded file datamime_type- MIME type (e.g., “application/pdf”)filename- Optional filename for the document
Sourcepub fn audio_base64(data: impl Into<String>, format: AudioMediaType) -> Self
pub fn audio_base64(data: impl Into<String>, format: AudioMediaType) -> Self
Create audio content from base64-encoded data
OpenRouter only supports base64-encoded audio; direct URLs are not supported.
§Arguments
data- Base64-encoded audio dataformat- Audio format (e.g.,AudioMediaType::WAV,AudioMediaType::MP3)
Sourcepub fn video_url(url: impl Into<String>) -> Self
pub fn video_url(url: impl Into<String>) -> Self
Create video content from a URL
URL support varies by provider.
§Arguments
url- URL to the video (must be publicly accessible)
Sourcepub fn video_base64(data: impl Into<String>, media_type: VideoMediaType) -> Self
pub fn video_base64(data: impl Into<String>, media_type: VideoMediaType) -> Self
Create video content from base64-encoded data
§Arguments
data- Base64-encoded video datamedia_type- Video media type (e.g.,VideoMediaType::MP4)
Trait Implementations§
Source§impl Clone for UserContent
impl Clone for UserContent
Source§fn clone(&self) -> UserContent
fn clone(&self) -> UserContent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UserContent
impl Debug for UserContent
Source§impl<'de> Deserialize<'de> for UserContent
impl<'de> Deserialize<'de> for UserContent
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&str> for UserContent
impl From<&str> for UserContent
Source§impl From<String> for UserContent
impl From<String> for UserContent
Source§impl From<UserContent> for UserContent
Convert OpenAI’s UserContent to OpenRouter’s UserContent
impl From<UserContent> for UserContent
Convert OpenAI’s UserContent to OpenRouter’s UserContent
Source§fn from(value: UserContent) -> Self
fn from(value: UserContent) -> Self
Source§impl FromStr for UserContent
impl FromStr for UserContent
Source§impl PartialEq for UserContent
impl PartialEq for UserContent
Source§impl Serialize for UserContent
impl Serialize for UserContent
Source§impl TryFrom<UserContent> for UserContent
impl TryFrom<UserContent> for UserContent
Source§type Error = MessageError
type Error = MessageError
impl StructuralPartialEq for UserContent
Auto Trait Implementations§
impl Freeze for UserContent
impl RefUnwindSafe for UserContent
impl Send for UserContent
impl Sync for UserContent
impl Unpin for UserContent
impl UnsafeUnpin for UserContent
impl UnwindSafe for UserContent
Blanket Implementations§
Source§impl<T> ArgumentConvert for Twhere
T: FromStr,
impl<T> ArgumentConvert for Twhere
T: FromStr,
Source§fn convert<'life0, 'async_trait>(
__arg0: impl CacheHttp + 'async_trait,
__arg1: Option<GuildId>,
__arg2: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<T, <T as ArgumentConvert>::Err>> + Send + 'async_trait>>where
'life0: 'async_trait,
T: 'async_trait,
fn convert<'life0, 'async_trait>(
__arg0: impl CacheHttp + 'async_trait,
__arg1: Option<GuildId>,
__arg2: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<T, <T as ArgumentConvert>::Err>> + Send + 'async_trait>>where
'life0: 'async_trait,
T: 'async_trait,
s as a command parameter of this type.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
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
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> 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 more