replicate-rs
A Rust client library for Replicate. This library allows you to run AI models, create predictions, stream outputs, and manage various Replicate resources from your Rust applications.
Overview
replicate-rs
is an async-first Rust implementation of the Replicate API client, designed to provide a safe, efficient, and ergonomic interface to Replicate's AI model platform. Built with tokio
for async runtime and reqwest
for HTTP client capabilities.
Production-ready features include: retry logic with exponential backoff, configurable timeouts, comprehensive error handling, and full async support.
Features
Core Functionality
- ✅ Async/Await Support: Built on tokio for high-performance async operations
- ✅ Type Safety: Leverages Rust's type system for compile-time correctness
- ✅ HTTP Client: Uses reqwest for robust HTTP communications
- ✅ Authentication: Secure API token management
- ✅ Error Handling: Comprehensive error types with detailed context
API Operations
- ✅ Predictions: Create, get, list, and cancel predictions
- 🔲 Models: Access and manage AI models
- 🔲 Streaming: Real-time server-sent events for model outputs
- ✅ Files: Upload and manage files with multipart form data
- 🔲 Versions: Access specific model versions
- 🔲 Collections: Browse model collections
- 🔲 Deployments: Manage model deployments
- 🔲 Training: Create and manage fine-tuning jobs
- 🔲 Webhooks: Configure webhooks for async notifications
- 🔲 Hardware: Query available hardware options
Advanced Features
- ✅ Pagination: Efficient handling of paginated responses
- ✅ Retry Logic: Automatic retry with exponential backoff
- ✅ Timeout Configuration: Configurable connect and request timeouts
- 🔲 Rate Limiting: Built-in rate limit handling
- ✅ File Handling: Multipart uploads, encoding strategies, metadata support
- 🔲 Progress Tracking: Monitor long-running predictions
- 🔲 Concurrent Operations: Run multiple predictions in parallel
Quick Start
[]
= "0.1.0"
= { = "1.0", = ["full"] }
use ;
async
Configuration
Retry Configuration
The client includes built-in retry logic with exponential backoff for handling transient failures:
use ;
use Duration;
// Create client with custom retry settings
let retry_config = RetryConfig ;
let client = with_retry_config?;
// Or configure an existing client
let mut client = new?;
client.configure_retries?;
Timeout Configuration
Configure connection and request timeouts for better control over network operations:
use ;
use Duration;
// Configure timeouts on existing client
let mut client = new?;
client.configure_timeouts?;
// Create client with custom timeout and retry configuration
let http_config = HttpConfig ;
let client = with_http_config?;
// Disable timeouts (use with caution!)
client.configure_timeouts?;
File Uploads and Multipart Form Data
The library provides comprehensive file handling with multipart form data support for efficient file uploads:
Basic File Upload
use ;
use HashMap;
let client = new?;
// Upload file from bytes with metadata
let file_content = b"Hello, World!";
let mut metadata = new;
metadata.insert;
let uploaded_file = client.files.create_from_bytes.await?;
println!;
println!;
// Upload from local file path
let file = client.files.create_from_path.await?;
// Upload using FileInput abstraction
let file_input = from_bytes_with_metadata;
let file = client.files.create_from_file_input.await?;
File Management
// List all uploaded files
let files = client.files.list.await?;
for file in files
// Get file by ID
let file = client.files.get.await?;
println!;
// Delete file
let deleted = client.files.delete.await?;
assert!;
File Encoding Strategies
The library supports two file encoding strategies for use with predictions:
// 1. Multipart Upload (recommended for larger files)
let prediction = client
.create_prediction
.file_input_with_strategy
.input
.send
.await?;
// 2. Base64 Data URL (for smaller files < 1MB)
let prediction = client
.create_prediction
.file_input_with_strategy
.input
.send
.await?;
// Default strategy is Multipart
let prediction = client
.create_prediction
.file_input // Uses Multipart by default
.send
.await?;
File Input Types
// From URL (for reference, not upload)
let file_from_url = from_url;
// From local file path
let file_from_path = from_path;
// From bytes with metadata
let file_from_bytes = from_bytes_with_metadata;
// Simple bytes input
let file_simple = from_bytes;
Advanced File Operations
// Upload with custom metadata
let mut metadata = new;
metadata.insert;
metadata.insert;
metadata.insert;
let file = client.files.create_from_bytes.await?;
// Access file metadata
println!;
println!;
println!;
Contributing
We welcome contributions! Please see our Contributing Guide for details on:
- Development setup
- Code style and formatting
- Testing requirements
- Pull request process
- Issue reporting
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Replicate for providing the AI model platform
- replicate-python for API design inspiration
- The Rust community for excellent async and HTTP libraries
Status
🚧 This project is under active development. APIs may change before the 1.0 release.
Current status: Phase 4 - Production Features (60% complete)
Recent milestones:
- ✅ Phase 1: Core Infrastructure (100% complete)
- ✅ Phase 2: Core API Operations (85% complete)
- ✅ Phase 3: Advanced Features (80% complete)
- 🔄 Phase 4: Production Features - Retry logic ✅, Timeout configuration ✅
- ⏳ Phase 5: Polish & Release
For the latest updates, check our project milestones and issues.