chipp
Rust client for the Chipp.ai API - OpenAI-compatible chat completions with streaming support.
Features
- ✅ Non-streaming chat: Simple request/response with
chat() - ✅ Streaming chat: Real-time text streaming with
chat_stream() - ✅ Latency measurement: API connectivity testing with
ping() - ✅ Session management: Automatic
chatSessionIdtracking for conversation continuity - ✅ Automatic retries: Exponential backoff for transient failures
- ✅ Configurable timeouts: Per-request timeout configuration
- ✅ Correlation IDs: Automatic UUID generation for request tracing
- ✅ Comprehensive error handling: Typed errors with context
- ✅ Full async/await: Built on
tokioandreqwest - ✅ Security-first: API keys redacted from Debug output
Installation
Add this to your Cargo.toml:
[]
= "0.1.1" # x-release-please-version
= { = "1", = ["full"] }
Or install via cargo:
Quick Start
use ;
async
Examples
Non-Streaming Chat
use ;
let client = new?;
let mut session = new;
let messages = vec!;
let response = client.chat.await?;
println!;
Streaming Chat
use ;
use StreamExt;
let mut stream = client.chat_stream.await?;
while let Some = stream.next.await
Session Continuity
The client automatically manages chatSessionId for conversation continuity:
// First message
let messages1 = vec!;
client.chat.await?;
// Second message (remembers context)
let messages2 = vec!;
let response = client.chat.await?;
// Response will mention "42"
Latency Measurement
Measure API latency for performance monitoring:
use Duration;
// Measure API latency
let latency = client.ping.await?;
if latency < from_secs
Token Usage Tracking
Use chat_detailed() to get token counts for rate limiting:
use ;
let client = new?;
let mut session = new;
let response = client
.chat_detailed
.await?;
println!;
println!;
println!;
println!;
ChatResponse accessors:
content()- Response textusage()- Token countssession_id()- Chat session IDcompletion_id()- Completion ID for debuggingcreated_at()- Unix timestampfinish_reason()- Why completion stoppedmodel()- Model/app ID
Running Examples
Set your API credentials:
Run the examples:
# Simple non-streaming example
# Streaming example
# Session continuity example
# Error handling example (demonstrates retry logic, fallback strategies, etc.)
Configuration
Using the Builder Pattern (Recommended)
use ChippConfig;
let config = builder
.api_key
.model
.timeout // Optional: default is 30s
.max_retries // Optional: default is 3
.build?;
Direct Struct Initialization
use ChippConfig;
use Duration;
let config = ChippConfig ;
Configuration Options:
api_key(required): Your Chipp API key from the Share → API tabmodel(required): Your appNameId from the Chipp dashboardbase_url: API endpoint (default:https://app.chipp.ai/api/v1)timeout: Request timeout (default: 30 seconds)max_retries: Maximum retry attempts for transient failures (default: 3)initial_retry_delay: Initial backoff delay (default: 100ms)max_retry_delay: Maximum backoff delay (default: 10 seconds)
Error Handling
use ChippClientError;
match client.chat.await
Security Best Practices
This SDK is designed with security in mind. Follow these best practices to protect your API credentials:
Never Hardcode API Keys
// ❌ BAD: Hardcoded API key
let config = builder
.api_key // NEVER do this!
.build?;
// ✅ GOOD: Load from environment variable
let config = builder
.api_key
.build?;
Use Environment Variables
Store credentials in environment variables, not in source code or config files:
# Set in your shell or .env file (which is gitignored)
Avoid Logging Configuration Objects
The ChippConfig struct implements a custom Debug trait that redacts the API key:
let config = builder
.api_key
.model
.build?;
// Safe to log - API key is redacted
println!;
// Output: ChippConfig { api_key: "[REDACTED]", base_url: "...", model: "my-app", ... }
However, avoid logging raw API key strings directly:
// ❌ BAD: Logging the raw API key
let api_key = var?;
debug!; // NEVER do this!
// ✅ GOOD: Log without exposing secrets
info!;
Production Recommendations
- Use a secrets manager (AWS Secrets Manager, HashiCorp Vault, etc.) for production deployments
- Rotate API keys regularly and update your environment variables
- Audit logs to ensure no sensitive data is accidentally logged
- Use
.gitignoreto exclude.envfiles from version control
Testing
Unit Tests
Integration Tests (requires API key)
Documentation
Full API documentation is available on docs.rs.
Build documentation locally:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup
-
Clone the repository:
-
Run tests:
-
Run examples:
Code Quality
Before submitting a PR, please ensure:
# Format code
# Run clippy
# Run tests
# Build docs
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Contributions are welcome! Please see CONTRIBUTING.md for guidelines on:
- Setting up pre-commit hooks
- Code quality standards
- Testing requirements
- Pull request process
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Links
- Chipp.ai - Official website
- API Documentation (docs.rs) - Full Rust API reference
- Crates.io - Package registry
- GitHub Repository - Source code and issues