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. Hand it to your AI assistant, drag the unzipped folder in under Add code, or push it with Git. Tokay figures out the rest.

Haven't connected your assistant yet? Set it up once, then ask it to deploy this example. Agents can use Tokay MCP at https://mcp.tokay.io/mcp or the Tokay API, and our agent instructions cover both.

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.

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 259b82f

Guide: Deploy a FastAPI app