Generative AI · Intermediate level

Intermediate level · Module 4 of 10 · 10 guided hours

Building Applications with LLM APIs

Calling models from Python through one provider-independent interface (scripted practice model, local Ollama, hosted APIs), with safe keys, streaming, errors, retries, rate limits and cost estimation.

Learning objectives

  • Call hosted and local models through one interface
  • Handle keys, errors, retries and rate limits
  • Estimate and control costs

Topics

  • provider-independent interface
  • hosted vs local backends
  • API keys and configuration
  • streaming responses
  • errors, retries and rate limits
  • cost estimation

Lessons

  1. Lesson 1 One Interface, Many Backends

    Learners write a small generate() interface with a scripted practice model, a local Ollama backend and a hosted backend, so that application code never depends on one provider.

    adapter patternscripted practice modelOllama REST APIhosted provider APIconfiguration

  2. Lesson 2 Keys, Streaming, Errors and Rate Limits

    Learners keep keys out of code, stream long responses to users, and handle timeouts, provider errors and rate limits with retries.

    environment variables.gitignorestreamingtimeouts and retriesHTTP 429

  3. Lesson 3 Estimating and Controlling Cost

    Learners estimate cost per request and per month from token counts and prices, compare model options and apply simple savings.

    cost per requestinput vs output tokensmonthly estimateprompt trimmingsmaller or local models

Practical activity

Build the project's provider-independent model interface with secure keys, streaming, error handling and a cost estimate for three model options.

Expected outcomes

  • Robust, affordable LLM API integration
  • Cost awareness

Assessment

Interface code with tests (70%) and cost estimate (30%).

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.