Deploy to Any Platform
Prerequisites: make sure you’ve completed the Get Started guide.
This page shows one way to deploy a Python Genkit app to any platform: run a FastAPI server that calls your flows. (FastAPI is ASGI and works well on most Python hosting providers.)
1. Set up your project (uv)
Section titled “1. Set up your project (uv)”mkdir -p ~/tmp/genkit-fastapi-projectcd ~/tmp/genkit-fastapi-project
uv inituv add genkit genkit-plugin-google-genai fastapi uvicorn2. Define a flow
Section titled “2. Define a flow”Create flows.py:
from genkit import Genkitfrom genkit.plugins.google_genai import GoogleAI
ai = Genkit( plugins=[GoogleAI()], model='googleai/gemini-2.5-flash',)
@ai.flow()async def joke_flow(topic: str) -> str: response = await ai.generate( prompt=f'Tell a medium-sized joke about {topic}', ) return response.text3. Create a web server
Section titled “3. Create a web server”Create main.py:
from fastapi import Depends, FastAPI, HTTPException, statusfrom fastapi.security import HTTPAuthorizationCredentials, HTTPBearerfrom pydantic import BaseModel
from flows import joke_flow
app = FastAPI()security = HTTPBearer(auto_error=False)
class JokeRequest(BaseModel): topic: str
async def require_auth( credentials: HTTPAuthorizationCredentials | None = Depends(security),) -> None: # Optional: replace with real auth logic, or delete this dependency entirely. if credentials is None or credentials.credentials != 'open-sesame': raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail='not authorized', )
@app.get('/health')async def health() -> dict[str, str]: return {'status': 'ok'}
@app.post('/joke')async def joke(request: JokeRequest, _auth: None = Depends(require_auth)) -> dict[str, str]: text = await joke_flow(request.topic) return {'joke': text}4. Run the app
Section titled “4. Run the app”export GEMINI_API_KEY=<your API key>uv run uvicorn main:app --reload --port 8000Or with the Developer UI:
export GEMINI_API_KEY=<your API key>genkit start -- uv run uvicorn main:app --reload --port 8000Invoke the endpoint:
curl -X POST "http://127.0.0.1:8000/joke" \ -H "Authorization: Bearer open-sesame" \ -H "Content-Type: application/json" \ -d '{"topic":"bananas"}'5. Deploy the project
Section titled “5. Deploy the project”Deployment steps vary by provider, but generally you configure:
- runtime: Python 3.11+ (or your provider’s recommended version)
- start command:
uv run uvicorn main:app --host 0.0.0.0 --port $PORT - environment variables: set
GEMINI_API_KEY(and any other secrets)