A Rust library for generating AI-powered summaries using Claude API.
SolSummary provides a simple interface to Claude AI for generating summaries and analyses.
- Rust 1.90 or higher
- Claude API key from Anthropic
Add this to your Cargo.toml:
[dependencies]
solsummary = "0.0.1"-
Get a Claude API Key
- Sign up at console.anthropic.com
- Generate an API key from your account dashboard
-
Configure the Application
- Copy
example.config.tomltoconfig.toml:cp example.config.toml config.toml
- Edit
config.tomland add your API key:api_key = "your-actual-api-key-here"
- You can customize the model versions and
max_tokensin the config file max_tokenscontrols the maximum length of the response (default: 4096)
- Copy
-
Build the Project
cargo build
use solsummary::{ClaudeModel, SolSummary};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let summary = SolSummary::new()?;
let result = summary.summarize(
ClaudeModel::Sonnet,
"Summarize the following data".to_string(),
r#"{"key": "value"}"#.to_string(),
None
).await?;
println!("Summary: {}", result);
Ok(())
}You can override the default max_tokens setting by passing Some(value) as the last parameter:
use solsummary::{ClaudeModel, SolSummary};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let summary = SolSummary::new()?;
let result = summary.summarize(
ClaudeModel::Sonnet,
"Provide a detailed analysis".to_string(),
r#"{"complex": "data", "requires": "longer response"}"#.to_string(),
Some(8192)
).await?;
println!("Summary: {}", result);
Ok(())
}In addition to the predefined models (Sonnet, Opus, Haiku), you can pass raw model strings:
use solsummary::{ClaudeModel, SolSummary};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let summary = SolSummary::new()?;
// Using the custom() helper method
let result = summary.summarize(
ClaudeModel::custom("claude-sonnet-4-5-20250929"),
"Summarize the following data".to_string(),
r#"{"key": "value"}"#.to_string(),
None
).await?;
println!("Summary: {}", result);
Ok(())
}Or using the Custom variant directly:
use solsummary::{ClaudeModel, SolSummary};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let summary = SolSummary::new()?;
let result = summary.summarize(
ClaudeModel::Custom("claude-opus-4-1-20250805".to_string()),
"Summarize the following data".to_string(),
r#"{"key": "value"}"#.to_string(),
None
).await?;
println!("Summary: {}", result);
Ok(())
}The library provides detailed error types based on Claude API responses:
InvalidRequest- HTTP 400: Issue with request format or contentAuthenticationError- HTTP 401: Invalid or missing API keyPermissionError- HTTP 403: API key lacks required permissionsNotFound- HTTP 404: Requested resource not foundRequestTooLarge- HTTP 413 or validation: Request exceeds 30 MB limitRateLimitError- HTTP 429: Rate limit exceededApiError- HTTP 500: Internal API errorOverloaded- HTTP 529: API temporarily overloadedInvalidApiKey- Empty API key providedInvalidParameters- Empty prompt or dataNetworkError- Network connectivity issuesEnvError- Environment variable issues
use solsummary::{ClaudeModel, SolSummary, SolSummaryError};
#[tokio::main]
async fn main() {
let summary = SolSummary::new().expect("Failed to initialize");
match summary.summarize(
ClaudeModel::Sonnet,
"Summarize".to_string(),
data.to_string(),
None
).await {
Ok(result) => println!("{}", result),
Err(SolSummaryError::RateLimitError(msg)) => {
eprintln!("Rate limit hit: {}", msg);
}
Err(SolSummaryError::AuthenticationError(msg)) => {
eprintln!("Auth failed: {}", msg);
}
Err(e) => eprintln!("Error: {}", e),
}
}cargo runcargo run -- --config my_config.toml# Show version
cargo run -- --version
# Show help
cargo run -- --helpAfter building, you can use the binary directly:
# Default config
./target/debug/solsummary
# Custom config
./target/debug/solsummary --config my_config.toml
# Show version
./target/debug/solsummary --versioncargo test