Check 40.09 · AI agent compatibility

Document existing public APIs

Document your public APIs so an AI agent uses them without guessing: what each operation does, parameters, errors, limits, side effects and discovery.

Priority
Experimental
Difficulty
Intermediate
Estimated time
2 to 5 days, then ongoing
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

If your website or software already exposes a public or partner API (application programming interface), its documentation must let an AI agent pick the right operation, call it correctly and understand its errors, without trial and error. Once this check is done, every operation says what it is for, when to use it, what it changes, what it costs in quota and how to react to each error, and the documentation can be discovered from a fixed address. If you have no API, this check does not apply to you. This topic is experimental: no search engine or agent publishes any rule on how it reads API documentation.

Why it matters

An agent that has to act on a service takes one of three paths: the web interface, a dedicated connector (often an MCP server, Model Context Protocol) or the API directly, in the code it writes or runs. In the last two cases, it does not see your screens: all it has is the documentation and the API's responses.

Documentation written for a human developer often assumes unstated context: “use the usual endpoint”, “see the integration guide”, a type parameter with no list of values, a 400 error with no meaningful body. A human fills the gaps by reading the forum or asking support. An agent fills the gaps by making things up: a plausible parameter, an enum value that does not exist, a retry on an operation that has already charged the customer.

Publishing and indexing the documentation are covered in publish API documentation if applicable (opens in a new tab). This guide is about its content: what to write so that a machine can act correctly. The formal description in OpenAPI format is the subject of the guide use OpenAPI if relevant (opens in a new tab).

What it improves

  • Correct calls on the first try Fewer made-up parameters and error loops when a coding assistant or an agent uses the API. A plausible effect, not publicly measured.
  • Safer actions Operations that modify, charge or delete are flagged, which lets the agent or its host ask for confirmation.
  • AI assistant answers Exact operation names and error codes that a generative engine can reuse instead of guessing them. No page guarantees a citation.
  • A basis for what comes next Complete documentation converts effortlessly into an OpenAPI specification or into MCP tools.
  • Support and integrations Fewer “why am I getting a 400 error” tickets.
  • Rankings No direct effect.

How to check

Run a one-hour audit on five representative operations: a simple read, a paginated search, a create, an update, and an operation that charges or deletes.

Check Compliant
One sentence says what the operation is for and when to prefer it over another “To check a slot before booking, call GET /v1/disponibilites first”
Each parameter has a type, a format, bounds and its allowed values statut: planifiee, en_cours, terminee
A complete request and response example, runnable as is curl command and actual response JSON
Side effects are written down “Creates an invoice and sends an email to the customer”
Each error code is listed with its cause and what to do 409 creneau_indisponible: offer another slot
Quotas, pagination and retries are explained 429 with Retry-After, next cursor
Authentication and the required permissions are named for each operation interventions:write scope

Then the agent test, which is free: open ChatGPT, Claude or Perplexity, paste the URL of a reference page and ask “Write the curl command to create a job on March 3 at 9 a.m. for customer 42, then explain what I should do if I get a 409 error”. Run the command in a test environment. Every made-up parameter and every misread error points to a passage to rewrite.

Finally, check discovery:

curl -s -I https://example.com/ | grep -i "^link"
curl -s https://example.com/.well-known/api-catalog

Compliant result: a Link header or a catalog that points to the documentation and the specification (see step 5).

How to implement

The examples use Planifia, a fictional vendor of field service scheduling software.

Step 1 — Inventory the public operations

List every operation actually available to customers or partners, not just the documented ones. Sources: routes file, API gateway, access logs from the last three months. Fill in this table in a spreadsheet:

Operation Method and path Purpose in one sentence Side effect Required permission Idempotent Documented
List jobs GET /v1/interventions Search the jobs for a period None interventions:read Yes Yes
Create a job POST /v1/interventions Schedule a job at a customer's site Notifies the technician by text message interventions:write No, except with Idempotency-Key Partly
Cancel a job POST /v1/interventions/{id}/annulation Cancel before the technician's visit Charges a fee if less than 24 hours interventions:write Yes No
Export invoices GET /v1/factures/export Download a monthly CSV None factures:read Yes No

The “Side effect” and “Idempotent” columns are the ones people forget, and the ones that matter most to an agent. Operations that are used but undocumented come first; those that should not be public must be closed (see check authentication and authorization (opens in a new tab)).

Step 2 — Write each operation with a fixed template

The same template for every operation helps humans and machines alike. Markdown template:

## Create a job

`POST /v1/interventions`

Schedules a job at a customer's site on a given date. Use it after checking the slot with `GET /v1/disponibilites`. To move an existing job, use `PATCH /v1/interventions/{id}`.

Effects: creates the job with status `planifiee` and sends a text message to the technician. Charges nothing.
Required permission: `interventions:write` scope.
Idempotency: send an `Idempotency-Key` header (UUID) so the request can be repeated without creating a duplicate.

### Body parameters (JSON)

| Name | Type | Required | Rules |
|---|---|---|---|
| client_id | integer | yes | existing ID, see GET /v1/clients |
| debut | date-time string | yes | ISO 8601 with time zone, e.g. 2027-03-03T09:00:00+01:00, in the future |
| duree_minutes | integer | no | 15 to 480, default 60 |
| type | string | yes | `installation`, `maintenance` or `depannage` |

### Example

curl -X POST https://api.example.com/v1/interventions \
  -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: 6f1c2a8e-2d4b-4c1e-9a77-0b5e3f9d2c10" \
  -H "Content-Type: application/json" \
  -d '{"client_id":42,"debut":"2027-03-03T09:00:00+01:00","type":"maintenance"}'

Response 201: {"id":918,"statut":"planifiee","debut":"2027-03-03T09:00:00+01:00","technicien_id":7}

### Errors

| Status | Code | Cause | What to do |
|---|---|---|---|
| 401 | token_invalide | token missing or expired | obtain a new token |
| 403 | portee_insuffisante | interventions:write scope missing | ask the user for the scope |
| 409 | creneau_indisponible | technician already booked | call GET /v1/disponibilites and offer another slot |
| 422 | donnees_invalides | a field breaks its rules | read `errors`, fix the named field |
| 429 | limite_atteinte | quota exceeded | wait for the `Retry-After` duration |

Writing rules:

  • The first sentence states the use, not the implementation: “Schedules a job” rather than “POST endpoint on the job resource”.
  • Guide the choice between similar operations: when two operations look alike, say which one to pick. This is the information agents most often lack.
  • Real values in the examples, consistent between request and response, and runnable in a test environment.
  • Write down the effects visible outside the API: email sent, payment, notification, data shared with a third party.

Step 3 — Standardize errors

A single, documented error format lets the agent correct itself. The standard format is RFC 9457 (Problem Details for HTTP APIs), served with the application/problem+json type:

{
  "type": "https://example.com/docs/api/erreurs#creneau_indisponible",
  "title": "Slot unavailable",
  "status": 409,
  "detail": "Technician 7 already has a job on 2027-03-03 from 08:30 to 10:00.",
  "code": "creneau_indisponible",
  "instance": "/v1/interventions"
}

What to document on a single “Errors” page: each business code, its HTTP status, its cause, the expected action, and whether the request can be repeated as is. The type points to the anchor on the matching documentation page: the agent that reads the error finds the explanation. Error messages in forms are covered in provide clear error messages (opens in a new tab).

Step 4 — Document the cross-cutting rules

One page each, linked from every operation:

  • Authentication: method (API key, OAuth 2.0), where to get credentials, list of scopes and the operations each one covers, token lifetime.
  • Limits: quotas per minute and per day, headers returned, expected behavior on 429 (wait for Retry-After, do not retry in a loop).
  • Pagination: type (cursor or page), maximum size, field that signals the end.
  • Idempotency and retries: which operations can be repeated safely, how long an Idempotency-Key stays valid. This header name is a widespread convention, being standardized at the IETF.
  • Versions: current version, dated deprecations, version header or prefix.
  • Test environment: sandbox URL, available sample data. This is where an agent or a developer must be able to try things without risk.

Step 5 — Make the documentation discoverable by machines

Three complementary mechanisms, all optional:

  1. Link header on the API root, with the service-desc (machine-readable description) and service-doc (human documentation) relations defined by RFC 8631:
Link: <https://example.com/openapi.json>; rel="service-desc", <https://example.com/docs/api/>; rel="service-doc"
  1. API catalog at /.well-known/api-catalog, defined by RFC 9727 (June 2025), served as application/linkset+json:
{
  "linkset": [
    {
      "anchor": "https://example.com/.well-known/api-catalog",
      "item": [
        { "href": "https://example.com/docs/api/" }
      ],
      "service-desc": [
        { "href": "https://example.com/openapi.json", "type": "application/json" }
      ]
    }
  ]
}
  1. Markdown versions and llms.txt: some documentation vendors also publish each page as .md and an llms.txt index. These are experimental conventions whose use by search engines is not documented: see evaluate Markdown versions (opens in a new tab) and evaluate llms-full.txt for documentation (opens in a new tab).

Good to know: no consumer assistant documents reading /.well-known/api-catalog or the Link header. These mechanisms mainly serve developer tools and the agents that you or your customers configure. Treat them as good practice, not as a visibility signal.

Laravel

Versions Laravel 11 to 13.

Scribe and Scramble generate the reference from routes and validation rules; check in their documentation that their version is compatible with yours. Generators produce the parameters, not the use or the side effects: add those in the code.

With Scribe, docblock annotations feed the page:

/**
 * Create a job
 *
 * Schedules a job at a customer's site. Check the slot first with
 * GET /v1/disponibilites. Sends a text message to the technician. Charges nothing.
 *
 * @group Interventions
 * @authenticated
 * @header Idempotency-Key 6f1c2a8e-2d4b-4c1e-9a77-0b5e3f9d2c10
 * @response status=409 scenario="Slot taken" {"type":"https://example.com/docs/api/erreurs#creneau_indisponible","status":409,"code":"creneau_indisponible"}
 */
public function store(StoreInterventionRequest $request): JsonResponse

For the Link header on the API root, a middleware is enough:

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class AddApiDiscoveryLinks
{
    public function handle(Request $request, Closure $next): Response
    {
        $response = $next($request);

        $response->headers->set(
            'Link',
            '<https://example.com/openapi.json>; rel="service-desc", <https://example.com/docs/api/>; rel="service-doc"',
        );

        return $response;
    }
}

Register it on the api group in bootstrap/app.php with $middleware->api(append: [AddApiDiscoveryLinks::class]);. You get the RFC 9457 format by customizing exception rendering in the same file, in the withExceptions method.

Symfony

Versions Symfony 7 and 8, API Platform 4.

API Platform produces the documentation and the specification from the resources. Describe the use and the effects of each operation in the openapi option:

use ApiPlatform\Metadata\Post;
use ApiPlatform\OpenApi\Model;

#[Post(
    openapi: new Model\Operation(
        summary: 'Create a job',
        description: 'Schedules a job at a customer\'s site. Check the slot first with GET /v1/disponibilites. Sends a text message to the technician. Charges nothing.',
    ),
)]

API Platform can serve its errors in Problem Details format (application/problem+json); check the negotiated format in your configuration and document your business codes as well.

WordPress

Versions WordPress 6.4 and later.

The WordPress REST API publishes at /wp-json/ a machine-readable index that lists, for each route, its arguments and their description. So fill in description, type, enum and required in register_rest_route, and always provide a permission_callback:

add_action( 'rest_api_init', function () {
    register_rest_route( 'planifia/v1', '/interventions', array(
        'methods'             => 'POST',
        'callback'            => 'planifia_create_intervention',
        'permission_callback' => function () {
            return current_user_can( 'edit_posts' );
        },
        'args'                => array(
            'type' => array(
                'description' => 'Job type. Sends a text message to the technician.',
                'type'        => 'string',
                'enum'        => array( 'installation', 'maintenance', 'depannage' ),
                'required'    => true,
            ),
        ),
    ) );
} );

Check the result with curl -s https://example.com/wp-json/planifia/v1 | jq. WordPress's native routes are documented by the project itself: only document your custom routes.

Shopify

Versions Shopify stores, November 2026.

Shopify's APIs are documented by Shopify. Only the APIs you expose yourself concern you (app, app proxy, external service): apply steps 1 to 5 to them.

Common mistakes

  • Documenting the parameters but not the use: the agent knows how to call the operation, not when. It picks the wrong one of two similar operations.
  • Leaving out side effects: a text message sent or an invoice issued without the documentation saying so rules out any request for confirmation beforehand.
  • Examples that do not run: placeholder token in the body, values inconsistent between request and response, a field renamed since.
  • Errors with no body: an empty 400 or an HTML error page forces the agent to guess.
  • Implicit enums: “the job type” with no list of values produces made-up values.
  • Documentation behind a login: neither the agent nor the generative engine reads it.
  • Documentation lagging behind the code: generate the reference in continuous integration and fail the deployment if it diverges.

Frequently asked questions

Does API documentation help get cited by AI?

Accurate public API documentation makes your operation names, parameters and error codes available to assistants that write code or answer technical questions. It reduces made-up answers, but nothing guarantees a citation. Its first benefit is operational: an agent or an AI-assisted developer calls your API correctly and knows how to react to errors without contacting support.

Do AI agents need separate documentation?

No, a single set of documentation is enough, as long as it is explicit. What helps an agent also helps a developer in a hurry: the use of each operation, the allowed values, the side effects, runnable examples and what to do for each error. Machine-readable formats, such as OpenAPI, Markdown versions or an API catalog, add to the human documentation without replacing it.

Which error format should an API use?

The standard format is Problem Details, defined by RFC 9457 and served with the application/problem+json type. It contains a type pointing to the documentation, a title, the HTTP status and a readable detail. Add a stable business code and document, on a single page, the cause and the expected action for each code. An agent can then fix its request instead of repeating it unchanged.

What should be documented first?

Start with the operations that modify data, charge money or send messages, then the operations called most often in your logs. For each one, write its use in one sentence, its side effects, the required permissions, its idempotency and the possible errors. Simple read operations, already understandable from their parameters, can wait for a second pass.

Updated on

Topic checklist (PDF)

And now?

In the “AI agent compatibility” topic

  1. Use semantic HTML and explicit labels
  2. Identify what each button does
  3. Provide clear error messages
  4. Keep URLs stable
  5. Avoid mandatory complex gestures
  6. Make component states accessible
  7. Display final prices, availability and options
  8. Simplify booking and checkout
  9. Document existing public APIs
  10. Use OpenAPI if relevant
  11. Evaluate MCP based on use cases
  12. Evaluate compatible agentic commerce protocols
  13. Check authentication and authorization
  14. Require confirmation for sensitive actions
  15. Test user journeys with browsing agents
  16. Prevent prompt injection and unauthorized interactions