claude-client
A Rust client for the Claude API. This client provides a simple interface to interact with Claude's API, including sending messages and listing available models.
Features
- Send messages to Claude with optional system prompts
- List available Claude models
- Built-in error handling and type safety
- Async/await support using tokio
- Default to latest Claude model (claude-3-7-sonnet-20250219)
Building and Testing
Prerequisites
- Rust 1.75 or later
- An Anthropic API key for running tests
Building
To build the project:
Running Tests
The test suite includes both unit tests and integration tests. The integration tests require a valid Anthropic API key to be set in the environment:
# Set your API key
# Run all tests
# Run only unit tests
# Run only integration tests
If no API key is set, the integration tests will be skipped automatically.
Usage
First, set your Anthropic API key as an environment variable:
Basic Usage
use ClaudeClient;
async
Using a Specific Model
use ClaudeClient;
async
Listing Available Models
use ClaudeClient;
async
Error Handling
The client uses Rust's Result type for error handling. All errors are wrapped in a Box<dyn std::error::Error>. Common errors include:
- Missing or invalid API key
- Network connectivity issues
- Invalid model selection
- API rate limits
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.