1+ ---
2+ description: Librechat specific endpoints
3+ globs: "app/api/librechat.py"
4+ alwaysApply: false
5+ ---
6+ ## Base Path
7+
8+ All endpoints are prefixed with `/v1/librechat`
9+
10+ ## Endpoints
11+
12+ ### 1. Execute Code
13+ **Endpoint:** `POST /exec`
14+
15+ **Description:** Execute Python code in a secure sandbox environment
16+
17+ **Request Body:**
18+ ```json
19+ {
20+ "lang": "py", // Only Python is supported
21+ "code": "string", // The code to execute
22+ "files": [ // Optional
23+ {
24+ "id": "string",
25+ "name": "string",
26+ "size": "number" // Optional, defaults to 0
27+ }
28+ ]
29+ }
30+ ```
31+
32+ **Response:**
33+ ```json
34+ {
35+ "session_id": "string",
36+ "stdout": "string",
37+ "stderr": "string",
38+ "files": [ // Optional
39+ {
40+ "id": "string",
41+ "name": "string",
42+ "size": "number",
43+ "content_type": "string"
44+ }
45+ ]
46+ }
47+ ```
48+
49+ **Error Responses:**
50+ - `400`: Invalid request (unsupported language or invalid JSON)
51+ - `401`: Unauthorized
52+ - `422`: Validation error
53+ - `500`: Internal server error
54+ - `503`: Service unavailable
55+
56+ ### 2. Upload Files
57+ **Endpoint:** `POST /upload`
58+
59+ **Request:**
60+ - Content-Type: `multipart/form-data`
61+
62+ **Parameters:**
63+ - `file`: File (required)
64+ - `entity_id`: String (optional, form field)
65+
66+ **Headers:**
67+ - `user-id`: String
68+ - `x-api-key`: String
69+ - `user-agent`: String
70+
71+ **Response:**
72+ ```json
73+ {
74+ "message": "success",
75+ "session_id": "string",
76+ "files": [
77+ {
78+ "fileId": "string",
79+ "filename": "string"
80+ }
81+ ]
82+ }
83+ ```
84+
85+ **Error Responses:**
86+ - `400`: Bad request
87+ - `413`: File size too large
88+
89+ ### 3. Download File
90+ **Endpoint:** `GET /download/{session_id}/{file_id}`
91+
92+ **Path Parameters:**
93+ - `session_id`: String (required)
94+ - `file_id`: String (required)
95+
96+ **Response:**
97+ - Streaming response of the file content
98+
99+ **Error Responses:**
100+ - `404`: File not found
101+
102+ ### 4. List Files
103+ **Endpoint:** `GET /files/{session_id}`
104+
105+ **Path Parameters:**
106+ - `session_id`: String (required)
107+
108+ **Query Parameters:**
109+ - `detail`: String (optional)
110+ - When set to "summary", returns minimal file information
111+
112+ **Response:**
113+ ```json
114+ [
115+ {
116+ "name": "session_id/fileId",
117+ "lastModified": "ISO-8601 timestamp",
118+ "type": "string", // Only included if detail != "summary"
119+ "size": "number" // Only included if detail != "summary"
120+ }
121+ ]
122+ ```
123+
124+ **Error Responses:**
125+ - `400`: Bad request
126+
127+ ### 5. Delete File
128+ **Endpoint:** `DELETE /files/{session_id}/{file_id}`
129+
130+ **Path Parameters:**
131+ - `session_id`: String (required)
132+ - `file_id`: String (required)
133+
134+ **Response:**
135+ ```json
136+ {
137+ "message": "success"
138+ }
139+ ```
140+
141+ **Error Responses:**
142+ - `404`: File not found
143+
144+ ## Notes
145+
146+ 1. All file operations are session-based, requiring a valid session ID
147+ 2. Maximum file upload size is configured in the application settings
148+ 3. Only Python code execution is currently supported
149+ 4. All endpoints may return standard HTTP error codes for common failure cases
0 commit comments