@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 pip/installed packages inside the decorated function body, not at the top of your file. This ensures imports happen on the remote worker. This rule applies to installed packages only; local project modules can be imported at the top of the file because Flash ships their source (see Import local modules). Correct: imports inside the function.System dependencies
Usesystem_dependencies to install system-level packages (via apt):
Import local modules
Your endpoint can import local (non-pip) Python modules that live alongside it in your project, such as a siblingutils.py file or a helpers/ package. Flash detects these imports, follows them transitively, and ships the module source to the worker for you, so an import like import utils or from helpers import load works remotely with no extra configuration.
Flash resolves local imports whether they appear at the top of the file or inside the function body, and it supports absolute imports (import utils), relative imports (from . import helpers), and dynamic imports with a literal name (importlib.import_module("plugin")). It also pulls in the __init__.py files for any packages you import. Flash can’t resolve dynamic imports whose module name is computed at runtime, so it emits a warning, and you’re responsible for making those modules available on the worker.
Flash bundles only local project files. Standard library modules are already present in the worker image, and pip packages must still be declared through the dependencies parameter. This applies transitively: if a bundled local module imports a pip package at its top level, that package must still be declared in the dependencies of any endpoint that uses the module.
On flash build and flash deploy, local modules are bundled when they pass the ignore filter, and importing a local module that an ignore rule excludes (or one Flash can’t resolve) fails the build. See Local modules and the ignore filter for details.
Live execution size limit
When you run an endpoint live (calling an@Endpoint function directly, or during flash dev), Flash ships the resolved module source inline with the request. The combined source is capped at 8 MiB. If your local dependencies exceed this limit, deploy the app with flash deploy instead, which bundles local modules into the build artifact rather than the request payload. See Local module payload too large for the corresponding error.
Local modules in a parent directory
On the live execution path, Flash treats a module imported by absolute name from a parent directory as external and doesn’t ship it, which causes aModuleNotFoundError on the worker. For example, this happens with import shared when shared.py sits above your endpoint file. To avoid it, place your endpoint at or above its local dependencies, or use flash deploy, which resolves imports against the whole project directory.
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.