Expand description
§otter-ai
Unified LLM API with provider collections, automatic auth resolution, token and cost tracking, and simple context persistence and hand-off to other models mid-session.
This is a Rust re-implementation of the @earendil-works/pi-ai TypeScript package.
§Quick Start
use otter_ai::*;
use otter_ai::types::*;
use otter_ai::models::create_models;
use otter_ai::providers::faux::register_faux_provider;
// 1. Create the models registry
let models = create_models();
// 2. Register a provider
let reg = register_faux_provider(None);
models.set_provider_arc(reg.provider.clone());
// 3. Refresh the model catalog
models.refresh_all(false, true).await?;
// 4. Look up a model
let model = models.get_model("faux", "faux-mini")
.expect("model not found");
// 5. Build a conversation context
let context = Context {
system_prompt: Some("You are a helpful assistant.".into()),
messages: vec![Message::User {
content: vec![ContentBlock::Text { text: "Hello!".into(), text_signature: None}],
timestamp: chrono::Utc::now().timestamp_millis(),
}],
..Default::default()
};
// 6. Get a complete response
let options = SimpleStreamOptions::default();
let response = models.complete(&model, context, options).await?;
println!("{}", content_text(&match &response {
Message::Assistant { content, .. } => content,
_ => panic!("unexpected message type"),
}));Re-exports§
pub use types::content_text;pub use types::uuidv7;pub use types::Api;pub use types::ApiStreamOptions;pub use types::AssistantMessage;pub use types::AssistantMessageEvent;pub use types::CancellationToken;pub use types::ContentBlock;pub use types::Context;pub use types::ImageContent;pub use types::JsonSchemaFormat;pub use types::KnownApi;pub use types::Message;pub use types::Model;pub use types::ModelCostRates;pub use types::ModelThinkingLevel;pub use types::ProviderEnv;pub use types::ProviderHeaders;pub use types::ProviderId;pub use types::ProviderRequestOptions;pub use types::ResponseFormat;pub use types::SimpleStreamOptions;pub use types::Tool;pub use types::ToolChoice;pub use types::Usage;pub use types::UsageCost;pub use models::create_models;pub use models::Models;pub use models_store::InMemoryModelsStore;pub use models_store::ModelsStore;pub use models_store::ModelsStoreEntry;pub use auth::default_provider_auth_context;pub use auth::parse_loose_credential;pub use auth::AuthContext;pub use auth::Credential;pub use auth::CredentialStore;pub use auth::FileCredentialStore;pub use auth::InMemoryCredentialStore;pub use auth::ModelAuth;pub use utils::calculate_usage_cost;pub use utils::config_dir;pub use utils::config_dir;pub use utils::config_path;pub use utils::create_assistant_message_event_stream;pub use utils::ensure_config_dir;pub use utils::parse_partial_json;pub use utils::string_enum_schema;pub use utils::tool_from_schema;pub use utils::validate_tool_arguments;pub use utils::with_retry;pub use utils::AssistantMessageEventStream;pub use utils::EventStream;pub use utils::RetryConfig;pub use schemars;pub use serde_json;
Modules§
Macros§
- schema_
for - Generates a
RootSchemafor the given type using default settings.
Traits§
- Json
Schema - A type which can be described as a JSON Schema document.