### Quick Start: Initialize and Use Rainy SDK Client Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/index_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to initialize the Rainy SDK client using an API key and perform a health check. This example requires the 'tokio' runtime for asynchronous operations. ```rust use rainy_sdk::RainyClient; #[tokio::main] async fn main() -> Result<(), Box> { // Create client with API key - automatically connects to api.enosislabs.com let client = RainyClient::with_api_key("your-api-key")?; // Check API health let health = client.health_check().await?; println!("API Status: {:?}", health.status); Ok(()) } ``` -------------------------------- ### Rust: Example Search Queries Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/type.Result_search=std%3A%3Avec This section provides examples of common search queries used within the Rust ecosystem. These examples demonstrate how to search for specific types, type conversions, and generic type manipulations. They are useful for navigating documentation and finding relevant code examples. ```Rust std::vec ``` ```Rust u32 -> bool ``` ```Rust Option, (T -> U) -> Option ``` -------------------------------- ### List All Available Models with RainyClient (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=u32+-%3E+bool Explains the `list_available_models` asynchronous method for retrieving comprehensive information about all models available via the Rainy API, including provider details and compatibility. Includes an example of how to use it. ```Rust pub async fn list_available_models(&self) -> Result // Example Usage: // let client = RainyClient::with_api_key("your-api-key")?; // let models = client.list_available_models().await?; // // println!("Total models: {}", models.total_models); // for (provider, model_list) in &models.providers { // println!("Provider {}: {:?}", provider, model_list); // } ``` -------------------------------- ### Get Available Models (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search= Shows how to fetch a list of all available models and their providers from the Rainy API using the `RainyClient`. This method is useful for understanding which models are accessible and their capabilities. ```Rust let client = RainyClient::with_api_key("your-api-key")?; let models = client.list_available_models().await?; println!("Total models: {}", models.total_models); for (provider, model_list) in &models.providers { println!("Provider {}: {:?}", provider, model_list); } ``` -------------------------------- ### Retrieve Cowork Capabilities with Rainy SDK Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search= Demonstrates how to retrieve coworker capabilities using the Rainy SDK. This involves creating a client and calling `get_cowork_capabilities()`. The example shows how to check the user's subscription plan and the number of available AI models based on the returned capabilities. ```rust let client = RainyClient::with_api_key("your-api-key")?; let caps = client.get_cowork_capabilities().await?; if caps.plan.is_paid() { println!("Paid plan with {} models available", caps.models.len()); } else { println!("Free plan - upgrade for more features"); } ``` -------------------------------- ### Get RainyClient Authentication Configuration (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=u32+-%3E+bool Provides the `auth_config` method, which returns a reference to the current authentication configuration of the `RainyClient`. ```Rust pub fn auth_config(&self) -> &AuthConfig ``` -------------------------------- ### Convert Result to Option (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/type.Result Shows how to convert a `Result` into an `Option` using the `ok()` method. This consumes the Result and discards the error if present. Examples cover both Ok and Err variants. ```rust let x: Result = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result = Err("Nothing here"); assert_eq!(x.ok(), None); ``` -------------------------------- ### Get Usage Statistics - Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search= Retrieves comprehensive usage statistics, including daily usage and recent transactions, for the authenticated user. Requires an API key for client initialization. Returns detailed usage data. ```Rust let client = RainyClient::with_api_key("user-api-key")?; let usage = client.get_usage_stats(Some(30)).await?; println!("Total requests: {}", usage.total_requests); println!("Total tokens: {}", usage.total_tokens); for daily in &usage.daily_usage { println!("{}: {} credits used", daily.date, daily.credits_used); } ``` -------------------------------- ### Get Reference to Result Content (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/type.Result Illustrates the `as_ref()` method for obtaining references to the contained values of a `Result` without consuming it. It converts `&Result` to `Result<&T, &E>`. Examples show both Ok and Err scenarios. ```rust let x: Result = Ok(2); assert_eq!(x.as_ref(), Ok(&2)); let x: Result = Err("Error"); assert_eq!(x.as_ref(), Err(&"Error")); ``` -------------------------------- ### Get Mutable Reference to Result Content (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/type.Result Explains the `as_mut()` method, which converts `&mut Result` to `Result<&mut T, &mut E>`, allowing mutable access to the contained values. The example demonstrates modifying values within Ok and Err variants. ```rust fn mutate(r: &mut Result) { match r.as_mut() { Ok(v) => *v = 42, Err(e) => *e = 0, } } let mut x: Result = Ok(2); mutate(&mut x); assert_eq!(x.unwrap(), 42); let mut x: Result = Err(13); mutate(&mut x); assert_eq!(x.unwrap_err(), 0); ``` -------------------------------- ### Initialize RainyClient with API Key (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search= Demonstrates how to create a `RainyClient` instance using an API key, typically retrieved from an environment variable. This client is the primary interface for interacting with the Rainy API, handling authentication, rate limiting, and retries automatically. ```Rust use rainy_sdk::{RainyClient, Result}; #[tokio::main] async fn main() -> Result<()> { // Create a client using an API key from an environment variable let api_key = std::env::var("RAINY_API_KEY").expect("RAINY_API_KEY not set"); let client = RainyClient::with_api_key(api_key)?; // Use the client to make API calls let models = client.get_available_models().await?; println!("Available models: {:?}", models); Ok(()) } ``` -------------------------------- ### Create Free Plan CoworkCapabilities in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/cowork/struct.CoworkCapabilities Provides a constructor function to create a `CoworkCapabilities` instance representing the free plan. This is useful for offline or fallback scenarios where specific plan details are not available. ```rust pub fn free() -> Self { // Implementation details for creating free plan capabilities } ``` -------------------------------- ### RainyClient Initialization Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search= Methods for creating and configuring the RainyClient. ```APIDOC ## RainyClient Initialization ### `RainyClient::with_api_key(api_key: impl Into) -> Result` **Description**: Creates a new `RainyClient` with the given API key. This is the simplest way to create a client, using default settings. **Method**: `fn` **Arguments**: - `api_key` (String) - Your Rainy API key. **Returns**: A `Result` containing the new `RainyClient` or a `RainyError`. ### `RainyClient::with_config(auth_config: AuthConfig) -> Result` **Description**: Creates a new `RainyClient` with a custom `AuthConfig`, allowing for advanced configuration like custom base URLs or timeouts. **Method**: `fn` **Arguments**: - `auth_config` (AuthConfig) - The authentication configuration to use. **Returns**: A `Result` containing the new `RainyClient` or a `RainyError`. ### `RainyClient::with_retry_config(self, retry_config: RetryConfig) -> Self` **Description**: Sets a custom retry configuration for the client, overriding the default retry behavior. **Method**: `fn` **Arguments**: - `retry_config` (RetryConfig) - The new retry configuration. **Returns**: The `RainyClient` instance with the updated retry configuration. ``` -------------------------------- ### Get RainyClient Base URL Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient Shows how to retrieve the base URL that the `RainyClient` is configured to use for its API requests. ```rust let base_url = client.base_url(); ``` -------------------------------- ### Result `unwrap_or` Method Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/type.Result_search= Shows how to use `unwrap_or` to get the `Ok` value or a default value if the `Result` is an `Err`. ```APIDOC ## POST /api/result/unwrap_or ### Description Retrieves the `Ok` value from a `Result` or returns a provided default value if the `Result` is an `Err`. The default value is eagerly evaluated. ### Method POST ### Endpoint /api/result/unwrap_or ### Parameters #### Request Body - **result_value** (Result) - Required - The `Result` to unwrap. - **default_value** (T) - Required - The default value to return if `result_value` is `Err`. ### Request Example ```json { "result_value": {"Err": "error"}, "default_value": 2 } ``` ### Response #### Success Response (200) - **value** (T) - The unwrapped `Ok` value or the default value. #### Response Example ```json { "value": 2 } ``` ``` -------------------------------- ### RainyClient Initialization Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=u32+-%3E+bool Methods for creating and configuring the RainyClient. ```APIDOC ## RainyClient Initialization ### `RainyClient::with_api_key` #### Description Creates a new `RainyClient` with the given API key. This is the simplest way to create a client, using default settings. #### Method `pub fn with_api_key(api_key: impl Into) -> Result` #### Arguments * `api_key` (String) - Your Rainy API key. #### Returns A `Result` containing the new `RainyClient` or a `RainyError`. ### `RainyClient::with_config` #### Description Creates a new `RainyClient` with a custom `AuthConfig`, allowing for advanced configuration like custom base URLs or timeouts. #### Method `pub fn with_config(auth_config: AuthConfig) -> Result` #### Arguments * `auth_config` (AuthConfig) - The authentication configuration to use. #### Returns A `Result` containing the new `RainyClient` or a `RainyError`. ### `RainyClient::with_retry_config` #### Description Sets a custom retry configuration for the client, overriding the default retry behavior. #### Method `pub fn with_retry_config(self, retry_config: RetryConfig) -> Self` #### Arguments * `retry_config` (RetryConfig) - The new retry configuration. #### Returns The `RainyClient` instance with the updated retry configuration. ### `RainyClient::auth_config` #### Description Returns a reference to the current authentication configuration. #### Method `pub fn auth_config(&self) -> &AuthConfig` ### `RainyClient::base_url` #### Description Returns the base URL being used by the client. #### Method `pub fn base_url(&self) -> &str` ``` -------------------------------- ### ContentPart Constructors and Methods Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/models/struct.ContentPart_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods for creating and modifying ContentPart instances. ```APIDOC ## ContentPart Methods ### Create Text Content Part #### `text(content: impl Into) -> Self` Creates a new text content part. ### Create Function Call Content Part #### `function_call(name: impl Into, args: Value) -> Self` Creates a new function call content part. ### Create Function Response Content Part #### `function_response(name: impl Into, response: Value) -> Self` Creates a new function response content part. ### Add Thought Signature #### `with_thought_signature(self, signature: impl Into) -> Self` Adds a thought signature to this content part. ### Mark as Thought Content #### `as_thought(self) -> Self` Marks this content part as containing thought content. ``` -------------------------------- ### Create and Configure AuthConfig in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/auth/struct.AuthConfig_search= Demonstrates how to create a new AuthConfig instance and customize its settings using builder-style methods like with_base_url, with_timeout, and with_max_retries. ```rust use rainy_sdk::auth::AuthConfig; let config = AuthConfig::new("your-api-key") .with_base_url("https://api.example.com") .with_timeout(60) .with_max_retries(5); assert_eq!(config.base_url, "https://api.example.com"); assert_eq!(config.timeout_seconds, 60); assert_eq!(config.max_retries, 5); ``` -------------------------------- ### Get RainyClient Base URL (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=u32+-%3E+bool Documents the `base_url` method, which returns the base URL currently being used by the `RainyClient` instance. ```Rust pub fn base_url(&self) -> &str ``` -------------------------------- ### Get Request ID from RainyError Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/enum.RainyError_search= Retrieves the unique request identifier associated with a `RainyError`, if present. This ID is valuable for debugging and customer support. ```rust pub fn request_id(&self) -> Option<&str> // Returns the unique request ID associated with the error, if available. // This is useful for debugging and support requests. ``` -------------------------------- ### Authentication: Initialize Rainy SDK Client with API Key Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/index_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows the simplest method to create a client for the Rainy SDK using an API key. This is a prerequisite for making authenticated requests to the Rainy API. ```rust // Simplest way to create a client let client = RainyClient::with_api_key("ra-20250125143052Ab3Cd9Ef2Gh5Ik8Lm4Np7Qr")?; ``` -------------------------------- ### VZip Implementation Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/search/struct.SearchOptions_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Documentation for the `VZip` implementation, enabling zipping operations. ```APIDOC ## Implementation: VZip for T ### Description Provides functionality for zipping operations using the `VZip` type. ### Method: vzip ```rust fn vzip(self) -> V; ``` Performs the zipping operation. ``` -------------------------------- ### Get Machine-Readable Code from RainyError Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/enum.RainyError_search= Extracts a machine-readable error code from a `RainyError`, if available. This code can be used for programmatic error handling or logging. ```rust pub fn code(&self) -> Option<&str> // Returns the machine-readable error code, if available. ``` -------------------------------- ### Get User Account Information Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=std%3A%3Avec Retrieves comprehensive information about the currently authenticated user. This endpoint requires authentication using an API key. ```APIDOC ## GET /user/account ### Description Retrieves information about the authenticated user, including current credit balance. ### Method GET ### Endpoint /user/account ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let client = RainyClient::with_api_key("user-api-key")?; let user = client.get_user_account().await?; println!("Current credits: {}", user.current_credits); ``` ### Response #### Success Response (200) - **current_credits** (integer) - The remaining credits for the user. #### Response Example ```json { "current_credits": 1000 } ``` ``` -------------------------------- ### Create Basic Search Options in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/search/struct.SearchOptions_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E A constructor function for SearchOptions that creates a default configuration for a basic web search. This is a convenient way to initialize search parameters. ```rust pub fn basic() -> Self ``` -------------------------------- ### Get Remaining Uses in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/cowork/struct.CoworkUsage_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Implements the `remaining` method for the `CoworkUsage` struct. This function returns the number of remaining uses available. ```rust pub fn remaining(&self) -> u32 { // Implementation details omitted } ``` -------------------------------- ### Get Request Timeout Duration in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/auth/struct.AuthConfig_search= Provides a method to retrieve the configured request timeout value from AuthConfig as a standard Rust Duration type. ```rust pub fn timeout(&self) -> Duration ``` -------------------------------- ### ContentPart Implementation Methods Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/models/struct.ContentPart_search= Provides methods for creating and modifying ContentPart instances, such as creating text parts, function call parts, function response parts, and adding thought signatures. ```APIDOC ## ContentPart Implementations ### `text(content: impl Into) -> Self` Creates a new text content part. ### `function_call(name: impl Into, args: Value) -> Self` Creates a new function call content part. ### `function_response(name: impl Into, response: Value) -> Self` Creates a new function response content part. ### `with_thought_signature(self, signature: impl Into) -> Self` Adds a thought signature to this content part. ### `as_thought(self) -> Self` Marks this content part as containing thought content. ``` -------------------------------- ### GET /user/account Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search= Retrieves comprehensive information about the currently authenticated user, including their current credit balance. This endpoint requires authentication using an API key. ```APIDOC ## GET /user/account ### Description Get current user account information. This endpoint requires user authentication with an API key. ### Method GET ### Endpoint /user/account ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let client = RainyClient::with_api_key("user-api-key")?; let user = client.get_user_account().await?; println!("Current credits: {}", user.current_credits); ``` ### Response #### Success Response (200) - **current_credits** (integer) - The current credit balance of the user. #### Response Example ```json { "current_credits": 1000 } ``` ``` -------------------------------- ### Create RainyClient with Custom AuthConfig (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=u32+-%3E+bool Details the `with_config` method for initializing `RainyClient` with a custom `AuthConfig`. This allows for advanced settings like custom base URLs or timeouts. ```Rust pub fn with_config(auth_config: AuthConfig) -> Result ``` -------------------------------- ### Get Machine-Readable Code from RainyError Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/enum.RainyError_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Extracts a machine-readable error code from a `RainyError`, if available. This code can be used for programmatic error handling or logging. It returns an `Option<&str>`. ```rust pub fn code(&self) -> Option<&str> ``` -------------------------------- ### VZip Implementation Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/models/struct.ChatCompletionStreamResponse_search=std%3A%3Avec Documentation for the `vzip` method within the `VZip` trait implementation. ```APIDOC ## impl VZip for T ### Description Implementation of the `VZip` trait for type `T` where `V` implements `MultiLane`. ### Method `vzip` ### Endpoint N/A (This is a trait implementation, not a REST endpoint) ### Parameters None ### Request Example N/A ### Response #### Success Response Returns a value of type `V`. #### Response Example N/A ``` -------------------------------- ### Get Retry Delay for RainyError Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/enum.RainyError_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the recommended delay in seconds before retrying a request when a `RainyError` occurs. This is particularly relevant for rate-limiting errors. It returns an `Option`. ```rust pub fn retry_after(&self) -> Option ``` -------------------------------- ### GET /usage/statistics Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search= Retrieves detailed usage statistics for the user, including daily usage and recent transactions. An optional parameter can specify the number of past days to include. ```APIDOC ## GET /usage/statistics ### Description Returns comprehensive usage statistics including daily usage and recent transactions. ### Method GET ### Endpoint /usage/statistics ### Parameters #### Path Parameters None #### Query Parameters - **days** (integer) - Optional. The number of past days for which to retrieve usage statistics. #### Request Body None ### Request Example ```rust let client = RainyClient::with_api_key("user-api-key")?; let usage = client.get_usage_stats(Some(30)).await?; println!("Total requests: {}", usage.total_requests); println!("Total tokens: {}", usage.total_tokens); for daily in &usage.daily_usage { println!("{}: {} credits used", daily.date, daily.credits_used); } ``` ### Response #### Success Response (200) - **total_requests** (integer) - The total number of requests made. - **total_tokens** (integer) - The total number of tokens used. - **daily_usage** (array of objects) - An array containing daily usage statistics. - **date** (string) - The date of the usage. - **credits_used** (integer) - The number of credits used on that date. #### Response Example ```json { "total_requests": 5000, "total_tokens": 100000, "daily_usage": [ { "date": "2023-10-26", "credits_used": 150 }, { "date": "2023-10-27", "credits_used": 200 } ] } ``` ``` -------------------------------- ### Implement Free Plan Capabilities in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/cowork/struct.CoworkCapabilities_search= Provides a constructor function `free()` for the `CoworkCapabilities` struct. This function creates an instance representing the capabilities for a free plan, often used for offline or fallback scenarios. It initializes the struct with default or free-tier values. ```rust pub fn free() -> Self ``` -------------------------------- ### Get User Account Information Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=u32+-%3E+bool Retrieves comprehensive information about the currently authenticated user, including their credit balance. This endpoint requires authentication using an API key. ```APIDOC ## GET /api/user/account ### Description Get current user account information. This endpoint requires user authentication with an API key. ### Method GET ### Endpoint /api/user/account ### Parameters #### Query Parameters - **api_key** (string) - Required - The API key for user authentication. ### Request Example ```rust let client = RainyClient::with_api_key("user-api-key")?; let user = client.get_user_account().await?; println!("Current credits: {}", user.current_credits); ``` ### Response #### Success Response (200) - **current_credits** (integer) - The remaining credits for the user. - **user_id** (string) - The unique identifier for the user. #### Response Example ```json { "current_credits": 1000, "user_id": "user-12345" } ``` ``` -------------------------------- ### WithSubscriber Implementation Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/models/struct.ChatCompletionStreamResponse_search=std%3A%3Avec Documentation for methods related to attaching subscribers within the `WithSubscriber` trait implementation. ```APIDOC ## impl WithSubscriber for T ### Description Implementation of the `WithSubscriber` trait for type `T`. ### Methods #### `with_subscriber(self, subscriber: S) -> WithDispatch` ##### Description Attaches the provided `Subscriber` to this type, returning a `WithDispatch` wrapper. ##### Method `with_subscriber` ##### Endpoint N/A (This is a trait implementation, not a REST endpoint) ##### Parameters - **subscriber** (S) - Required - The subscriber to attach. ##### Request Example N/A ##### Response - **Success Response (200)**: Returns a `WithDispatch` wrapper. #### `with_current_subscriber(self) -> WithDispatch` ##### Description Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. ##### Method `with_current_subscriber` ##### Endpoint N/A (This is a trait implementation, not a REST endpoint) ##### Parameters None ##### Request Example N/A ##### Response - **Success Response (200)**: Returns a `WithDispatch` wrapper. ``` -------------------------------- ### Get Request ID from RainyError Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/enum.RainyError_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the unique request identifier associated with a `RainyError`. This ID is crucial for debugging and providing context to support personnel. It returns an `Option<&str>`. ```rust pub fn request_id(&self) -> Option<&str> ``` -------------------------------- ### CoworkPlan Methods Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/cowork/type.CoworkTier This section details the methods available for the CoworkPlan enum, including checking payment status and retrieving display names. ```APIDOC ## Methods for CoworkPlan ### `is_paid(&self) -> bool` #### Description Checks if the current CoworkPlan requires payment. #### Method `pub fn is_paid(&self) -> bool` #### Returns - `bool`: `true` if the plan requires payment, `false` otherwise. ### `display_name(&self) -> &'static str` #### Description Gets a user-friendly display name for the current CoworkPlan. #### Method `pub fn display_name(&self) -> &'static str` #### Returns - `&'static str`: A static string representing the display name of the plan. ``` -------------------------------- ### Get Machine-Readable Code for RainyError Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/enum.RainyError_search=std%3A%3Avec The `code` method returns an optional string slice representing a machine-readable error code. This can be used for programmatic error handling or logging. ```rust pub fn code(&self) -> Option<&str> { // ... implementation details ... } ``` -------------------------------- ### Create AuthConfig with API Key in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/auth/struct.AuthConfig_search=std%3A%3Avec Provides the implementation for the `new` associated function of AuthConfig, which creates a new instance with a given API key and default settings. This is the entry point for configuring the client. ```rust pub fn new(api_key: impl Into) -> Self ``` -------------------------------- ### Ownership and Cloning Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/auth/struct.AuthConfig_search=std%3A%3Avec Provides methods for obtaining ownership and cloning data. ```APIDOC ## `to_owned` ### Description Creates owned data from borrowed data, usually by cloning. ### Method `fn to_owned(&self) -> T` ### Endpoint N/A (Method within a type) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example N/A ### Response #### Success Response - **T** (type) - The owned data, typically a clone of the borrowed data. #### Response Example N/A ## `clone_into` ### Description Uses borrowed data to replace owned data, usually by cloning. ### Method `fn clone_into(&self, target: &mut T)` ### Endpoint N/A (Method within a type) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example N/A ### Response #### Success Response None (modifies `target` in place) #### Response Example N/A ``` -------------------------------- ### Get Usage Statistics with Rainy SDK Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search= Fetches detailed usage statistics for the user. An optional number of days can be provided to specify the lookback period, with a default of 30 days. ```rust let client = RainyClient::with_api_key("user-api-key")?; let usage = client.get_usage_stats(Some(14)).await?; // Process usage statistics... ``` -------------------------------- ### Conversion Traits (`Into`, `TryFrom`, `TryInto`) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/auth/struct.AuthConfig_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Documentation for traits related to type conversions, both fallible and infallible. ```APIDOC ## Conversion Traits (`Into`, `TryFrom`, `TryInto`) ### Description These traits facilitate conversions between different types. `Into` provides infallible conversion, while `TryFrom` and `TryInto` handle fallible conversions. ### `impl Into for T` #### `fn into(self) -> U` Calls `U::from(self)`. This conversion's behavior is determined by the `From for U` implementation. ### `impl TryFrom for T` #### Type `Error = Infallible` - The type returned in the event of a conversion error. #### `fn try_from(value: U) -> Result>::Error>` - Performs the conversion. ### `impl TryInto for T` #### Type `Error = >::Error` - The type returned in the event of a conversion error. #### `fn try_into(self) -> Result>::Error>` - Performs the conversion. ``` -------------------------------- ### Configure ChatCompletionRequest Provider Hint in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/models/struct.ChatCompletionRequest A builder method to specify a provider hint for the request. This can guide the system in selecting a particular model provider for processing the chat completion. ```rust pub fn with_provider(self, provider: impl Into) -> Self ``` -------------------------------- ### Create RainyClient with API Key (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=u32+-%3E+bool Provides the function signature and a brief explanation for creating a `RainyClient` using an API key. This method uses default configurations for base URL, timeout, and retries. ```Rust pub fn with_api_key(api_key: impl Into) -> Result ``` -------------------------------- ### Get Retry Delay for RainyError Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/enum.RainyError_search= Retrieves the recommended delay in seconds before retrying a request, specifically for errors like rate limiting. Returns an `Option` with the delay or `None` if not applicable. ```rust pub fn retry_after(&self) -> Option // Returns the recommended delay in seconds before a retry, if applicable. // This is typically used with `RateLimit` errors. // Returns an `Option` containing the retry delay in seconds, or `None` if not applicable. ``` -------------------------------- ### Conversion Traits (`Into`, `From`, `TryFrom`, `TryInto`) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/auth/struct.AuthConfig_search=u32+-%3E+bool Documentation for traits related to type conversions, both fallible and infallible. ```APIDOC ## Conversion Traits ### Description These traits facilitate conversions between different types, including infallible (`Into`, `From`) and fallible (`TryInto`, `TryFrom`) conversions. ### Traits - `impl Into for T where U: From` - `fn into(self) -> U`: Calls `U::from(self)`. - `impl TryFrom for T where U: Into` - `type Error = Infallible` - `fn try_from(value: U) -> Result>::Error>`: Performs the conversion. - `impl TryInto for T where U: TryFrom` - `type Error = >::Error` - `fn try_into(self) -> Result>::Error>`: Performs the conversion. ``` -------------------------------- ### Default Values with `unwrap_or` on Result in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/type.Result Shows how to use `unwrap_or` to get the `Ok` value from a `Result` or a provided default value if it's an `Err`. The default value is eagerly evaluated. ```rust let default = 2; let x: Result = Ok(9); assert_eq!(x.unwrap_or(default), 9); let x: Result = Err("error"); assert_eq!(x.unwrap_or(default), default); ``` -------------------------------- ### Create Chat Completion with Rainy SDK Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search= Demonstrates how to create a chat completion using the Rainy SDK. It initializes a client, defines user messages, sets up a completion request with parameters like model and max tokens, and then prints the content of the first response choice. This method is suitable for single, non-streaming responses. ```rust let client = RainyClient::with_api_key("user-api-key")?; let messages = vec![ ChatMessage::user("Hello, how are you?"), ]; let request = ChatCompletionRequest::new("gemini-pro", messages) .with_max_tokens(150) .with_temperature(0.7); let response = client.create_chat_completion(request).await?; if let Some(choice) = response.choices.first() { println!("Response: {}", choice.message.content); } ``` -------------------------------- ### Get Offline Capabilities Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/fn.get_offline_capabilities_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves offline capabilities based on cached plan data. This function is useful when the network is unavailable, providing a degraded user experience using previously cached plan information. ```APIDOC ## GET /offline_capabilities ### Description Retrieves offline capabilities based on cached plan data. This can be used when the network is unavailable to provide a degraded experience based on previously cached plan info. ### Method GET ### Endpoint /offline_capabilities ### Parameters #### Query Parameters - **cached_plan** (Option) - Optional - The cached plan data to base offline capabilities on. ### Request Example (No request body for GET request) ### Response #### Success Response (200) - **CoworkCapabilities** - An object containing the available offline capabilities. #### Response Example ```json { "capabilities": [ "feature1", "feature2" ] } ``` ``` -------------------------------- ### Ownership and String Conversion Traits Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/auth/struct.AuthConfig_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Documentation for traits related to owning data and converting values to strings. ```APIDOC ## Ownership and String Conversion (`ToOwned`, `ToString`, `ToStringFallible`) ### Description These traits provide mechanisms for creating owned versions of data and converting values into strings, including fallible string conversion. ### `impl ToOwned for T` #### Type `Owned = T` - The resulting type after obtaining ownership. #### `fn to_owned(&self) -> T` - Creates owned data from borrowed data, usually by cloning. #### `fn clone_into(&self, target: &mut T)` - Uses borrowed data to replace owned data, usually by cloning. ### `impl ToString for T` #### `fn to_string(&self) -> String` - Converts the given value to a `String`. ### `impl ToStringFallible for T` #### `fn try_to_string(&self) -> Result` - Similar to `ToString::to_string`, but avoids panicking on out-of-memory errors. ``` -------------------------------- ### Get Request ID for RainyError Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/enum.RainyError_search=std%3A%3Avec The `request_id` method returns an optional string slice containing a unique identifier for the request that caused the error. This ID is valuable for debugging and when seeking support. ```rust pub fn request_id(&self) -> Option<&str> { // ... implementation details ... } ``` -------------------------------- ### Get Usage Statistics Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=u32+-%3E+bool Retrieves comprehensive usage statistics for the user, including daily usage breakdowns and recent transaction summaries. An optional parameter can specify the number of past days to include. ```APIDOC ## GET /api/usage/stats ### Description Returns comprehensive usage statistics including daily usage and recent transactions. ### Method GET ### Endpoint /api/usage/stats ### Parameters #### Query Parameters - **days** (integer) - Optional - The number of past days to include in the usage statistics. Defaults to all available data if not provided. ### Request Example ```rust let client = RainyClient::with_api_key("user-api-key")?; let usage = client.get_usage_stats(Some(30)).await?; println!("Total requests: {}", usage.total_requests); println!("Total tokens: {}", usage.total_tokens); for daily in &usage.daily_usage { println!("{}: {} credits used", daily.date, daily.credits_used); } ``` ### Response #### Success Response (200) - **total_requests** (integer) - The total number of requests made. - **total_tokens** (integer) - The total number of tokens consumed. - **daily_usage** (array) - An array of daily usage objects. - **date** (string) - The date of the daily usage record (YYYY-MM-DD). - **credits_used** (integer) - The number of credits used on that date. #### Response Example ```json { "total_requests": 5000, "total_tokens": 1000000, "daily_usage": [ { "date": "2023-10-26", "credits_used": 50 }, { "date": "2023-10-27", "credits_used": 75 } ] } ``` ``` -------------------------------- ### Create Advanced Search Options in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/search/struct.SearchOptions_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E A constructor function for SearchOptions that creates a configuration for an advanced web search, including AI-generated answers. This allows for more comprehensive search results. ```rust pub fn advanced() -> Self ``` -------------------------------- ### Get Credit Statistics with Rainy SDK Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search= Retrieves statistics about the user's credit balance and usage. An optional number of days can be specified to look back in history; defaults to 30 days. ```rust let client = RainyClient::with_api_key("user-api-key")?; let credits = client.get_credit_stats(Some(7)).await?; println!("Current credits: {}", credits.current_credits); println!("Estimated cost: {}", credits.estimated_cost); ``` -------------------------------- ### Build HTTP Headers from AuthConfig in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/auth/struct.AuthConfig_search= Illustrates the process of building HTTP headers, including Authorization and User-Agent, from an AuthConfig instance. This method returns a Result containing a HeaderMap or a RainyError. ```rust pub fn build_headers(&self) -> Result ``` -------------------------------- ### Implement Clone Trait for SearchOptions in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/search/struct.SearchOptions Demonstrates the implementation of the `Clone` trait for the `SearchOptions` struct, allowing instances to be duplicated. Includes methods for cloning and clone-from operations. ```rust impl Clone for SearchOptions { fn clone(&self) -> SearchOptions fn clone_from(&mut self, source: &Self) } ``` -------------------------------- ### Rust Ownership Management: to_owned and clone_into Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/models/struct.ContentPart_search= Demonstrates methods for creating owned data from borrowed data (`to_owned`) and replacing owned data with borrowed data (`clone_into`), typically involving cloning. These are fundamental for managing data ownership and mutability in Rust. ```rust trait OwnedData { type Owned; fn to_owned(&self) -> Self::Owned; fn clone_into(&self, target: &mut Self::Owned); } // Example usage (conceptual): // let borrowed_data = &some_value; // let owned_data = borrowed_data.to_owned(); // let mut existing_owned_data = ...; // borrowed_data.clone_into(&mut existing_owned_data); ``` -------------------------------- ### into_ok Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/type.Result_search= Returns the contained Ok value, but never panics. ```APIDOC ## GET /result/into_ok ### Description Returns the contained `Ok` value, but never panics. Unlike `unwrap`, this method is known to never panic on the result types it is implemented for. Therefore, it can be used instead of `unwrap` as a maintainability safeguard that will fail to compile if the error type of the `Result` is later changed to an error that can actually occur. ### Method GET ### Endpoint `/result/into_ok` ### Parameters #### Query Parameters - **value** (Result) - Required - The Result value to convert. ### Request Example ```json { "value": "Ok(\"this is fine\")" } ``` ### Response #### Success Response (200) - **value** (T) - The contained Ok value. #### Response Example ```json { "value": "this is fine" } ``` ``` -------------------------------- ### Get Retry Delay for RainyError Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/enum.RainyError_search=std%3A%3Avec The `retry_after` method returns an optional `u64` representing the recommended delay in seconds before retrying an operation. This is particularly relevant for rate-limiting errors, providing guidance on when to attempt the operation again. ```rust pub fn retry_after(&self) -> Option { // ... implementation details ... } ``` -------------------------------- ### Create ContentPart Instances in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/models/struct.ContentPart_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides functions to create instances of the ContentPart struct. These include creating a text-only part, a part representing a function call with a name and arguments, and a part for a function response with a name and result. It also allows adding a thought signature or marking a part as containing thought content. ```Rust pub fn text(content: impl Into) -> Self ``` ```Rust pub fn function_call(name: impl Into, args: Value) -> Self ``` ```Rust pub fn function_response(name: impl Into, response: Value) -> Self ``` ```Rust pub fn with_thought_signature(self, signature: impl Into) -> Self ``` ```Rust pub fn as_thought(self) -> Self ``` -------------------------------- ### Create API Key with Rainy SDK (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=u32+-%3E+bool Demonstrates the creation of a new API key with an optional expiration date. This operation requires authentication using a master API key and returns the newly created `ApiKey` object. ```rust let client = RainyClient::with_api_key("master-api-key")?; let new_key = client.create_api_key("My new key", Some(30)).await?; println!("Created API key: {}", new_key.key); ``` -------------------------------- ### Get Usage Statistics with Rainy SDK Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=u32+-%3E+bool Retrieves detailed usage statistics for the user. Similar to credit statistics, this function accepts an optional number of days to specify the lookback period, defaulting to 30 days. ```Rust let client = RainyClient::with_api_key("user-api-key")?; let usage = client.get_usage_stats(Some(14)).await?; // Process usage statistics here ``` -------------------------------- ### Convert Result Error to Option (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/type.Result Demonstrates the `err()` method for converting a `Result` into an `Option`. This consumes the Result and discards the success value if present. Examples include Ok and Err cases. ```rust let x: Result = Ok(2); assert_eq!(x.err(), None); let x: Result = Err("Nothing here"); assert_eq!(x.err(), Some("Nothing here")); ``` -------------------------------- ### Cowork Capabilities API Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves information about the user's current subscription plan, available AI models, and feature access. ```APIDOC ## GET /v1/cowork/capabilities ### Description Retrieves the user's current subscription plan details, available AI models, feature access, and usage information. ### Method GET ### Endpoint /v1/cowork/capabilities ### Parameters None ### Response #### Success Response (200) - **plan** (object) - Information about the subscription plan. - **name** (string) - Name of the plan (e.g., "Free", "GoPlus", "Pro"). - **is_paid** (boolean) - True if the plan is a paid tier. - **models** (array of strings) - List of AI model identifiers available for the current plan. - **features** (object) - Access status for various features. - **web_research** (boolean) - **document_export** (boolean) - **image_analysis** (boolean) - ... (other features) - **usage** (object) - Current usage statistics. - **requests_remaining** (integer) - **tokens_remaining** (integer) #### Response Example ```json { "plan": { "name": "Pro", "is_paid": true }, "models": [ "gpt-4o", "gemini-pro", "llama-3.1-8b-instant" ], "features": { "web_research": true, "document_export": true, "image_analysis": false }, "usage": { "requests_remaining": 950, "tokens_remaining": 98000 } } ``` ``` -------------------------------- ### Get User Account Information - Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search= Fetches the current user account information, including available credits. This endpoint requires prior user authentication using an API key. Returns user-specific account details. ```Rust let client = RainyClient::with_api_key("user-api-key")?; let user = client.get_user_account().await?; println!("Current credits: {}", user.current_credits); ``` -------------------------------- ### Implement display_name Method for CoworkPlan in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/cowork/enum.CoworkPlan Implements a method to retrieve a user-friendly display name for each CoworkPlan variant. This is useful for presenting plan information to users in a clear and understandable format. ```rust pub fn display_name(&self) -> &'static str { match self { CoworkPlan::Free => "Free", CoworkPlan::GoPlus => "Go Plus", CoworkPlan::Plus => "Plus", CoworkPlan::Pro => "Pro", CoworkPlan::ProPlus => "Pro Plus", } } ``` -------------------------------- ### unwrap Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/error/type.Result_search= Returns the contained Ok value or panics. ```APIDOC ## GET /result/unwrap ### Description Returns the contained `Ok` value, consuming the `self` value. Panics if the value is an `Err`, with a panic message provided by the `Err`’s value. ### Method GET ### Endpoint `/result/unwrap` ### Parameters #### Query Parameters - **value** (Result) - Required - The Result value to unwrap. ### Request Example ```json { "value": "Ok(2)" } ``` ### Response #### Success Response (200) - **value** (T) - The contained Ok value. #### Response Example ```json { "value": 2 } ``` #### Error Response (400) - **error** (string) - A message indicating that the value was an Err and the panic occurred. #### Error Response Example ```json { "error": "panic: emergency failure" } ``` ``` -------------------------------- ### Get Available Cowork Models with Rainy SDK (Rust) Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/client/struct.RainyClient_search=u32+-%3E+bool Retrieves a list of AI model identifiers that are available for the current subscription plan. This function is useful for dynamically adapting application features based on user access. ```rust let client = RainyClient::with_api_key("your-api-key")?; let models = client.get_cowork_models().await?; println!("Available models: {:?}", models); ``` -------------------------------- ### Implement Serialize for CreditTransaction in Rust Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/models/struct.CreditTransaction_search= Implements the Serialize trait for the CreditTransaction struct, allowing it to be serialized into various data formats using the Serde library. This is vital for sending transaction data, for example, in API responses or when storing data. ```rust impl Serialize for CreditTransaction { fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where __S: Serializer, { // ... implementation details ... } } ``` -------------------------------- ### Rust: Create New RateLimiter Instance Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/auth/struct.RateLimiter Demonstrates how to create a new instance of the deprecated `RateLimiter`. This function takes the maximum number of requests allowed per minute as an argument. ```rust pub fn new(requests_per_minute: u32) -> Self ``` -------------------------------- ### TryInto Trait Source: https://docs.rs/rainy-sdk/latest/rainy_sdk/search/struct.SearchOptions_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Documentation for the `TryInto` trait, which provides a convenient way to perform fallible conversions using `TryFrom`. ```APIDOC ## Trait: TryInto ### Description Provides a fallible way to convert into another type, typically implemented using `TryFrom`. ### Method: try_into ```rust fn try_into(self) -> Result>::Error>; ``` Performs the conversion from the current type `T` into type `U`. ```