Code Interpreter API
Introduction
LibreChat’s Code Interpreter API provides a secure and hassle-free way to execute code and manage files through a simple API interface. Whether you’re using it through LibreChat’s Agents or integrating it directly into your applications, the API offers a powerful sandbox environment for running code in multiple programming languages.
Subscription
Access to this feature requires an API subscription, get started here.
Getting Started
- Visit code.librechat.ai to get your API key
- Integrate the API into your application or use it through LibreChat
- Start executing code and generating files securely
Key Features
Supported Languages
Execute code in multiple programming languages:
- Python, Node.js (JS/TS), Go, C/C++, Java, PHP, Rust, Fortran
Seamless File Handling
- Upload files for processing
- Download generated outputs
- Secure file management
- Session-based file organization
Security & Convenience
- Secure sandboxed execution environment
- No local setup required
- No server deployment needed
- No configuration management
Using the API
In LibreChat
The API has first-class support in LibreChat through two main methods:
-
AI Agents: Enable Code Interpreter in your agent’s configuration to allow it to execute code and process files automatically.
-
Manual Execution: Use the “Run Code” button in code blocks within the chat interface, as shown here:
To set up your API key:
a. Per-user setup: input your API key in LibreChat when prompted (using the above methods)
b. Global setup: use LIBRECHAT_CODE_API_KEY
environment variable in the .env file of your project (provides access to all users)
Direct API Integration
The Code Interpreter API can be integrated into any application using a simple API key authentication:
- Get your API key from code.librechat.ai
- Include the API key in your requests using the
x-api-key
header
Core Functionality
Code Execution
- Run code snippets in supported languages
- Receive stdout/stderr output
- Get execution statistics (memory usage, CPU time)
- Handle program arguments
- Access execution status and results
File Operations
- Upload input files
- Download generated outputs
- List available files
- Delete unnecessary files
- Manage file sessions
Limitations
- Code cannot access the network
- Only 10 files can be generated per run
- Generated files are limited to 10MB in size
- Max execution time is 15 seconds
- Max memory usage is 250 MB
- Higher limits are planned for premium subscriptions (Enthusiast, Pro, Enterprise)
Use Cases
- Code Testing: Test code snippets in multiple languages
- File Processing: Transform and analyze files programmatically
- AI Applications: Execute AI-generated code securely
- Development Tools: Build interactive coding environments
- Objective Logic: Verify code logic and correctness, improving AI models
Why a Paid API?
While LibreChat remains free and open source under the MIT license, the Code Interpreter API is offered as a paid service for several key reasons:
-
Project Sustainability: Subscribing to an API plan provides direct support to the project’s development, even more effectively than GitHub Sponsors. Your subscription helps ensure LibreChat’s continued growth and improvement.
-
Technical Considerations: Including code execution capabilities in the core project would add significant complexity and hardware requirements that not all users need. The API service eliminates these concerns while maintaining a lightweight core application.
-
Managed Service Benefits:
- No complex configuration
- Immediate availability
- Regular updates and maintenance
- Professional support
- Secure, sandboxed environment
-
Intellectual Property Protection: The Code Interpreter’s architecture represents significant innovation in secure, scalable sandbox technology. While similar solutions exist, they often lack the comprehensive security measures and scalability features that make this implementation unique. Keeping this component as a closed-source API helps protect these innovations and ensures the service maintains its high security and performance standards.
Even if you only use code execution occasionally, subscribing helps support LibreChat’s development while enhancing your experience with professional-grade features. It’s a win-win that keeps the core project free while offering optional advanced capabilities for those who need them.
Conclusion
The Code Interpreter API provides a secure, convenient way to execute code and manage files without the hassle of setting up and maintaining execution environments. Whether you’re using it through LibreChat’s Agents or integrating it directly into your applications, it offers a robust solution for code execution needs.
For detailed technical specifications and API reference, please visit our API Documentation.
#LibreChat #CodeExecution #API #Development