The FastAPI plugin can be installed using poetry with the following command poetry add aineko-plugins-nodes-fastapi-server.
API Reference
aineko_plugins.nodes.fastapi_server.FastAPI
Bases: AbstractNode
Node for creating a FastAPI app with a gunicorn server.
node_params should contain the following keys:
app: path to FastAPI app
port (optional): port to run the server on. Defaults to 8000.
log_level (optional): log level to log messages from the uvicorn server.
Defaults to "info".
To access the inputs and outputs from your FastAPI app, import the inputs
and outputs variables from aineko_plugins.nodes.fastapi_server. Use
them as you would use self.inputs and self.outputs in a regular node.
We recommend no more than 1 FastAPI node per pipeline since the Inputs and
Outputs objects are namespaced at the pipeline level.
A common use case with an API server is to check its operational health status. For Aineko specifically, it is useful to know if the pipeline and API node are operational as well. Aineko comes with a light weight helper function as follows:
Return the health status of the Aineko FastAPI server.
Health router can be imported by an Aineko FastAPI server and added
to the app as a router.
The health check endpoint is available via a GET request to the /health
route and returns a 200 response if the server is active.
For example, if the FastAPI app is running locally on
http://localhost:8000, the health check endpoint can be accessed via
a GET request query to http://localhost:8000/health.
Source code in nodes/aineko-plugins-nodes-fastapi-server/aineko_plugins/nodes/fastapi_server/health.py
101112131415161718192021222324252627282930313233
@health_router.get("/health",status_code=200)asyncdefread_health()->dict:"""Return the health status of the Aineko FastAPI server. Health router can be imported by an Aineko FastAPI server and added to the app as a router. The health check endpoint is available via a GET request to the `/health` route and returns a 200 response if the server is active. For example, if the FastAPI app is running locally on `http://localhost:8000`, the health check endpoint can be accessed via a GET request query to `http://localhost:8000/health`. Example usage in FastAPI app: ```python hl_lines="2 5" from fastapi import FastAPI from aineko_plugins.nodes.fastapi_server import health_router app = FastAPI() app.include_router(health_router) ``` """return{"status":"healthy"}
Authentication Considerations
By default, the /health endpoint does not contain authentication.
One method to add authentication is to use security middleware at the app level for FastAPI. This will handle adding authentication to the health endpoint without having to add custom dependencies.
For more information about security with FastAPI, check out the documentation here.