Package the Model Call as One Function

packaging for deployment

Part of: Ship & Monitor an LLM App (Capstone)

Every project you've built so far has been a script. You run it, you watch the terminal, you're done. Shipping is different. Someone else's browser or curl command hits a URL and your code has to answer without you standing next to it. The first move toward that is packaging. You pull every place that calls the model into one function with one job, so the rest of your app (a route, a CLI, a test) calls that function and never touches the API directly. What packaging means here Right now your model-calling code is probably scattered around: a system prompt in one spot, a client.messages.create(...) in another, some parsing after it. Packaging collects all of that into a single entry point, usually named something like handle request, that takes one plain dict in and returns one plain dict out. Everything downstream (a web route, a test, a CLI) calls this one function and never touches the Anthropic client. Why one entry point matters Every layer you add for the rest of this capstone wraps around handle request: the web route in the next lesson, the logger, the cost calculator, the budget guard. If your model call is scattered across five files, you patch five places every time you a

Challenge: Validate the Request Envelope