OpenAI Rust SDK
A comprehensive Rust SDK for the OpenAI API with integrated YARA-X rule validation testing. This library provides complete access to all OpenAI APIs including Chat, Assistants, Batch processing, and more, with special capabilities for testing AI models' ability to generate valid YARA rules.
Developed by Wyatt Roersma and Claude Code.
Features
✅ Complete OpenAI API Support
- Create, retrieve, cancel, and list batch jobs
- JSONL format support for batch requests
- Automatic retry and error handling
- Type-safe API interactions
✅ YARA-X Integration
- Real-time YARA rule validation using yara-x
- Feature detection (hex patterns, strings, regex, metadata)
- Performance metrics and complexity scoring
- Pattern testing against sample data
✅ Testing Framework
- Generate batch jobs with YARA-specific questions
- Validate AI-generated rules for correctness
- Built-in test suite with various rule types
- Comprehensive error reporting
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Environment Setup
Generate a Batch Job
Validate a YARA Rule
Run Test Suite
Usage Examples
Full Integration Example
use ;
Batch Processing Workflow
- Prepare Questions: Generate JSONL file with YARA-related questions
- Upload File: Use OpenAI Files API to upload the JSONL
- Create Batch: Submit batch job with file ID
- Monitor Progress: Poll for completion (up to 24 hours)
- Download Results: Retrieve generated YARA rules
- Validate Rules: Use yara-x validator to test correctness
Modern Responses API
The SDK now ships with a native client for the /v1/responses endpoints. You can access
the full feature set--including conversations, background execution, and structured
outputs--through the new builder and client helpers:
use StreamExt;
use ;
# block_on?;
Compatibility helpers such as generate_text, create_chat_completion, and
create_custom_response automatically route through the Responses API to maintain
the existing interface while unlocking new functionality.
Test Suites
The SDK includes three test suites for different complexity levels:
Basic Suite
- Simple string detection rules
- Basic PE file detection
- Error/warning pattern matching
Malware Suite
- Ransomware detection patterns
- Trojan indicators
- Cryptominer signatures
- Advanced malware techniques
Comprehensive Suite
- Complex multi-condition rules
- External variable usage
- Iterator patterns
- Module imports
- Performance-optimized rules
Project Structure
openai_rust_sdk/
├── src/
│ ├── lib.rs # Library entry point
│ ├── main.rs # CLI application
│ └── testing/
│ ├── mod.rs # Testing module exports
│ ├── yara_validator.rs # YARA-X validation
│ ├── test_cases.rs # Built-in test cases
│ └── batch_generator.rs # Batch job generation
├── examples/
│ └── full_integration.rs # Complete usage example
├── test_data/
│ ├── yara_x_questions.jsonl # Sample questions
│ └── simple_batch.jsonl # Basic test batch
└── tests/
└── integration_test.rs # Integration tests
CLI Commands
# Validate a single YARA rule
# Run the built-in test suite
# Generate batch job for basic testing
# Generate batch job for malware detection
# Generate comprehensive test batch
Testing with GPT-5-Nano
The SDK is configured to use gpt-5-nano for testing, which provides fast and cost-effective rule generation. Example batch request:
Validation Metrics
The validator provides comprehensive metrics:
- Compilation Status: Whether the rule compiles successfully
- Feature Detection: Identifies rule components (strings, hex, regex, etc.)
- Performance Metrics: Compilation time and complexity scoring
- Pattern Testing: Tests rules against sample data
- Error Reporting: Detailed error messages for invalid rules
Development
Building
Running Tests
Formatting & Linting
License
MIT
Contributing
Contributions are welcome! Please ensure all tests pass and code is properly formatted before submitting PRs.
Requirements
- Rust 1.89.0 or later
- OpenAI API key for batch processing
- yara-x crate for rule validation