Skip to main content
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:
set GRAVIXLAYER_API_KEY=your_api_key_here

Quick Start

Here’s a simple example to get you started with file uploads:
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}")

Supported File Types

File Purposes

PurposeDescriptionUse Cases
fine-tuneFiles for model fine-tuningTraining datasets, JSONL files
batchFiles for batch processingBulk inference data
visionImage files for vision modelsPNG, JPG, JPEG, GIF, WEBP
user_dataUser-specific data filesPersonal documents, datasets
evalsEvaluation and testing filesTest datasets, benchmark data

Supported Formats

CategoryExtensions
DocumentsPDF, TXT, DOCX, MD
ImagesPNG, JPG, JPEG, GIF, WEBP
DataJSON, CSV, JSONL
CodePY, 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:
MethodPurposeBest For
content()Read file content for processing in memoryData analysis, parsing, processing
download()Download file to disk with enhanced metadataSaving files locally
Both methods return the same file data as bytes (Python) or Buffer (JavaScript), but serve different use cases.