Attaching the API Key
A free lesson from Swipe AI · Building With AI APIs, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
You already know the API key is a private credential that proves a request is really from you. In an actual request, the key isn't buried inside the payload alongside your prompt — it's attached to the request as its own separate piece, alongside the endpoint and the payload, so the provider can check who's asking before it even looks at what's being asked.
This separation matters: the provider checks the API key first, independent of the payload's contents. An invalid or missing key gets rejected before your prompt is ever read — authentication happens before anything about the actual request is considered.
Conceptual request with the key kept separate:
endpoint: ".../generate-text"
api_key: "sk-••••••••••••" <- checked first, on its own
payload: {
prompt: "List three uses for a spreadsheet.",
max_output_length: 80
}
If api_key is missing or invalid: request rejected — payload never even gets read.Where does the API key sit in a request, relative to the payload?
An invalid or missing API key gets a request rejected ____ the payload is ever read.
The API key is typically embedded inside the payload, as one of the prompt settings.
Free ai tools
Keep your streak going in Swipe AI
Swipe through every level of Building With AI APIs on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →