pub mod client;
pub mod error;
pub mod types;
#[cfg(feature = "chat")]
pub mod chat;
#[cfg(feature = "responses")]
pub mod responses;
#[cfg(feature = "streaming")]
pub mod streaming;
#[cfg(feature = "embeddings")]
pub mod embeddings;
#[cfg(feature = "anthropic")]
pub mod anthropic;
#[cfg(feature = "providers")]
pub mod providers;
#[cfg(feature = "models")]
pub mod models;
#[cfg(feature = "generations")]
pub mod generations;
pub use client::{OpenRouterClient, OpenRouterClientBuilder};
pub use error::{OpenRouterError, Result};
#[cfg(feature = "chat")]
pub use chat::{
ChatCompletionBuilder,
ChatCompletionRequest,
ChatCompletionResponse,
ChatCompletionBuilder as ChatRequestBuilder,
Choice,
};
#[cfg(feature = "responses")]
pub use responses::{
ResponsesRequestBuilder,
ResponsesRequest,
ResponsesResponse,
ResponsesRequestBuilder as ResponseBuilder,
InputItem, InputRole, InputContent, OutputItem, OutputContent,
ReasoningSummary, ReasoningConfig,
};
#[cfg(feature = "streaming")]
pub use streaming::{
ChatCompletionStream,
ChatCompletionChunk,
StreamingChoice,
DeltaMessage,
collect_stream,
};
#[cfg(feature = "embeddings")]
pub use embeddings::{
EmbeddingBuilder,
EmbeddingRequest,
EmbeddingResponse,
EmbeddingData,
EmbeddingDataItem,
EmbeddingUsage,
EmbeddingModel,
EmbeddingInput,
EmbeddingEncodingFormat,
};
#[cfg(feature = "anthropic")]
pub use anthropic::{
AnthropicMessageBuilder,
AnthropicMessageRequest,
AnthropicMessageResponse,
AnthropicMessageParam,
AnthropicRole,
AnthropicContentItem,
AnthropicResponseContent,
AnthropicUsage,
AnthropicTool,
AnthropicToolChoice,
AnthropicThinking,
};
#[cfg(feature = "providers")]
pub use providers::{
Provider,
ProvidersResponse,
};
#[cfg(feature = "models")]
pub use models::{
Model,
ModelsResponse,
ModelsCountResponse,
PublicPricing,
ModelArchitecture,
TopProviderInfo,
PerRequestLimits,
DefaultParameters,
ListModelsParams,
};
#[cfg(feature = "generations")]
pub use generations::{
GenerationResponse,
GenerationData,
ProviderResponse,
};
pub use types::{
Message,
Role,
Function,
Tool,
ToolChoice,
ResponseFormat,
Usage,
Plugin,
ProviderPreferences,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = OpenRouterError::ConfigError("test error".to_string());
assert_eq!(err.to_string(), "Configuration error: test error");
}
#[test]
fn test_role_serialization() {
let role = Role::User;
let json = serde_json::to_string(&role).unwrap();
assert_eq!(json, "\"user\"");
let role = Role::Assistant;
let json = serde_json::to_string(&role).unwrap();
assert_eq!(json, "\"assistant\"");
}
#[test]
fn test_role_deserialization() {
let role: Role = serde_json::from_str("\"system\"").unwrap();
assert!(matches!(role, Role::System));
}
#[test]
fn test_usage_default() {
let usage = Usage {
prompt_tokens: 10,
completion_tokens: 20,
total_tokens: 30,
prompt_tokens_details: None,
completion_tokens_details: None,
cost: None,
};
assert_eq!(usage.prompt_tokens, 10);
assert_eq!(usage.completion_tokens, 20);
assert_eq!(usage.total_tokens, 30);
}
#[test]
fn test_message_builder_pattern() {
let msg = Message {
role: Role::User,
content: Some("Hello".to_string()),
name: None,
tool_calls: None,
};
assert!(matches!(msg.role, Role::User));
assert_eq!(msg.content, Some("Hello".to_string()));
}
}