Skip to content

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.)

Terminal window
mkdir -p ~/tmp/genkit-fastapi-project
cd ~/tmp/genkit-fastapi-project
uv init
uv add genkit genkit-plugin-google-genai fastapi uvicorn

Create flows.py:

flows.py
from genkit import Genkit
from 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.text

Create main.py:

main.py
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from 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}
Terminal window
export GEMINI_API_KEY=<your API key>
uv run uvicorn main:app --reload --port 8000

Or with the Developer UI:

Terminal window
export GEMINI_API_KEY=<your API key>
genkit start -- uv run uvicorn main:app --reload --port 8000

Invoke the endpoint:

Terminal window
curl -X POST "http://127.0.0.1:8000/joke" \
-H "Authorization: Bearer open-sesame" \
-H "Content-Type: application/json" \
-d '{"topic":"bananas"}'

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)