liveBook · Manning

Contract

As explained in Introduction to Generative AI, Second Edition

An application programming interface (API) is a defined programmatic interface through which software clients access a system's capabilities.

A travel assistant might recommend a flight but need access to a payment service to book it. An application programming interface (API) is a defined way for software to access another system’s capabilities. Its contract describes how to interact with that capability, including the inputs it accepts and the outputs it provides. section 6.7 section 8.11

For a language model, an API can provide access to information or tools beyond the model itself. A calculator API, for example, takes a mathematical expression and returns a result. A calendar API can return the current date. Knowing what each tool expects helps the model decide how to call it and interpret the response. section 8.11

Table 8.1 Sample API tool calls and output formats [49]

API name

Example input

Example output

Question answering

“Where was the Knights of Columbus founded?”

“New Haven, Connecticut”

Wikipedia search

“Fishing Reel Types”

“Spin fishing > Spin fishing is distinguished between fly fishing and bait cast fishing by the type of rod and reel used. There are two types of reels used when spin fishing, the open-faced reel and the closed-faced reel.”

Calculator

“27 + 4 * 2”

“35”

Calendar

(none)

Today is Monday, June 30, 2025.

Machine translation

“sûreté nucléaire”

“nuclear safety”

Compare sample inputs and outputs for five tools, including search, calculation, and translation. section 8.11

Toolformer illustrates one way to teach a model to use APIs. Researchers annotated examples with tool calls, executed the calls, and supplied the results in a consistent format. They retained examples where the call helped predict the output, then fine-tuned the model on the resulting data. This helped it learn both how to call tools and when a call might be useful. section 8.11

An API connection can enable action, but access alone does not make an assistant reliable. A travel assistant might invent a flight or misunderstand a traveler’s preferences, making automatic payment risky even if a payment API is available. section 6.7

How Introduction to Generative AI, Second Edition covers it

How deep it goes
Explains tool inputs and outputs and the steps used to train Toolformer, without detailing API design.
Examples
Uses travel booking and payment, plus calculator, calendar, search, question-answering, and translation tools.
What you can do after
Evaluate how API access can extend an assistant while recognizing risks from incorrect recommendations or misunderstood preferences.
How it connects
Connects APIs to language models, AI agents, tool use, and fine-tuning.

Also explained in

Compare how 45 books explain contract →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Introduction to Generative AI, Second Edition. The section links point to the parts of the book it draws on.