Integrating an LLM into an Application

Integrating an LLM into an Application is an intermediate-level course of 5 lessons (about 1 h 30 min), with 15 exercises and 15 quiz questions. Prerequisites: Intermediate Python (Functions, Modules, OOP). Exercises run in the browser, with nothing to install.

  • Generative AI
  • Intermediate
  • 5 lessons
  • 1 h 30 min
  • 15 exercises
  • Exercises run in the browser

The course in brief

This course teaches you to plug a large language model into a real application, without depending on a particular provider. You build requests, validate JSON outputs, let the model safely call your functions, stream responses, then control costs, limits, and logging. All exercises run in Python with a simulated, deterministic, testable model.

What you will be able to do

  • Build a chat request (roles, history, parameters) and read the response, including the stop reason and usage
  • Get a JSON output, validate it against a schema, and fix it with a bounded loop
  • Expose tools to the model and run them safely (allowlist, validation, permissions, confirmation)
  • Read a streamed response, relay it, and handle cancellation
  • Calculate and track token costs, and handle rate limits with bounded retries
  • Log every call in a usable way that respects personal data

Syllabus: 5 lessons

    • Build the message list (system, user, assistant) for a chat request
    • Read a model response: text, stop reason, and token consumption
    • Place the model call on the server side, never in the browser

    Calling a model APIMessages and rolesGeneration parameters

  1. 02

    Structured Outputs: Getting and Validating JSON

    20 min
    • Ask the model for a JSON output that conforms to a schema
    • Validate the output (types, required fields, allowed values) before using it
    • Set up a bounded correction loop for invalid output

    Structured outputsSchema validationCorrection loop

  2. 03

    Tool Calls: Letting the Model Use Your Functions

    20 min
    • Describe a tool (name, description, parameters) so that a model can request it
    • Execute a tool call safely: allowlist, argument validation, errors sent back to the model
    • Write the request → tool call → result → final answer loop with a step limit

    Tool calls (function calling)Tool-response loopTool security

  3. 04

    Streaming: Displaying the Response as It Is Generated

    15 min
    • Explain the benefit of streaming for perceived latency
    • Read an event stream (Server-Sent Events) and reconstruct the response
    • Handle cancellation, limits, and end of stream on the server side

    Response streamingServer-Sent EventsCancelling a generation

  4. 05

    Costs, Limits, and Logging

    20 min
    • Estimate and track the cost of an AI feature from token usage
    • Handle rate limits and temporary errors with bounded retries
    • Log every call in a usable way that respects personal data

    Token costRate limits and retriesCall loggingAI gateway

Final project

Reliable Server-Side Customer Support Assistant

For a fictional online store, build in Python the core of a support assistant with a simulated model. The assistant classifies each message into validated JSON (category, priority, need for a human), answers follow-up questions by calling an order-status tool restricted to the logged-in user, offers a product return only after confirmation, streams its responses with cancellation, and goes through a single gateway that handles retries, quotas, and usage events. Deliver a cost report based on a fictional price grid.

Deliverables

  • An executable Python module with a single gateway (call, retries, quota, logging)
  • The JSON classification schema, its validation, and the bounded correction loop
  • The declared tools (description, parameters) and their safe execution, with confirmation for the return
  • The streaming function with cancellation and a cap
  • An automated test suite using a simulated model (nominal and error cases)
  • A pandas report of costs and errors per feature

Assessment criteria

  • No call to the model is possible without going through the server-side gateway
  • Every model output (JSON, tool arguments) is validated before use
  • Temporary errors are retried in a bounded way and request errors are not
  • Sensitive actions require confirmation and respect the user's permissions
  • The logs make it possible to calculate costs and error rates without storing unnecessary personal data
  • The tests cover failure cases (invalid JSON, unknown tool, infinite loop, cancellation)

Frequently asked questions

Do I need an account with a model provider to take the course?

No. The exercises use a model simulated by a local, deterministic Python function, which lets you test the application's logic. The principles then apply to any service, in the cloud or hosted locally.

Is the course tied to a particular provider or SDK?

No. It presents the mechanisms common to most chat APIs (messages, structured outputs, tools, streaming, usage) using a neutral format. The exact field names vary by service and can be found in its documentation.

What level of Python do I need?

The level of the intermediate Python course (PY2): functions, dictionaries, exceptions, and a bit of pandas for the last lesson. No prior knowledge of AI is required.

Does the course cover model pricing?

It explains how cost is calculated (input and output tokens multiplied by the model's rates) with a fictional price grid. Real prices change often and are found in your provider's terms.

This course, told for your job

Say what you want to be able to do: “Integrating an LLM into an Application” takes its place in your path, with examples from your field. The concepts stay those of the course.

The preview is free, and you can take the courses one at a time without paying. The path only contains lessons from the catalogue.