LLM Auto Optimizer - Integrations
Production-ready integrations with external services for the LLM Auto Optimizer project.
Features
Jira Integration
Full-featured Jira REST API client with:
- Authentication: OAuth 2.0, Basic Auth, and Personal Access Tokens
- Issue Management: Full CRUD operations (Create, Read, Update, Delete)
- Project Management: List and query projects
- Board & Sprint Management: Agile board and sprint operations
- JQL Queries: Advanced search with Jira Query Language
- Webhook Support: Event-driven integration with signature verification
- Rate Limiting: Automatic rate limiting with configurable limits
- Retry Logic: Exponential backoff with configurable retry attempts
- Error Handling: Comprehensive error types and context
Anthropic Claude Integration
Full-featured Claude API client with:
- Authentication: API key authentication
- Multiple Models: Support for Claude 3.5 Sonnet, Opus, Sonnet, and Haiku
- Message API: Send and receive messages with system prompts
- Streaming: Real-time streaming responses via Server-Sent Events
- Token Management: Token counting, validation, and budget tracking
- Cost Tracking: Automatic cost calculation and statistics
- Rate Limiting: Per-tier rate limiting
- Retry Logic: Automatic retries for transient errors
- Error Handling: Detailed error responses and context
Installation
Add to your Cargo.toml:
[]
= { = "crates/integrations" }
# Optional: Enable only specific integrations
= { = "crates/integrations", = false, = ["jira"] }
Usage
Jira Client
Basic Authentication
use ;
async
Create an Issue
use ;
let request = CreateIssueRequest ;
let issue = client.create_issue.await?;
println!;
JQL Search
use JqlSearchRequest;
let request = JqlSearchRequest ;
let results = client.search_issues.await?;
println!;
for issue in results.issues
Webhooks
use ;
use async_trait;
;
let processor = new;
processor.register_handler.await;
// Process webhook payload
processor.process_event.await?;
Anthropic Client
Simple Completion
use ;
async
Advanced Message with System Prompt
use ;
let request = MessageRequest ;
let response = client.send_message.await?;
Streaming Responses
use ;
use StreamExt;
let stream_handler = new;
let mut stream = stream_handler.stream_message.await?;
let mut collector = new;
while let Some = stream.next.await
let response = collector.to_response?;
println!;
Token Management
use ;
let mut counter = new;
// Estimate tokens in text
let text = "Hello, world!";
let tokens = counter.count_text;
println!;
// Estimate cost for a request
let cost = counter.estimate_cost;
println!;
// Manage token budget
let mut budget = new?;
if budget.can_allocate
Architecture
Design Principles
- Type Safety: All API types are strongly typed with Serde support
- Error Handling: Comprehensive error types with context
- Async First: Built on Tokio for high-performance async operations
- Observability: Tracing integration for logging and monitoring
- Resilience: Automatic retries, rate limiting, and error recovery
- Testing: Comprehensive unit and integration tests
Module Structure
integrations/
├── src/
│ ├── jira/
│ │ ├── mod.rs # Module exports
│ │ ├── types.rs # Type definitions
│ │ ├── auth.rs # Authentication manager
│ │ ├── client.rs # Main API client
│ │ └── webhooks.rs # Webhook processor
│ ├── anthropic/
│ │ ├── mod.rs # Module exports
│ │ ├── types.rs # Type definitions
│ │ ├── client.rs # Main API client
│ │ ├── streaming.rs # Streaming support
│ │ └── tokens.rs # Token utilities
│ └── lib.rs # Library root
├── tests/
│ ├── jira_tests.rs # Jira integration tests
│ └── anthropic_tests.rs # Anthropic integration tests
├── Cargo.toml
└── README.md
Configuration
Environment Variables
# Jira
# Anthropic
Configuration Files
See config.example.yaml in the project root for configuration file examples.
Error Handling
All clients return anyhow::Result<T> for consistent error handling:
match client.get_issue.await
Rate Limiting
Both clients implement rate limiting to prevent API quota exhaustion:
- Jira: Configurable per-minute rate limit (default: 100 requests/minute)
- Anthropic: Tier-based rate limiting (default: 50 requests/minute)
Rate limiters use the token bucket algorithm with automatic backoff.
Testing
Run tests:
# All tests
# Specific integration
# With logging
RUST_LOG=debug
Performance
Both integrations are optimized for production use:
- Async I/O: Non-blocking operations with Tokio
- Connection Pooling: Reusable HTTP connections
- Response Caching: Configurable caching for frequently accessed data
- Batch Operations: Support for bulk operations where available
Security
- API Keys: Never logged or exposed in error messages
- TLS: All connections use HTTPS with certificate validation
- Webhook Signatures: HMAC-SHA256 signature verification for webhooks
- Input Validation: All inputs validated before API calls
Contributing
See CONTRIBUTING.md for guidelines.
License
Apache 2.0 - See LICENSE for details.
Support
- Documentation: docs.rs/integrations
- Issues: GitHub Issues
- Discussions: GitHub Discussions