### Install Rainy SDK dependencies Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Add the required dependencies to your Cargo.toml file to use the Rainy SDK with Tokio and Futures. ```toml [dependencies] rainy-sdk = "0.6.50" tokio = { version = "1.53", features = ["macros", "rt-multi-thread"] } futures = "0.3" ``` -------------------------------- ### Initialize RainyClient and create chat completion Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Demonstrates creating a client using an environment variable and executing a chat completion request. ```rust use rainy_sdk::{ChatCompletionRequest, ChatMessage, RainyClient}; #[tokio::main] async fn main() -> Result<(), Box> { let client = RainyClient::with_api_key(std::env::var("RAINY_API_KEY")?)?; let request = ChatCompletionRequest::new( "compatible/chat-model", vec![ChatMessage::user("Explain ownership in Rust in two sentences.")], ) .with_max_completion_tokens(200) .with_temperature(0.2); let response = client.create_chat_completion(request).await?; println!("{}", response.choices[0].message.content); Ok(()) } ``` -------------------------------- ### Configure Reasoning Model Parameters Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Shows how to set reasoning effort levels and manual token budgets for compatible models. ```rust use rainy_sdk::{ChatCompletionRequest, ChatMessage, ReasoningConfig, RainyClient}; # fn example(client: &RainyClient) -> rainy_sdk::Result<()> { let effort_request = ChatCompletionRequest::new( "compatible/reasoning-model", vec![ChatMessage::user("Think carefully, then answer.")], ) .with_reasoning_effort("high") .with_include_reasoning(true); let explicit_budget = ChatCompletionRequest::new( "compatible/reasoning-model", vec![ChatMessage::user("Use an explicit budget.")], ) .with_reasoning_config(ReasoningConfig::manual_budget(2048)); # let _ = (client, effort_request, explicit_budget); # Ok(()) # } ``` -------------------------------- ### Initialize and login with RainySessionClient Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Requires the rainy-account feature enabled. Ensure environment variables RAINY_EMAIL and RAINY_PASSWORD are set before execution. ```rust use rainy_sdk::RainySessionClient; # async fn example() -> Result<(), Box> { let mut session = RainySessionClient::new()?; let login = session .login( &std::env::var("RAINY_EMAIL")?, &std::env::var("RAINY_PASSWORD")?, ) .await?; println!("signed in as {}", login.user.email); # Ok(()) # } ``` -------------------------------- ### Configure Chat Completion Requests Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Demonstrates creating an OpenAIChatCompletionRequest with response formats, reasoning configuration, and tool definitions. ```rust use rainy_sdk::{ FunctionDefinition, OpenAIChatCompletionRequest, OpenAIChatMessage, OpenAIContentPart, OpenAIMessageContent, ReasoningConfig, ResponseFormat, Tool, ToolType, }; # fn example() -> rainy_sdk::Result<()> { let request = OpenAIChatCompletionRequest::new( "compatible/chat-model", vec![OpenAIChatMessage::user(r#"Describe this image."#)], ) .with_response_format(ResponseFormat::JsonObject) .with_reasoning_config(ReasoningConfig::effort("high")) .with_tools(vec![Tool { r#type: ToolType::Function, function: FunctionDefinition::new("lookup") .with_description("Look up a value") .with_parameters(rainy_sdk::serde_json::json!({ "type": "object", "properties": {"key": {"type": "string"}} })), }]); let multimodal = OpenAIChatMessage::user(OpenAIMessageContent::parts(vec![ OpenAIContentPart::text("This is text"), ])); let _ = (request, multimodal); # Ok(()) # } ``` -------------------------------- ### Run development and validation checks Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Standard commands for formatting, testing, linting, and documentation generation in the development environment. ```bash cargo fmt --all -- --check cargo check --locked --all-targets --all-features cargo test --locked --all-features cargo clippy --locked --all-targets --all-features -- -D warnings cargo doc --locked --all-features --no-deps cargo package --locked --list ``` -------------------------------- ### Configure RainyClient with custom base URL Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Shows how to use AuthConfig to set a custom API base URL, timeout, and retry settings. ```rust use rainy_sdk::{AuthConfig, RainyClient}; # fn example() -> Result<(), Box> { let config = AuthConfig::new(std::env::var("API_KEY")?) .with_api_base_url("https://example-compatible-provider.com/v1") .with_timeout(60) .with_retry(false); let client = RainyClient::with_config(config)?; # let _ = client; # Ok(()) # } ``` -------------------------------- ### Create a Response Request Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Constructs a ResponsesRequest with text input, reasoning effort, token limits, and function tools. ```rust use rainy_sdk::{RainyClient, ResponsesRequest}; # async fn example(client: &RainyClient) -> rainy_sdk::Result<()> { let request = ResponsesRequest::text( "compatible/responses-model", "Summarize the supplied context.", ) .with_reasoning_effort("medium") .with_max_output_tokens(800) .add_function_tool( "lookup", "Look up a value", rainy_sdk::serde_json::json!({"type": "object", "properties": {}}), ); let response = client.create_response(request).await?.0; println!("{}", response.text().unwrap_or_default()); # Ok(()) # } ``` -------------------------------- ### Perform Model Discovery in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Opt-in operation to discover models based on specific criteria like input modalities and tool support. ```rust use rainy_sdk::{ModelSelectionCriteria, RainyClient}; # async fn example(client: &RainyClient) -> rainy_sdk::Result<()> { let models = client .select_models(ModelSelectionCriteria { required_input_modalities: vec!["text".to_string()], require_tools: Some(true), ..Default::default() }) .await?; for model in models { println!("{}", model.id); } # Ok(()) # } ``` -------------------------------- ### Configure Anthropic version for compatible deployments Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Demonstrates setting a specific Anthropic version on the client for compatible Messages deployments. ```rust use rainy_sdk::{AuthConfig, RainyClient}; # fn example() -> Result<(), Box> { let client = RainyClient::with_config(AuthConfig::new(std::env::var("API_KEY")?))? .with_anthropic_version("2024-10-22")?; # let _ = client; # Ok(()) # } ``` -------------------------------- ### Enable optional features in Cargo.toml Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Include specific optional features like rainy-account by modifying the dependency declaration in your Cargo.toml. ```toml rainy-sdk = { version = "0.6.50", features = ["rainy-account"] } ``` -------------------------------- ### OpenAIChatCompletionRequest Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Constructs a chat completion request for OpenAI-compatible models, supporting multimodal content, tool definitions, and response formatting. ```APIDOC ## OpenAIChatCompletionRequest ### Description Creates a new chat completion request compatible with OpenAI-style APIs. Supports multimodal content, tool definitions, and specific response formats. ### Method Constructor: `OpenAIChatCompletionRequest::new(model: &str, messages: Vec)` ### Parameters - **model** (string) - Required - The model identifier. - **messages** (Vec) - Required - A list of chat messages. ### Configuration Methods - **with_response_format** (ResponseFormat) - Optional - Sets the expected response format (e.g., JsonObject). - **with_reasoning_config** (ReasoningConfig) - Optional - Configures reasoning effort. - **with_tools** (Vec) - Optional - Defines available tools for the model. ``` -------------------------------- ### Create an Anthropic Message Request Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Initializes an AnthropicMessageRequest with system prompts and native thinking budget configuration. ```rust use rainy_sdk::{AnthropicMessage, AnthropicMessageRequest, RainyClient}; # async fn example(client: &RainyClient) -> rainy_sdk::Result<()> { let request = AnthropicMessageRequest::new( "compatible/messages-model", vec![AnthropicMessage::user("Give a concise answer.")], 1024, ) .with_system("You are concise.") .with_thinking(256); let response = client.create_message(request).await?; println!("{}", response.text()); # Ok(()) # } ``` -------------------------------- ### Stream Chat Completions in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Uses a bounded incremental SSE parser to handle chat completion streams. Requires a RainyClient instance and a ChatCompletionRequest. ```rust use futures::StreamExt; use rainy_sdk::{ChatCompletionRequest, ChatMessage, RainyClient}; # async fn example(client: &RainyClient) -> rainy_sdk::Result<()> { let request = ChatCompletionRequest::new( "compatible/chat-model", vec![ChatMessage::user("Write a short haiku about Rust.")], ); let mut stream = client.chat_completion_stream(request).await?; while let Some(chunk) = stream.next().await { if let Some(delta) = chunk?.choices.first().and_then(|choice| choice.delta.content.as_deref()) { print!("{delta}"); } } # Ok(()) # } ``` -------------------------------- ### ChatCompletionRequest Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Constructs a standard chat completion request with support for reasoning controls. ```APIDOC ## ChatCompletionRequest ### Description Creates a standard chat completion request with support for reasoning effort and explicit budget configuration. ### Method Constructor: `ChatCompletionRequest::new(model: &str, messages: Vec)` ### Configuration Methods - **with_reasoning_effort** (string) - Optional - Sets the reasoning effort level (e.g., 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'). - **with_include_reasoning** (bool) - Optional - Whether to include reasoning in the response. - **with_reasoning_config** (ReasoningConfig) - Optional - Sets a manual token budget for reasoning. ``` -------------------------------- ### RainyClient::create_response Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Sends a ResponsesRequest to the client to generate text responses, optionally including tool definitions and reasoning parameters. ```APIDOC ## Method: create_response ### Description Sends a `ResponsesRequest` to the API to generate a response based on the provided context and configuration. ### Parameters - **request** (ResponsesRequest) - Required - The request object containing the model, prompt, and optional configurations like reasoning effort, max tokens, and function tools. ### Example ```rust let request = ResponsesRequest::text( "compatible/responses-model", "Summarize the supplied context.", ) .with_reasoning_effort("medium") .with_max_output_tokens(800) .add_function_tool( "lookup", "Look up a value", rainy_sdk::serde_json::json!({}), ); let response = client.create_response(request).await?.0; ``` ``` -------------------------------- ### Create Embeddings in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Generates text embeddings using a specified model, encoding format, and dimensions. ```rust use rainy_sdk::{EmbeddingEncodingFormat, EmbeddingsRequest, RainyClient}; # async fn example(client: &RainyClient) -> rainy_sdk::Result<()> { let request = EmbeddingsRequest::text("compatible/embedding-model", "Rainy embeddings") .with_encoding_format(EmbeddingEncodingFormat::Float) .with_dimensions(768); let response = client.create_embeddings(request).await?; println!("{} embedding(s)", response.data.len()); # Ok(()) # } ``` -------------------------------- ### RainyClient::create_message Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Sends an AnthropicMessageRequest to the client to generate native Anthropic messages with support for system prompts and thinking budgets. ```APIDOC ## Method: create_message ### Description Sends an `AnthropicMessageRequest` to the API to generate a response using native Anthropic message structures. ### Parameters - **request** (AnthropicMessageRequest) - Required - The request object containing the model, message history, and optional configurations like system prompts and thinking budgets. ### Example ```rust let request = AnthropicMessageRequest::new( "compatible/messages-model", vec![AnthropicMessage::user("Give a concise answer.")], 1024, ) .with_system("You are concise.") .with_thinking(256); let response = client.create_message(request).await?; ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.