Callix
A flexible, configuration-driven HTTP client library for Rust, designed for easy integration with AI APIs and RESTful services.
Features
- Configuration-Driven - Define providers and endpoints in YAML
- Auto Retry - Built-in retry mechanism with configurable delays
- Template Engine - Dynamic variable substitution in URLs and bodies
- Multi-Provider - Support for OpenAI, Gemini, Claude, OpenRouter, and more
- Type-Safe - Full Rust type safety with serde integration
- Zero Config - Works out of the box with default configurations
Installation
Add this 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 API keys, create a .env file:
# .env
OPENAI_API_KEY=sk-your-key-here
GEMINI_API_KEY=your-key-here
Add dotenv:
Load in your code:
use dotenv;
use env;
async
Quick Start
Basic Usage
use CallixBuilder;
use Duration;
async
OpenAI Example
use json;
let response = callix
.request?
.var
.var
.var
.send
.await?;
let json: Value = response.json.await?;
println!;
OpenRouter Example
// Access 100+ AI models with one API key
let response = callix
.request?
.var
.var
.var
.send
.await?;
Configuration
Default Configuration
Callix comes with built-in configurations for popular AI providers:
- OpenAI (GPT-4, GPT-3.5)
- Google Gemini (Gemini Pro, Flash)
- Anthropic Claude (Claude 3.5 Sonnet, Opus, Haiku)
Custom Configuration
Create a config.yaml:
providers:
my_api:
base_url: "https://api.example.com"
headers:
Authorization: "Bearer {{API_KEY}}"
Content-Type: "application/json"
endpoints:
predict:
path: "/v1/predict"
method: "POST"
body_template: |
{
"input": "{{text}}",
"model": "{{model}}"
}
Then use it:
let callix = new
.config
.build?;
let response = callix
.request?
.var
.var
.var
.send
.await?;
Advanced Features
Custom Headers
let response = callix
.request?
.var
.header
.header
.send
.await?;
Retry Configuration
let callix = new
.retries
.retry_delay
.timeout
.build?;
Error Handling
match response.status
Examples
Check out the examples directory for more:
openai.rs- OpenAI ChatGPT integrationgemini.rs- Google Gemini APIanthropic.rs- Anthropic Claude API
Run an example:
Features Flags
[]
= { = "0.1", = ["rustls-tls"] }
Available features:
native-tls(default) - Use native TLSrustls-tls- Use Rustls (pure Rust)blocking- Blocking HTTP clientcookies- Cookie store supportgzip,brotli- Compression supportstream- Streaming response support
Documentation
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- 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
Acknowledgments
Built with:
Contact
- GitHub Issues: Report a bug
- Discussions: Ask a question