liveBook · Manning

Contract

As explained in LLMs in Production

An API is a defined interface through which software applications request capabilities or data from another software system.

An API is the interface an application uses to request another system’s capabilities. For an LLM application, that might mean sending a message to a hosted model rather than deploying the model yourself. This is a fast, inexpensive way to test whether the model works for your use case before making a larger investment. section 1.2.1

Listing 1.1 A simple app calling OpenAI’s API
import os
from openai import OpenAI

client = OpenAI(                       #1
    api_key=os.getenv("OPENAI_API_KEY")         #2
)

chat_completion = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "Hello world"}],
)

The Python call shows a minimal request: configure an OpenAI client with an API key, select a model, and send a user message. section 1.2.1

Buying API access also buys access to a provider’s model expertise, safety controls, and supporting systems. The trade-off is dependence on that provider’s rules and continued access. A game built around a hosted LLM faced demands to filter player content or lose access—an operational risk when the API is central to the product. section 1.2.1 section 1.2.2

If you deploy your own LLM, the API becomes the application’s service boundary. Plan it before deployment: decide how requests reach the model, what preprocessing they need, and how the service supports interactive, batch, or streaming work. Batching, rate limiting, and streaming belong in that plan. A service keeps model logic out of each client pipeline, but adds communication latency. section 6.1

Figure 6.1 A basic LLM service. A majority of the logic is handled by the API layer, which will ensure the correct preprocessing of incoming requests is done and serve the actual inference of the request.
figure

The service diagram locates request preprocessing and inference in the API layer, rather than in each application that uses the model. section 6.1

How LLMs in Production covers it

How deep it goes
Shows a minimal client call and outlines service-planning concerns, without specifying a complete request schema or endpoint contract.
Examples
Uses a Python OpenAI chat-completion call, a hosted-model access dispute, and an LLM service architecture.
What it assumes
Uses basic Python for the client example and a trained or finetuned model as the starting point for deployment planning.
What you can do after
Evaluate/understand it by weighing hosted API access against ownership and planning an LLM service around requests and inference.
How it connects
Connects APIs to build-versus-buy decisions, model deployment, request preprocessing, batching, rate limiting, streaming, and retrieval-augmented generation.

Also explained in

Compare how 44 books explain contract →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of LLMs in Production. The section links point to the parts of the book it draws on.