Python FastAPI API
A FastAPI todo service gives you generated API docs, request validation, a health check, and routes for listing or adding todos. Tokay runs it at a live URL as one Web Service.
Last updated
AI agent? Start with llms.txt.
This example matches a normal FastAPI project. Tokay analyzes the source and requirements.txt to detect the FastAPI start command and dependencies.
- Runtime
- Python
- Framework
- FastAPI
- Service types
- Web Service
- Resources
- None
- Required secrets
- None
What it does
Open /docs to explore every route and send requests from FastAPI's interactive page.
The todo list begins with three samples. Add a nonempty title and the API returns a new item. Empty or oversized titles are rejected before they reach the list.
The root response shows the Python version. /health returns a compact liveness result.
Deploy it
Bring this folder to Tokay any way you like. Paste or upload it in the dashboard, push it with git, or hand it to your AI agent along with our agent instructions. Tokay figures out the rest.
Working in Claude, ChatGPT, VS Code, or another MCP client? Connect the Tokay MCP server and ask your agent to deploy this example. It signs in through your browser, so there is no token to paste.
New to Tokay? The getting started guide walks you through your first deploy.
Try it
Set your live URL, create one todo, then confirm FastAPI saved it in the running process.
export APP_URL="https://your-app.tokay.app"
curl -X POST "$APP_URL/todos" \
-H 'Content-Type: application/json' \
-d '{"title":"ship the next thing"}'
curl "$APP_URL/todos"
The response list now includes your todo. Restart or deploy again and the samples return because this small starter has no database.
How it works
FastAPI and Pydantic generate the API docs and validation from the route and model definitions in main.py. Tokay installs the requirements and starts the app without changing its structure.
Secrets
This starter has no secrets. Every endpoint is ready to try after deployment.
Grow from here
Try the AI research queue when your FastAPI app needs saved jobs and a Background Worker.
Source code
main.py Raw
import platform
from typing import Annotated
from fastapi import FastAPI
from pydantic import BaseModel, StringConstraints
app = FastAPI(title="Tiny Todo API")
todos = [
{"id": 1, "title": "deploy this ✓"},
{"id": 2, "title": "add a database"},
{"id": 3, "title": "tell a friend"},
]
class TodoInput(BaseModel):
title: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1, max_length=200)]
@app.get("/")
def hello():
return {
"message": "Hello from FastAPI",
"runtime": f"Python {platform.python_version()}",
}
@app.get("/health")
def health():
return {"ok": True}
@app.get("/todos")
def list_todos():
return todos
@app.post("/todos", status_code=201)
def create_todo(todo_input: TodoInput):
todo = {"id": todos[-1]["id"] + 1 if todos else 1, "title": todo_input.title}
todos.append(todo)
return todo
requirements.txt Raw
fastapi==0.116.1
uvicorn[standard]==0.35.0
Built from revision 2b22698