Skip to course content
Free FastAPI backend course

FastAPI for AI Backend Development

Module 13 Activity

Scenario

Put the model behind an interface so the service is testable and the vendor is replaceable.

What you build

A model client behind one interface, validated output, cost in the response, and pre-checks that refuse before spending.

Steps

  1. Define the model call as an interface and provide a real and a fake implementation.
  2. Override it in tests so the whole suite runs offline, and make the real one fail loudly without configuration.
  3. Validate the model's output against a schema before returning it, and decide the status when it fails.
  4. Return cost, latency and versions in a meta block.
  5. Implement pre-checks - empty input, over-length, sensitive content, budget - that refuse before any spend.
  6. Confirm sensitive input never reaches the provider or your logs.

Evidence to hand in

Review checklist