Skip to content
Is there an AI for this?

FDE ACADEMY · MODULE 02 · LESSON 02

The API is an HTTP endpoint you can curl

Chat completions, streaming, structured output and the four failure modes worth designing for. The same interface whether the model is in the next rack or in someone else’s cloud.

Effort
Around ninety minutes, most of it waiting for a model to load.
Skills
api-integration · llm-inference

Free and self-paced. No certification is offered.

Before you startYou have read lesson 01 and can say what a context window is.


01One interface, several implementations

The OpenAI chat-completions shape has become the common interface: a list of messages, a model name, a handful of parameters, and either a response or a stream of chunks. Self-hosted servers implement it, gateways speak it, and most client libraries expect it. That is why a deployment can start on a hosted endpoint and move onto your own hardware without the application being rewritten — the base URL and the key change, and nothing else does.

Treat that as an architectural decision rather than a convenience. Anything in your stack that speaks a proprietary shape is a component you cannot swap when the constraint changes.


02The parameters that matter, and the ones that do not

Two knobs earn their place in most deployments. Temperature controls how much the sampling wanders; for extraction and classification you want it at or near zero, because you are not asking for creativity, you are asking for the same answer twice. The maximum output length is the other, because it is the difference between a truncated answer and a bill.

Structured output is the third thing to learn, and it changes how you build. Asking for JSON in the prompt and hoping is a parsing problem you will have forever; constraining generation to a schema turns it into a validation problem you can test. The extraction recipes on this site take the second route and their steps cite the server documentation for it.

  • Streaming is a user-experience decision, not a performance one — the total time is the same.
  • Put a key on the endpoint even on a private network. An unauthenticated model server is an open relay for your GPU.
  • A gateway earns its place as soon as two applications call the same model, for keys, quotas and logging in one place.

03Four failure modes to design for

Context overflow, when the prompt plus the requested output exceeds the window. Timeouts, when a long generation outlives the client’s patience. Rate limiting and queueing, when more requests arrive than the server can hold in flight. And malformed output, when the model returns something your parser did not expect.

Every one of them is normal operation rather than an incident, so handle each explicitly: count tokens before you send, set timeouts deliberately, back off on a queue, and validate every response against a schema before it reaches the rest of the system.


04Do this

PRACTICAL TASK

Serve a model and call it from the command line

Run the local serving recipe far enough to have an authenticated OpenAI-compatible endpoint, then exercise it: a normal call, a streaming call, a call that overflows the context, and one constrained to a schema.

What you need

  • A machine with a supported GPU, or a rented instance for the afternoon
  • Docker installed, and around 20 GB of disk for model weights

Steps

  1. 01

    Work through the local serving recipe up to and including the step that puts a key on the endpoint. Read each step’s linked documentation rather than only the summary.

    Local LLM serving — deployment steps

  2. 02

    Make one ordinary chat-completions request with curl. Read the response fields, including the token counts, and compare them with your estimate from lesson 01.

  3. 03

    Repeat it with streaming enabled and watch the chunks arrive. Note where you would put a first-token measurement.

  4. 04

    Deliberately overflow the context: send a prompt longer than the window and record exactly what the server returns. That message is what your application has to handle.

  5. 05

    Read the recipe’s measurement step and run it, so you have a latency figure of your own rather than a vendor’s.

    Measure before you promise anything

You are done when

  • A curl command returns a completion from an endpoint that refuses requests without your key.
  • You can quote your own tokens-per-second and first-token latency figures, and say under what concurrency you measured them.
  • You can state, from your own logs, what the server does when the context overflows.

05Where these facts live

This lesson does not restate anything that is already recorded with its evidence elsewhere on the site. These are the pages it leans on.

  • Local LLM serving

    Six steps from sizing to measurement, each grounded in the serving project’s own documentation.

  • LiteLLM

    The gateway pattern: one endpoint, many providers, keys and quotas in one place.

  • Call transcription and CRM notes

    A reference deployment that is mostly API calls between four services, with the boundary each crosses named.

Ticks are stored in your browser only. They are not sent anywhere, they are not attached to an account, and clearing your browser data removes them.