@Endpoint, you’re marking it to run remotely on Runpod instead of your local machine:
run_model(data), Flash provisions a GPU on Runpod (or reuses an existing one), sends your function code and input to the worker, executes it, and returns the result to your local environment.
Each unique endpoint name creates one Serverless endpoint on Runpod with its own URL, scaling configuration, and hardware allocation. The endpoint manages workers that scale up and down based on demand.
Endpoint types
TheEndpoint class supports four distinct patterns.
Queue-based endpoints
Use@Endpoint(...) as a decorator for batch processing and async workloads. Each function gets its own endpoint with dedicated workers.
- Batch processing jobs
- Long-running computations
- Workloads that don’t need immediate responses
Load-balanced endpoints
UseEndpoint(...) as an instance with route decorators for HTTP APIs. Multiple routes share the same workers.
- REST APIs with multiple routes
- Low-latency request/response patterns
- Services requiring custom HTTP methods
Custom Docker images
Deploy pre-built Docker images (like vLLM or your own workers) and interact with them as a client:Existing endpoints
Connect to an already-deployed Runpod endpoint by ID:GPU vs CPU
Specifygpu= for GPU endpoints or cpu= for CPU endpoints. They are mutually exclusive.
GPU endpoints
gpu= nor cpu= is specified, GPU defaults to GpuGroup.ANY.
CPU endpoints
Worker scaling
Control how many workers run for your endpoint with theworkers parameter:
workers=(1, N) keeps at least one worker warm, avoiding cold starts.
Dependency management
Specify Python packages in thedependencies parameter. Flash installs these on the remote worker before executing your function.
Version pinning
Use standard pip syntax for version constraints:Import packages inside the function body
You must import packages inside the decorated function body, not at the top of your file. This ensures imports happen on the remote worker. Correct: imports inside the function.System dependencies
Usesystem_dependencies to install system-level packages (via apt):
Parallel execution
Endpoint functions are async. Use Python’sasyncio to run multiple operations concurrently:
- Batch processing multiple inputs
- Running different models on the same data
- Parallelizing independent pipeline stages
Environment variables
Pass environment variables using theenv parameter:
Environment variables are excluded from configuration hashing. Changing environment values won’t trigger endpoint recreation, making it easy to rotate API keys.
Persistent storage
Attach a network volume for persistent storage across workers. Each volume is tied to a specific datacenter. Flash uses the volumename to find an existing volume or create a new one:
Endpoint parameters
For a complete list of parameters available for theEndpoint class, see Endpoint parameters.
Working with jobs (client mode)
When usingEndpoint(id=...) or Endpoint(image=...), you get an EndpointJob object for async operations:
Next steps
Custom Docker images
Deploy pre-built Docker images with Flash.
Build API endpoints
Create production APIs with Flash apps.
Deploy applications
Deploy Flash applications for production.
Clean up endpoints
Remove development endpoints when done testing.