An API is a contract between a system and its users or other components: it defines the interface through which they request functionality or exchange data. Design it carefully, because changing it can be costly even while the system is still under development. section 13.1
For an ML system, aim for simplicity and predictability. Hide unnecessary implementation details behind a few methods with a small number of parameters, so users can work with the system without understanding its internals. section 13.1 section 13.6
Listing 13.2 A better design for a predict function
def predict(features, time=None, seed=42):
if time is None:
time = datetime.now()
return model.predict(features, time, seed)
This predict interface lets callers supply a time and seed while providing defaults. Making these inputs available gives callers more control than hiding them inside the function. section 13.1
Practical ways to keep the contract usable as the system evolves:
- Separate external and internal API layers. Keep compatibility in mind for the external interface while retaining freedom to change unexposed internals. section 13.1.1
- Separate ML and input/output components where possible. They can then scale independently, and a new model component can be introduced for A/B testing or gradual rollout. section 13.1.1
- Provide a client library to lower the entry barrier and support debugging and experiments. It can also implement recommended retries and timeouts. section 13.1.1
- Consider feature toggles or an organizational alternative when operating in risky environments. section 13.1.1 section 13.6
An external API as a baseline
A third-party AI API can provide a baseline with zero or a few training samples. Comparing a specialized system against a major vendor’s offering can also help customers or investors understand its performance. section 8.4












































