
An API contract is an agreed description of how a client calls a service: the route, authentication boundary, accepted request, possible responses, and rules for changing them. For a frontend built by one AI agent and a backend built by another, that agreement is the handoff. Both agents need the same version and a named owner before either treats a generated call as ready to ship. An interface description can be precise while its implementation is still wrong; runtime proof is a separate step.
This guide shows a small, illustrative account-settings agreement and the decisions around it. It is about making the handoff explicit. The priority is what the two builders agree to, who changes it, and what evidence lets a reviewer accept the integration.
Start with the user action, not a generated route
Suppose a signed-in person edits the display name on an account settings page. The frontend needs a way to save the name and show the resulting account record. The backend owns authorization and persistence. Before either agent writes code, record one route, the caller identity, request and response shapes, error behavior, and the version of the agreement. The example below is hypothetical. It is not an AppHandoff endpoint, customer deployment, or claim that any tool executed it.
The route is PATCH /v1/account/settings. A session bearer token identifies the person; the service derives the account from that identity rather than accepting an account ID from the browser. The request carries a string displayName. The server trims leading and trailing whitespace, then requires the normalized name to be 1–80 characters; a raw input longer than 80 characters can be valid after trimming. A successful response returns accountId, the normalized displayName, and updatedAt. The client must not use the response as permission to edit another account. The backend owner decides whether this route exists and documents the accepted behavior; the frontend owner confirms that the form can use it.
Write one reference both sides can read
OpenAPI describes HTTP interfaces in a programming-language-neutral format, including operations, parameters, request bodies, responses, and security requirements. The OpenAPI Specification defines that format. The compact JSON document below is a complete illustrative OpenAPI 3.1 description for this single operation. It specifies an agreement; it does not run the handler or prove that authorization works.
{
"openapi": "3.1.0",
"info": {
"title": "Illustrative account settings API",
"version": "1.0.1"
},
"servers": [
{
"url": "https://api.example.test",
"description": "Illustrative only; no service is deployed here"
}
],
"paths": {
"/v1/account/settings": {
"patch": {
"operationId": "updateOwnAccountSettings",
"summary": "Update the signed-in account display name",
"security": [
{
"sessionBearer": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"displayName"
],
"additionalProperties": false,
"properties": {
"displayName": {
"type": "string",
"description": "Raw string input. The server trims leading and trailing whitespace, then requires 1–80 characters; whitespace-only input fails with 400."
}
}
}
}
}
},
"responses": {
"200": {
"description": "Saved settings",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"accountId",
"displayName",
"updatedAt"
],
"additionalProperties": false,
"properties": {
"accountId": {
"type": "string"
},
"displayName": {
"type": "string",
"description": "Stored display name after trimming; length is 1–80 characters.",
"minLength": 1,
"maxLength": 80
},
"updatedAt": {
"type": "string",
"format": "date-time"
}
}
}
}
}
},
"400": {
"description": "Invalid display name",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"401": {
"description": "Missing or invalid session",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
},
"description": "For an authenticated caller, trim displayName before applying its 1–80 character limit. Return 400 for a normalized name outside that range; on 200, store and return the normalized name. Derive the account from the bearer session."
}
}
},
"components": {
"securitySchemes": {
"sessionBearer": {
"type": "http",
"scheme": "bearer"
}
},
"schemas": {
"Error": {
"type": "object",
"required": [
"code",
"message"
],
"additionalProperties": false,
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
}
}
}
}
}
}The document version is 1.0.1, and the reference for an actual team should be a stable repository path or revision URL, such as api/account-settings.openapi.json at a particular commit. The OpenAPI version says which syntax the file uses; info.version identifies this example agreement. Those are different numbers. Put the reference and owner on the work ticket so a later agent can see which revision the frontend implemented. A URL to a floating main branch alone cannot tell a reviewer what was agreed when work started.
Show the result and failure paths
For this illustration, a signed-in request sends Authorization: Bearer <session-token> and Content-Type: application/json. The request body below is valid JSON. The account ID is absent by design: selecting the account is a server-side authorization decision, not a client-controlled form field.
{
"displayName": "Avery Chen"
}A 200 response uses the normalized displayName and an ISO 8601 timestamp. These sample values show the response shape; no request was sent to a service.
{
"accountId": "acct_example_42",
"displayName": "Avery Chen",
"updatedAt": "2026-10-09T14:00:00Z"
}For a displayName that is empty or over 80 characters after trimming, the illustrative service returns HTTP 400 with a stable error code that the form can map to field feedback. A missing or invalid bearer token returns HTTP 401 and must not save anything. The response below is an example of the 400 body; the 401 body follows the same error schema with code UNAUTHORIZED and a suitable message. A real implementation must verify both outcomes, including the absence of a write after failed authentication.
{
"code": "INVALID_DISPLAY_NAME",
"message": "Display name must be 1 to 80 characters."
}The operation and field descriptions specify trim-before-length validation. The request schema checks that displayName is a string; it does not apply the normalized length rule to the raw input. The response schema bounds the stored, normalized name. JSON Schema alone does not execute trimming or authorization in a server. The agreed behavior needs executable checks against an implementation before either agent treats the handoff as verified.
The 1–80 limit counts Unicode code points, matching the response schema's character count; JavaScript string length counts UTF-16 code units and would reject some valid emoji names. A whitespace-only body { "displayName": " " } normalizes to empty and returns 400 with no stored value. One leading space plus 80 letters is 81 raw characters but trims to an accepted 80-character stored name. The executable illustration also checks 41 emoji (accepted), 80 emoji (accepted), and 81 emoji (rejected). It does not call a provider or prove persistence.
const assert = require('node:assert/strict');
function checkDisplayName(raw) {
assert.equal(typeof raw, 'string');
const normalized = raw.trim();
const characters = Array.from(normalized).length;
if (characters < 1 || characters > 80) {
return { status: 400, storedDisplayName: null };
}
return { status: 200, storedDisplayName: normalized };
}
const whitespaceOnly = checkDisplayName(' ');
const raw81 = ' ' + 'A'.repeat(80);
const trimmedTo80 = checkDisplayName(raw81);
assert.equal(raw81.length, 81);
assert.deepEqual(whitespaceOnly, { status: 400, storedDisplayName: null });
assert.deepEqual(trimmedTo80, { status: 200, storedDisplayName: 'A'.repeat(80) });
const emoji41 = checkDisplayName('😀'.repeat(41));
const emoji80 = checkDisplayName('😀'.repeat(80));
const emoji81 = checkDisplayName('😀'.repeat(81));
assert.deepEqual(emoji41, { status: 200, storedDisplayName: '😀'.repeat(41) });
assert.deepEqual(emoji80, { status: 200, storedDisplayName: '😀'.repeat(80) });
assert.deepEqual(emoji81, { status: 400, storedDisplayName: null });
console.log(JSON.stringify({ whitespaceOnly, trimmedTo80, emoji41, emoji80, emoji81 }));Assign the change decision
The backend owner publishes the proposed agreement with its version, path, method, auth rule, shapes, examples, and reference. The frontend owner reads and confirms the same revision before wiring the form. If the frontend needs a different field or status code, it records the requested change for the backend owner to accept or reject. Neither agent should quietly edit its own copy and assume the other side will follow. This is a coordination rule for the hypothetical team, not an automatic feature of OpenAPI.
Backward compatibility deserves an explicit decision. For this example, adding an optional response field can usually leave the existing client working if it ignores unknown fields, but the strict additionalProperties: false response schema above would reject that addition in schema-based validation. The team must choose: keep a closed response and revise the contract and client together, or permit extra response fields and validate the client’s tolerance. Renaming displayName, changing its type, or making a formerly optional request field required is a breaking change for callers; use a new version or an agreed migration window. Do not label a change safe merely because the server compiles.
The illustrated decision is to keep version 1 stable for this form: do not rename displayName or change the 200 and error shapes without a coordinated revision. A backend agent can propose a version 2 route for an incompatible change, but a reviewer should decide when the existing client can move. The reference in the ticket should then point to each accepted revision, not a verbal promise that the endpoint is “basically the same.”
Carry the agreement through an agent handoff
In AppHandoff, an agent writes the agreed interface into the ticket itself (its description and acceptance criteria), and the consuming agent reads the ticket and confirms it on the thread. The tool’s current rules and per-tool help are authoritative for exact operation fields; this article does not provide copy-and-paste tool arguments. AppHandoff does not discover an API from the repository, publish a contract from code, or test a service automatically. The agents supply and confirm the information. Start with the MCP server guide for the connection and tool surface, then use the shared work board guide to understand how the work stays visible.
A useful ticket states “Account settings form needs PATCH /v1/account/settings” and links the accepted revision. The backend agent owns the route and auth checks; the frontend agent owns the form and error display. Each reports the relevant proof, and a reviewer can decide whether the integration is ready. That explicit ownership is especially useful when agents work in different repositories or sessions: a generated call may look plausible without any service that accepts it. See the AI coding agent handoff guide for the wider context of passing work between agents.
Verify the handoff before calling it done
A reference file and a confirmation make the intended interface legible. They do not prove that the service enforces it. An OpenAPI parser can check document syntax; schema validation can check example shape; neither observes a real authorization boundary. Consumer-driven tools such as Pact can help check expectations between consumer and provider when a team sets up and runs those checks. Keep the evidence attached to the exact revision under review and state which environments were exercised.
Use this short verification checklist for the illustrative account-settings change:
- Reference: record accepted OpenAPI agreement 1.0.1 at an exact file revision, backend owner, frontend owner, and the version 1 compatibility decision. Both agents confirm the same path, method, and trim-before-length rule.
- Shape: validate the document and JSON examples; check raw string input, normalized displayName bounds, required fields, and the 200, 400, and 401 response formats, including both edge cases above.
- Authorization: exercise a valid session, an absent session, an invalid session, and a session for another account; verify that the caller cannot select or alter the other account.
- Client: save a valid name through the actual form; show useful feedback for a 400; handle a 401 without pretending the save succeeded.
- Change review: compare the implementation and the accepted revision, record any deviation, and obtain a new confirmation before shipping a changed interface.
Those checks have different owners and evidence. A passing parser is evidence that the description is valid. A provider test is evidence about a particular handler and build. A browser flow is evidence about the client experience in a particular environment. No one artifact substitutes for the others. If any check has not run, say so on the ticket rather than describing the agreement as verified.
Keep the agreement small enough to maintain
Start with one user action that crosses the frontend/backend boundary. An exhaustive catalog of every route can delay the immediate handoff and be hard to keep current. The account-settings example needs only one operation, three outcomes, one auth rule, one owner on each side, and a clear compatibility decision. Add fields or routes when a real caller needs them. The value is the shared, versioned decision and its verification trail, not the amount of schema text.
When an AI agent proposes a new API call, ask it to cite the accepted contract revision and explain any difference before code review. When the backend changes, have its owner update that reference and ask the consumer to confirm. This keeps the discussion anchored to the user action and makes an incorrect assumption visible early. Choose and run contract tests against that revision, then attach the results for review.
What is an API contract for an AI-built frontend?
It is the shared, versioned agreement for a call: method and path, authentication, request and response fields, errors, owner, and change rules. The frontend and backend agents should confirm the same revision before treating generated code as integrated.
Does an OpenAPI file prove an endpoint works?
No. OpenAPI describes an intended HTTP interface. Parsing it or validating sample JSON does not prove that a handler exists, saves data, or enforces authorization. Run implementation and client checks against the accepted revision.
How do agents share a contract in AppHandoff?
An authorized agent publishes a ticket contract through the MCP ticket tool, and the consuming agent reads and confirms it. The agents provide the contract and evidence; AppHandoff does not infer the interface from code or run API checks automatically.
What makes an API change backward compatible?
Compatibility depends on the existing callers and the accepted schema. Adding an optional response field may be safe for a tolerant client but can fail a closed schema. Renames, type changes, and new required request fields need a coordinated revision or versioned route.
Put the handoff into practice
acceptance criteria generator — Turn known behavior into a reviewable acceptance criteria draft. Supply the feature, actor, action and success result, then add failure behavior and evidence you actually have. Missing answers stay visible.
pull request template generator — Start with a reusable repository template, ready to save as .github/pull_request_template.md on your default branch. Choose This PR description to draft a single review from change facts instead.