The Chute class is the core component of the Chutes framework, representing a deployable AI application unit. It extends FastAPI, so you can use all FastAPI features. This reference covers all methods, properties, and configuration options.
Docker image for the chute runtime environment (required).
Example:
# Using a string reference to a pre-built image
chute = Chute(
username="mycompany",
name="text-generator",
image="parachutes/python:3.12"
)
# Using a custom Image object
from chutes.image import Image
custom_image = Image(username="mycompany", name="custom-ai", tag="1.0")
chute = Chute(
username="mycompany",
name="text-generator",
image=custom_image
)
Optional Parameters
tagline: str = ""
A brief description of what the chute does.
Example:
chute = Chute(
username="mycompany",
name="text-generator",
image="parachutes/python:3.12",
tagline="Advanced text generation with GPT models"
)
readme: str = ""
Detailed documentation for the chute in Markdown format.
Example:
readme = """
# Text Generation API
This chute provides advanced text generation capabilities.
## Features
- Multiple model support
- Customizable parameters
- Real-time streaming
"""
chute = Chute(
username="mycompany",
name="text-generator",
image="parachutes/python:3.12",
readme=readme
)
standard_template: str = None
Reference to a standard template (e.g., "vllm", "sglang", "diffusion").
revision: str = None
Specific revision or version identifier for the chute.
node_selector: NodeSelector = None
Hardware requirements and preferences for the chute.
Utilization threshold at which to trigger scaling (0.0 to 1.0).
allow_external_egress: bool = False
Whether to allow external network connections after startup.
Important: By default, external network access is blocked after initialization. Set to True if your chute needs to fetch external resources at runtime (e.g., image URLs for vision models).
Example:
# For vision language models that need to fetch images
chute = Chute(
username="mycompany",
name="vision-model",
image="parachutes/python:3.12",
allow_external_egress=True
)
encrypted_fs: bool = False
Whether to use encrypted filesystem for the chute.
passthrough_headers: dict = {}
Headers to pass through to passthrough cord endpoints.
tee: bool = False
Whether this chute runs in a Trusted Execution Environment.
**kwargs
Additional keyword arguments passed to the underlying FastAPI application.
Decorators
Lifecycle Decorators
@chute.on_startup(priority: int = 50)
Decorator for functions to run during chute startup.
Signature:
@chute.on_startup(priority: int = 50)
async def initialization_function(self) -> None:
"""Function to run on startup."""
pass
Parameters:
priority: Execution order (lower values execute first, default=50)
0-20: Early initialization
30-70: Normal operations
80-100: Late initialization
Example:
@chute.on_startup(priority=10) # Runs early
async def load_model(self):
"""Load the AI model during startup."""
from transformers import AutoTokenizer, AutoModelForCausalLM
self.tokenizer = AutoTokenizer.from_pretrained("gpt2")
self.model = AutoModelForCausalLM.from_pretrained("gpt2")
print("Model loaded successfully")
@chute.on_startup(priority=90) # Runs late
async def log_startup(self):
print("All initialization complete")
Use Cases:
Load AI models
Initialize databases
Set up caches
Configure services
@chute.on_shutdown(priority: int = 50)
Decorator for functions to run during chute shutdown.
Signature:
@chute.on_shutdown(priority: int = 50)
async def cleanup_function(self) -> None:
"""Function to run on shutdown."""
pass
Example:
@chute.on_shutdown(priority=10)
async def cleanup_resources(self):
"""Clean up resources during shutdown."""
if hasattr(self, 'model'):
del self.model
print("Resources cleaned up")
API Endpoint Decorator
@chute.cord()
Decorator to create HTTP API endpoints. See Cord Decorator Reference for detailed documentation.
Basic Example:
@chute.cord(public_api_path="/generate", public_api_method="POST")
async def generate_text(self, prompt: str) -> str:
"""Generate text from a prompt."""
return await self.model.generate(prompt)
Job Decorator
@chute.job()
Decorator to create long-running jobs or server rentals. See Job Decorator Reference for detailed documentation.
Basic Example:
from chutes.chute.job import Port
@chute.job(ports=[Port(name="web", port=8080, proto="http")], timeout=3600)
async def training_job(self, **job_data):
"""Long-running training job."""
output_dir = job_data["output_dir"]
# Perform training...
return {"status": "completed"}
Properties
chute.name
The name of the chute.
Type:str
chute.uid
The unique identifier for the chute.
Type:str
chute.readme
The readme/documentation for the chute.
Type:str
chute.tagline
The tagline for the chute.
Type:str
chute.image
The image configuration for the chute.
Type:str | Image
chute.node_selector
The hardware requirements for the chute.
Type:NodeSelector | None
chute.standard_template
The standard template name if using a template.
Type:str | None
chute.cords
List of cord endpoints registered with the chute.
Type:list[Cord]
chute.jobs
List of jobs registered with the chute.
Type:list[Job]
Methods
async chute.initialize()
Initialize the chute by running all startup hooks. Called automatically when the chute starts in remote context.
await chute.initialize()
FastAPI Integration
Since Chute extends FastAPI, you can use all FastAPI features directly: