Callix
A flexible, configuration-driven HTTP client library for Rust, designed for seamless integration with AI APIs and RESTful services.
Features
- Configuration-Driven - Define providers and endpoints in YAML for easy management
- Auto Retry - Built-in retry mechanism with configurable delays and exponential backoff
- Template Engine - Dynamic variable substitution in URLs, headers, and request bodies
- Multi-Provider Support - Pre-configured for OpenAI, Gemini, Claude, and more
- Type-Safe - Full Rust type safety with serde integration
- Zero Config - Works out of the box with default configurations for popular AI services
- Async/Await - Built on Tokio and Reqwest for high-performance async operations
Table of Contents
Installation
Add Callix to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["full"] }
= "1.0"
Step-by-Step Setup
-
Create a new Rust project:
-
Add dependencies using
cargo add(Rust 1.62+):Or manually in
Cargo.toml:[] = "0.1.0" = { = "1", = ["full"] } = "1.0" -
Write your first code in
src/main.rs:use CallixBuilder; use Duration; async -
Run your project:
Optional: Environment Variables Setup
For secure API key management, create a .env file:
# .env
OPENAI_API_KEY=sk-your-key-here
GEMINI_API_KEY=your-key-here
ANTHROPIC_API_KEY=sk-ant-your-key-here
Add the dotenv crate:
Load environment variables in your code:
use dotenv;
use env;
async
Quick Start
Basic Usage
use CallixBuilder;
use json;
use Duration;
async
OpenAI Example
use json;
let response = callix
.request?
.var
.var
.var
.send
.await?;
let json: Value = response.json.await?;
println!;
Anthropic Claude Example
let response = callix
.request?
.var
.var
.var
.var
.send
.await?;
Configuration
Default Configuration
Callix includes pre-configured settings for popular AI providers:
- OpenAI - GPT-4, GPT-3.5 Turbo
- Google Gemini - Gemini Pro, Gemini Flash
- Anthropic Claude - Claude 3.5 Sonnet, Opus, Haiku
Custom Configuration
Create a config.yaml file to define your own API endpoints:
providers:
my_api:
base_url: "https://api.example.com"
headers:
Authorization: "Bearer {{API_KEY}}"
Content-Type: "application/json"
timeout: 30 # seconds (optional)
endpoints:
predict:
path: "/v1/predict"
method: "POST"
body_template: |
{
"input": "{{text}}",
"model": "{{model}}",
"temperature": {{temperature}}
}
query_params:
version: "{{api_version}}"
Use your custom configuration:
let callix = new
.config
.build?;
let response = callix
.request?
.var
.var
.var
.var
.var
.send
.await?;
Examples
Custom Headers
let response = callix
.request?
.var
.var
.var
.header
.header
.send
.await?;
Retry Configuration
let callix = new
.retries
.retry_delay
.timeout
.build?;
Error Handling
match response.status
Batch Processing
let prompts = vec!;
for prompt in prompts
Concurrent Requests
use join_all;
let prompts = vec!;
let futures: = prompts.iter.map.collect;
let results = join_all.await;
Documentation
- Full API Documentation - Complete API reference
- Wiki & Advanced Guide - Comprehensive guide with advanced usage
- Examples Directory - Working code examples
openai.rs- OpenAI ChatGPT integrationgemini.rs- Google Gemini APIanthropic.rs- Anthropic Claude API
Running Examples
Feature Flags
Customize Callix with feature flags:
[]
= { = "0.1", = ["rustls-tls", "gzip"] }
Available Features
| Feature | Description | Default |
|---|---|---|
native-tls |
Use system's native TLS | ✓ |
rustls-tls |
Use Rustls (pure Rust TLS) | ✗ |
blocking |
Blocking HTTP client support | ✗ |
cookies |
Cookie store support | ✗ |
gzip |
Gzip compression | ✗ |
brotli |
Brotli compression | ✗ |
stream |
Streaming response support | ✗ |
Architecture
Component Overview
CallixBuilder → Callix → RequestBuilder → HTTP Request → CallixResponse
↓ ↓
Config TemplateEngine
Core Modules
client- Main client implementation and HTTP method parsingconfig- Configuration management and provider definitionsrequest- Request building and execution with retry logicresponse- Response handling and parsing utilitiestemplate- Variable substitution and template renderingerror- Comprehensive error types and conversions
Minimum Supported Rust Version (MSRV)
Callix requires Rust 1.75 or higher.
Contributing
Contributions are welcome! Here's how to get started:
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
Development Setup
Guidelines
- Follow Rust naming conventions and idioms
- Add tests for new features
- Update documentation
- Run
cargo fmtandcargo clippybefore committing
Security
- Never hardcode API keys - Use environment variables
- Validate all user input - Sanitize before sending requests
- Use HTTPS - All default configurations use secure connections
- Rotate keys regularly - Follow security best practices
Acknowledgments
Built with these amazing Rust crates:
- reqwest - High-performance HTTP client
- serde - Serialization framework
- tokio - Async runtime
- serde_yaml - YAML configuration parsing
Support
- GitHub Issues: Report bugs or request features
- Discussions: Ask questions or share ideas
- Documentation: Read the docs