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.

Suppose you ask an assistant to suggest an outfit for today. To make a useful suggestion, it may need the local weather and your calendar. An application programming interface, or API, is a defined way for software to access another system’s capabilities. If the assistant is given access to weather and calendar information, it can use those sources as steps toward an answer; without that access, it cannot retrieve them. section 6.7

An API can also give an AI agent a tool to act beyond conversation. A travel assistant might use external services to find recommendations, while a payment API could enable a purchase. Access alone does not make the action reliable: an assistant might suggest a flight that does not exist or misunderstand what the traveler wants. Those risks matter more when it can make a payment than when it merely offers advice. section 6.7

Using an API well involves choosing the right tool, supplying an input it accepts, and making use of its result. In Toolformer, a language model was trained with examples of API calls and their responses. Calls were marked with special tokens, and training examples were filtered to favor calls that helped predict an answer. This taught the model when and how to use a small set of tools; it did not make every possible tool call necessary or trustworthy. 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”

The sample calls show that an API’s expected input and returned output depend on the tool: a calculator accepts an expression, while the calendar example takes no input and returns a date. section 8.11

How Introduction to Generative AI, Second Edition covers it

How deep it goes
Explains API use through inputs, outputs, and Toolformer’s training process, without specifying how to implement an API.
Examples
Uses weather and calendar access, travel recommendations, a possible payment API, and calculator, search, and translation tools.
What you can do after
Evaluate/understand when an assistant needs API access and why access alone does not ensure a reliable action.
How it connects
Links APIs to AI agents, external data, tool use, and language-model training.

Also explained in

Compare how 44 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.