# Day 12 - Feb 4 2026

Transition from running local Python scripts to hosting a production-ready API service.

### 1. Script vs. API

* Script: Runs once on my machine, does a job, and dies. Good for tasks.
* API: Runs forever (as a server), waiting for requests from the outside world. Good for products.

### 2. Why FastAPI?

I chose FastAPI over Flask or Django because:

* Speed: It's incredibly fast (comparable to NodeJS/Go).
* Async Native: Handles multiple requests at once (critical for AI apps that take time to generate text).
* Auto-Documentation: It automatically generates a `/docs` page using Swagger UI, so I don't have to write documentation manually.

### 3. The "Request/Response" Cycle

1. Client (Browser/App): Sends a `POST` request with a JSON body (`{"prompt": "Hello"}`).
2. Pydantic (Validator): Checks if the data is valid (Is "prompt" a string?). If not, it rejects it instantly.
3. Endpoint: My function receives the clean data, calls Ollama, and waits.
4. Response: The server wraps the AI's text in a JSON object and sends it back with a `200 OK` status.

### Status:

* [x] Installed FastAPI & Uvicorn
* [x] Defined Request Schema (Pydantic)
* [x] Tested API via Swagger UI (`/docs`)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://shankar-lab.gitbook.io/mylearning/15-days-genai-learning-challenge/day-12-feb-4-2026.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
