A comprehensive Rust library providing type-safe, async interfaces to OpenAI APIs and advanced agent development capabilities. Build powerful AI applications with support for chat completions, embeddings, file operations, batch processing, and Model Context Protocol (MCP) integration.
🚀 Complete OpenAI API Coverage
- ✅ Chat Completions API - Full support for GPT models with streaming
- ✅ Embeddings API - Text embedding generation with multiple models
- ✅ Files API - Upload, retrieve, and manage files
- ✅ Batch API - Process requests in batches for cost optimization
- ✅ Response API - Advanced response handling with streaming support
- ✅ Model Context Protocol (MCP) - Integration with MCP servers
🔧 Developer Experience
- Type Safety - Fully typed Rust API with comprehensive error handling
- Async/Await - Built on tokio for high-performance async operations
- Streaming Support - Real-time streaming for chat and response APIs
- Flexible Authentication - Support for multiple OpenAI-compatible APIs
- Event Handling - Customizable event handlers for streaming data
🎯 Agent Development
- Tool Integration - Function calling and tool execution
- Memory Management - Built-in context and conversation management
- Error Recovery - Robust error handling and retry mechanisms
- Multi-Modal Support - Text, images, audio, and file inputs
Set up your environment:
export OPENAI_API_KEY="your-api-key-here"
The library provides comprehensive examples for all supported APIs. Check out the examples/
directory for complete, runnable code:
chat.rs
- Chat completions with streaming supportembedding.rs
- Text embeddings generationfile.rs
- File upload and managementbatch.rs
- Batch processing for cost optimizationresponse.rs
- Advanced response API with real-time streamingmcp.rs
- Model Context Protocol integration
Run any example with:
cargo run --example chat
cargo run --example response
cargo run --example embedding
# ... etc
The library is organized into several key modules:
-
api/
- Core API implementations for different OpenAI endpointschat.rs
- Chat completions API with streaming supportembedding.rs
- Text embeddings generationfile.rs
- File upload and managementbatch.rs
- Batch processing operationsresponse.rs
- Advanced response API with real-time streamingtype.rs
- Common types and utilities
-
http.rs
- HTTP client abstraction with retry logic and streaming -
mcp.rs
- Model Context Protocol integration -
tool.rs
- Function calling and tool execution framework -
agent.rs
- High-level agent abstraction (work in progress) -
error.rs
- Comprehensive error handling
- Type Safety - Leverages Rust's type system for compile-time correctness
- Async-First - Built on tokio for high-performance async operations
- Streaming Support - Real-time data processing with Server-Sent Events
- Modularity - Clean separation of concerns with trait-based design
- Compatibility - Works with OpenAI and OpenAI-compatible APIs
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes with tests
- Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
If you find this project helpful and would like to support its development, you can buy me a coffee!
Your support is greatly appreciated and motivates me to keep improving this project.
- Fiat
- Crypto
- Bitcoin
bc1pedlrf67ss52md29qqkzr2avma6ghyrt4jx9ecp9457qsl75x247sqcp43c
- Ethereum
0x3e25247CfF03F99a7D83b28F207112234feE73a6
- Polkadot
156HGo9setPcU2qhFMVWLkcmtCEGySLwNqa3DaEiYSWtte4Y
- Bitcoin
Thank you for your support!
We would like to extend our heartfelt gratitude to the following projects and contributors:
- The Rust community for their continuous support and development of the Rust ecosystem.
Special thanks to the following projects and technologies that make OpenAgent possible:
- OpenAI - For providing the foundational APIs and documentation
- Model Context Protocol - For the innovative protocol enabling tool integration
This project follows the principles of open-source development and aims to contribute back to the Rust ecosystem by providing a reliable, type-safe, and performant library for AI application development.
Licensed under GPL-3.0.