You tap “Summarize,” and a moment later a tidy summary appears. In between, your words left the app, crossed the internet, reached a company’s AI model and came back with an answer plus some bookkeeping. Knowing what happens in that gap makes provider documentation readable, explains why some apps show text word by word, and tells you where to look when something breaks.
In short: the app packages your text, its own standing instructions and a few settings into a structured message, then sends it over an encrypted web connection to the provider’s address for that job. The provider checks the credential attached to the message and whether the account is within its limits. The model reads the input as small units called tokens and writes a reply one token at a time until it reaches a natural end or a length cap. A response then travels back carrying the output, counts of the tokens used, a reason the model stopped and an identifier for the exchange [1, 2, 3, 4]. Each request is a self-contained round trip; the model keeps no memory of the last one unless the app sends the earlier conversation again or uses an optional provider feature that stores it [5, 3, 6].
This is the fourth guide in BuildAIQ’s path through AI APIs. What an AI API is covers the basic idea, and the parts behind an AI feature maps the pieces this guide now sets in motion.
TL;DR
- A request is a labeled package: an address (the endpoint), a method (POST), headers carrying the credential and format, and a JSON body naming the model, instructions, input and settings such as a length cap [1, 2, 3, 4].
- The provider checks before the model writes. A bad credential or an exceeded limit comes back as an error code, not an answer [7, 8].
- The model builds the answer token by token and usually stops at a natural end or at the cap the app set, though providers list other stop reasons too [9, 3, 2].
- The response carries more than text: token usage counts, a stop reason or status, and an ID used for troubleshooting [2, 3, 4].
- Streaming changes when you see the answer, not what the request is. The same request can return everything at once or in pieces as it is generated [10, 11].
- Field names differ by provider, so read each provider’s reference rather than assuming one format [2, 3, 4].
A Few Terms Before We Start
An API (application programming interface) is a published set of rules one program uses to ask another for something. A request is the message the app sends; a response is the message that comes back. On the web, both follow HTTP, whose standard describes a client sending a request with a method and a target address, optionally with header fields and content, and a server answering with a response that always includes a status code [1]. HTTPS is the encrypted form of HTTP.
An endpoint is the specific web address of one API function, such as “generate a reply.” A method is the kind of request; POST asks the server to process the data enclosed in the request [1]. A header is a labeled line of information sent alongside the main content. An API key is a secret string that identifies the account or project making a request, usually sent in a header. JSON is a plain-text format for structured data, built from named fields and their values [12]. A token is the unit a model reads and writes; for Gemini models, Google puts one token at about four characters, or 100 tokens at roughly 60 to 80 English words, a rule of thumb Google gives for Gemini only [13]. BuildAIQ’s guide to tokens explains them in depth.
The Example: A “Summarize This Note” Button (Hypothetical)
Imagine a note-taking app with a button that turns a long note into three bullet points. When someone taps it, the app’s own server, where the secret credential lives, builds the request and sends it to an AI provider. The example is invented; it describes no real product, and no values below come from a real exchange.
Step 1: The App Builds the Request
Where it goes: the endpoint and the method
Providers publish one endpoint per function, and the app copies it from their documentation. In this guide the address appears only as a placeholder, $AI_API_URL. OpenAI, Anthropic and Google all document their text-generation endpoints as POST requests, because the app is sending data for the provider to process [2, 3, 4].
What rides along: the headers
Two headers matter most. The first proves who is asking. The HTTP standard’s Authorization header exists so a client can authenticate itself to a server [1]. OpenAI expects the key as a “Bearer” credential in that header [14]. Anthropic’s API overview, as of Nov 22, 2026, also lists an Authorization Bearer header, keeps an older x-api-key header as a supported fallback, and lists a version header as required [15]. Google’s Interactions API examples send the key in a header named x-goog-api-key [4].
The second header says what format the body is in. The Content-Type header names the media type of the content [1], and all three providers’ examples send application/json [15, 4, 2].
Illustrative headers, not any one provider’s exact set: Authorization: Bearer $AI_API_KEY and Content-Type: application/json.
The key belongs on the app’s server, never in browser or mobile-app code; OpenAI’s reference says not to expose it in any client-side code and to load it from an environment variable or key management service on the server [14]. The next guide, what an API key is and why to protect it, covers keys properly.
What’s inside: the JSON body
The body describes the job, usually in four parts.
- The model. Which of the provider’s models should answer; OpenAI’s reference calls this the model ID [2]. Choosing one is the subject of how to choose a model for a simple app.
- Standing instructions. Text the app sends with every request to shape the reply. OpenAI describes its
instructionsfield as a system (or developer) message inserted into the model’s context [2]. What these can and can’t control is covered in what a system prompt is. - The input. The user’s note, plus any earlier conversation the app wants the model to see [2, 3].
- Settings. All three providers’ references reviewed here offer a cap on answer length, measured in tokens, and Anthropic’s makes it required [2, 3, 4]. In OpenAI’s Responses API the cap counts both visible output and reasoning tokens [2].
Illustrative request body. Its field names match OpenAI’s Responses API as documented on Nov 22, 2026; other providers use different names, as the table further down shows [2]:
{"model": "MODEL_NAME", "instructions": "Summarize the note in three short bullet points.", "input": "NOTE_TEXT", "max_output_tokens": 300}
MODEL_NAME and NOTE_TEXT stand in for a real model name and the note itself. Apps that need the answer as data rather than prose can ask for a structured format; structured output explains how.
Step 2: The Request Crosses the Internet Over HTTPS
The app sends the package to the endpoint over HTTPS. Under the HTTP standard, a “secured” connection means the server has been authenticated as acting for the address the app asked for, and the communication has confidentiality and integrity protection acceptable to both sides [1]. In plain terms, HTTPS is designed to let the app confirm which server it reached and to protect the request from being read or altered on the way. That covers the trip only; what happens to the data on arrival depends on the provider’s terms (see Step 5).
Step 3: The Provider Checks the Key and the Limits
The provider also decides whether to accept the request at all, and two of its checks have documented errors. Google returns a 401 when the key is missing, invalid or expired, and OpenAI returns one for invalid authentication or an incorrect key [7, 8]. Both return a 429 when a usage limit is hit, but codes don’t map neatly to causes: OpenAI also uses 429 when prepaid credit runs out, while Google returns a separate 402 for that [7, 8]. In those cases the app gets an error message and no answer.
What happens inside after a request is accepted, such as queuing or routing, isn’t laid out step by step in the documentation reviewed for this guide. How limits work, and how to stay under them, is the job of the guide to rate limits.
Step 4: The Model Reads Tokens and Writes the Answer
Text becomes tokens
The provider turns everything in the request into tokens: the instructions, the note and any earlier conversation. Google says all input to and output from its Gemini API is tokenized [13]. Anthropic adds that the API transforms the request into a format suited to the model, so the token counts it reports won’t match the visible text one-to-one [3].
One token at a time, until it stops
Large language models work by predicting tokens. Google’s machine learning course describes decoder-style models as generating new tokens from the text already generated [9]. The model picks a likely next token, adds it to the sequence, and repeats.
It stops for one of two common reasons. Either the model reaches what it treats as a natural end, or it hits the length cap the app set. Anthropic’s reference notes that its models may stop before reaching that maximum, since the setting is only an upper limit [3]. A cap that is too low can cut an answer off; OpenAI warns that a low cap can leave a response incomplete, even before any visible text appears [16].
The model starts fresh every time
HTTP itself is stateless: each request and response stands on its own [1]. OpenAI says each text generation request is independent and stateless, so multi-turn chats work by sending earlier messages along with the new one, though OpenAI also offers optional features that keep the conversation on its side [5]. Anthropic describes its Messages API as suited to single queries or stateless multi-turn conversations [3]. Google’s Interactions API can keep conversation state on Google’s side, but developers can also run it statelessly by sending the full history each time [6]. Either way, a chat that seems to remember you is the app resending context or an optional provider feature storing it. How much context fits in one request is the subject of BuildAIQ’s guide to context windows.
Step 5: The Response Comes Back
When the model finishes, the provider sends back a response: a status code saying whether the request worked, and a JSON body with the result. In all three providers’ references, the body carries four kinds of information [2, 3, 4].
- The output. The generated text, usually inside a list of content items [2, 3, 4].
- Token usage. How many tokens went in and how many came out. Anthropic says it bills and rate-limits by token counts [3], and Google says the cost of a call depends partly on input and output tokens [13]. What those counts cost is explained in how AI API pricing works.
- Why it stopped. Anthropic reports a
stop_reason, such as reaching a natural stopping point or hitting the requested maximum [3]. OpenAI reports a status such as completed or incomplete, with the reason in a separate field [2]. Google marks an interaction incomplete when, for example, it hits the token limit [4]. - An ID. A unique identifier for the response [2, 3, 4]. Separately, response headers carry a request ID that providers ask for in troubleshooting: x-request-id at OpenAI and request-id at Anthropic [14, 15].
Illustrative response body, a blend of field names from different providers rather than any one provider’s exact format (the counts are made up):
{"id": "RESPONSE_ID", "status": "completed", "output_text": "SUMMARY_TEXT", "stop_reason": "end_of_answer", "usage": {"input_tokens": 410, "output_tokens": 55}}
Before showing the summary, the app should check the status; OpenAI advises checking the response status before using a partial answer [16]. And a successful status means the request worked, not that the summary is accurate; checking whether an AI answer is correct is a separate job.
Some providers also keep a copy by default. In OpenAI’s Responses API, storing the response is on unless the app turns it off, and stored data is kept for at least 30 days, subject to OpenAI’s stated exceptions [2]. Google’s Interactions API stores interactions by default, for 55 days on its Paid Tier (a default that Paid Tier projects can shorten) and 1 day on its Free Tier, and lets developers opt out with a setting [6]. Both facts come from the providers’ pages as of Nov 22, 2026, cover only those APIs, and say nothing about other products or about other providers, whose terms this guide didn’t check [2, 6].
Waiting for the Whole Answer or Streaming It
By default, OpenAI generates the model’s entire output before sending it back as a single response [10]. For a long answer, the screen can sit blank until the last token is written.
Streaming changes the delivery. With a stream setting turned on, the provider sends the output in pieces as it is generated, so the app can start showing text while the rest is still being written [10]. OpenAI, Anthropic and Google all document a stream option that uses server-sent events [2, 3, 11], a web standard that lets a server push data to a client over an open HTTP connection [17].
OpenAI’s latency guide names the two waits that matter. Time to first token is how long a request takes to start returning content; end-to-end latency is how long the user waits for the complete result [16]. Streaming mainly shortens the first. Both grow with the size of the job: OpenAI says a long prompt can delay the first token, and that when an answer starts quickly but takes too long to finish, the thing to inspect is what the model generates [16].
Same Journey, Different Field Names
Every provider follows the same broad steps, but the labels differ. The table below shows three examples from the providers’ API references, read on Nov 22, 2026 [2, 3, 4]. It is not an endorsement or a ranking, and other providers use other formats.
| Part of the request | OpenAI Responses API [2] | Anthropic Messages API [3] | Google Interactions API [4] |
|---|---|---|---|
| Standing instructions | instructions | system | system_instruction |
| Input | input | messages | input |
| Length cap | max_output_tokens | max_tokens (required) | max_output_tokens inside generation_config |
| Where the output sits | output | content | steps |
| Why it stopped | status and incomplete_details | stop_reason | status |
| Usage counts | input_tokens, output_tokens | input_tokens, output_tokens | total_input_tokens, total_output_tokens |
Google calls the Interactions API generally available as of June 2026 and recommended for new projects, and describes its older generateContent API as legacy but still fully supported, so older tutorials may show different names [6]. SDKs, the ready-made code libraries providers publish, hide some of these details but call the same API underneath. A no-code tool’s HTTP step sends this same kind of request; connecting an API to a no-code tool walks through that route.
When the Response Is an Error Instead
Every HTTP response carries a three-digit status code, and the first digit gives the class: 2xx means the request was received and accepted, 4xx means a problem with the request itself, and 5xx means the server failed on a request that looked valid [1]. The standards define Step 3’s two codes as a request lacking valid credentials (401) and too many requests in a given time (429), and providers add their own causes on top [1, 18, 7, 8]. Working out what a particular error means, and whether to try again, belongs to what to do when an AI API stops working.
What the Documentation Shows and Where It Stops
The outside of the journey is well documented: the HTTP and JSON standards define the envelope [1, 12], and each provider’s reference defines its own fields, errors and streaming format [2, 3, 4]. The three references describe the same sequence under different names.
The inside is thinner. The pages reviewed for this guide don’t publish the order of server-side checks, how requests are queued or routed, or typical timings, and OpenAI’s own guidance treats latency as something to measure by model and task [16]. So this guide gives no timing figures.
Practical Takeaways
- Read a provider’s API reference in request order: endpoint and method, required headers, body fields, then the response fields and error list.
- Keep the key on your server. A request built in browser or mobile-app code exposes the credential to anyone who looks [14].
- Set a length cap deliberately and check the stop reason. A cap that is too low can leave an answer incomplete [16, 3].
- Log the request ID with each call, and the response ID too; OpenAI recommends logging request IDs, and Anthropic asks for the request ID when you contact support about a specific request [14, 15].
- Use streaming when people are waiting to read a long answer; it shortens the time to first text, not the total work [10, 16].
- Don’t carry one provider’s field names into another’s API. Check each reference and note when you checked it, since names and defaults change [6].
Sources
- RFC 9110: HTTP Semantics. IETF / RFC Editor, 2022-06, accessed 2026-11-22.
- Create a model response (Responses API reference). OpenAI, accessed 2026-11-22.
- Messages (Claude API reference). Anthropic, accessed 2026-11-22.
- Creating an interaction (Gemini Interactions API reference, v1). Google, accessed 2026-11-22.
- Conversation state. OpenAI, accessed 2026-11-22.
- Interactions API (overview). Google, accessed 2026-11-22.
- Error codes. OpenAI, accessed 2026-11-22.
- API errors (Gemini Interactions API). Google, accessed 2026-11-22.
- LLMs: What's a large language model? (Machine Learning Crash Course). Google for Developers, 2026-01-02, accessed 2026-11-22.
- Streaming API responses. OpenAI, accessed 2026-11-22.
- Streaming interactions (Gemini API). Google, accessed 2026-11-22.
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format. IETF / RFC Editor, 2017-12, accessed 2026-11-22.
- Understand and count tokens (Gemini API). Google, accessed 2026-11-22.
- API Overview (OpenAI API reference). OpenAI, accessed 2026-11-22.
- API overview (Claude API). Anthropic, accessed 2026-11-22.
- Latency optimization. OpenAI, accessed 2026-11-22.
- HTML Standard, section 9.2 Server-sent events. WHATWG, accessed 2026-11-22.
- RFC 6585: Additional HTTP Status Codes. IETF / RFC Editor, 2012-04, accessed 2026-11-22.
