The GravixLayer SDK provides comprehensive file management capabilities, allowing you to upload, list, retrieve, delete, and access file content. This is useful for managing documents, datasets, and other files that can be used with AI models.
Public Preview: Gravix Layer is currently in Public preview. Features are experimental and may have issues or break as ongoing updates to API endpoints and models continue.
File management allows you to:
- Upload Files: Store documents, datasets, and media files
- List Files: View all uploaded files with metadata
- Retrieve Metadata: Get detailed information about specific files
- Access File Data: Two methods for different use cases:
content() - Read file content for processing in memory
download() - Download files to disk with enhanced metadata
- Delete Files: Remove files to manage storage
Prerequisites
Before managing files, you need to set up your API key:
API Key Required: You must export your GravixLayer API key in your terminal before using file operations. All file operations are tied to your API key and account.
Set your API key:
Windows (CMD)
Windows (PowerShell)
Linux/macOS
set GRAVIXLAYER_API_KEY=your_api_key_here
$env:GRAVIXLAYER_API_KEY="your_api_key_here"
export GRAVIXLAYER_API_KEY=your_api_key_here
Quick Start
Here’s a simple example to get you started with file uploads:
Python SDK
JavaScript SDK
from gravixlayer import GravixLayer
client = GravixLayer()
# Upload a file
with open("document.pdf", "rb") as file:
upload_response = client.files.create(
file=file,
purpose="batch"
)
print(f"File uploaded: {upload_response.id}")
print(f"Filename: {upload_response.filename}")
import { GravixLayer } from 'gravixlayer';
import { readFileSync } from 'fs';
const client = new GravixLayer({
apiKey: process.env.GRAVIXLAYER_API_KEY,
});
// Upload a file
const fileBuffer = readFileSync("document.pdf");
const uploadResponse = await client.files.create({
file: fileBuffer,
purpose: "batch",
filename: "document.pdf"
});
console.log('✅ File uploaded successfully!');
console.log(`Filename: ${uploadResponse.filename}`);
Supported File Types
File Purposes
| Purpose | Description | Use Cases |
fine-tune | Files for model fine-tuning | Training datasets, JSONL files |
batch | Files for batch processing | Bulk inference data |
vision | Image files for vision models | PNG, JPG, JPEG, GIF, WEBP |
user_data | User-specific data files | Personal documents, datasets |
evals | Evaluation and testing files | Test datasets, benchmark data |
| Category | Extensions |
| Documents | PDF, TXT, DOCX, MD |
| Images | PNG, JPG, JPEG, GIF, WEBP |
| Data | JSON, CSV, JSONL |
| Code | PY, JS, HTML, CSS, TS |
File Expiration
File Expiration with --expires-after:
- The
--expires-after parameter accepts time in seconds
- Default behavior: Files have no expiration limit when this parameter is not specified
- Expired files return 404 Not Found when accessed
File Access Methods
The SDK provides two methods for accessing file data:
| Method | Purpose | Best For |
content() | Read file content for processing in memory | Data analysis, parsing, processing |
download() | Download file to disk with enhanced metadata | Saving files locally |
Both methods return the same file data as bytes (Python) or Buffer (JavaScript), but serve different use cases.