Anthropic SDK for Rust
The Anthropic SDK for Rust provides a simple and efficient way to interact with the Anthropic API, allowing you to send requests and process responses asynchronously. This SDK supports both streaming and non-streaming responses, making it versatile for different use cases.
Features ✨
- Asynchronous request handling 🚀
- Support for streaming API responses 🌊
- Easy configuration for authentication and request parameters 🔧
- Error handling with detailed messages 🛠️💬
Installation
Add the following to your Cargo.toml file:
[]
= "0.1.0"
= "0.15.0"
= "1.0"
= { = "1.0", = ["full"] }
Usage
Basic Usage
For non-streaming responses, you can use the SDK as follows:
// examples/basic_usage.rs
use Client;
use dotenv;
use json;
async
This example demonstrates how to send a request to the Anthropic API and print the response.
Streaming Usage
For streaming responses, the SDK can be used as follows:
// examples/streaming_usage.rs
use Client;
use dotenv;
use json;
use ;
async
In this example, the response is processed as it streams in. Each chunk of text is printed as soon as it's received, and the entire message is also available at the end.
Configuration
Before running the examples, make sure to set your Anthropic API key in an .env file at the root of your project:
ANTHROPIC_API_KEY=your_api_key_here
Alternatively, you can set the ANTHROPIC_API_KEY environment variable in your system.
Feature Requests 📬
If you have any ideas or requests for new features, we'd love to hear from you! Please send your suggestions to hello@mixpeal.com, and we'll be sure to consider them for future updates. Your input is invaluable in helping us improve! 🌟🚀
Error Handling
The SDK provides detailed error messages for various failure scenarios, such as network issues, invalid parameters, or unauthorized access. Errors are returned as Result types, allowing you to handle them using idiomatic Rust error handling patterns.