Lesson 3 of 4 · 30 min

One API for Mobile, Web and AI Agents

Design the API once so every client and agent can use it.

XDQ Tutor · AI guide

Hello. In this lesson I will take you through 3 ideas, one at a time.

  1. Three kinds of caller
  2. Actions agents can use safely
  3. Versioning and contracts

Why it matters: Design the API once so every client and agent can use it. After each idea I will ask you one quick question.

Three kinds of caller

The short version: A modern product has three callers: the mobile app, the web app and AI agents that act for the business, such as a support agent checking an order.

A modern product has three callers: the mobile app, the web app and AI agents that act for the business, such as a support agent checking an order. Build one API for all three instead of a private back door for each.

Agents need the same things people do, with tighter limits: narrow permissions, clear errors and actions that are safe to retry.

Quick check

What does idempotent mean for a booking API?

Actions agents can use safely

The short version: Make write actions idempotent, so a repeated call does not create a second booking or refund.

Make write actions idempotent, so a repeated call does not create a second booking or refund. Return errors that say what was wrong and what to do. Give agents their own keys with only the scopes they need.

For anything that reaches a customer or moves money, the API should support a pending state: the agent proposes, a person approves, the action runs.

Quick check

Why avoid renaming API fields?

Versioning and contracts

The short version: Publish the API as a schema and generate clients from it.

Publish the API as a schema and generate clients from it. Mobile apps stay installed for a long time, so old versions keep calling. Add fields, do not rename them, and retire versions on a published schedule.

Contract tests run on every change and fail the build if a response shape breaks a client.

Key takeaways
  • One API serves mobile, web and agents
  • Write actions must be safe to repeat
  • Risky actions go through a pending and approve step
  • Add fields, never rename, and test the contract
Try it

Pick one write action, such as refund an order. Describe how you make it safe to retry, what errors it returns and where the approval step sits.

That is the lesson.
Mark it complete to track your progress on this device.
← PreviousHow to Build an Admin Panel with AI AgentsNext lesson →Deploying AI-Built Web Apps Safely