In short
OpenAPI is the standard format for describing an HTTP API in a JSON or YAML file: paths, methods, parameters, bodies, responses, errors and authentication. If you expose a public or partner REST API, publishing this file lets tools, coding assistants and agent platforms learn the API without reading your pages. Once this check is done, a valid, complete and up-to-date OpenAPI file is served at a fixed address such as https://example.com/openapi.json. Without an API, or with a GraphQL API, this check does not apply as is. This topic is experimental: no consumer assistant documents automatically reading these files on websites.
Why it matters
Human documentation explains; the OpenAPI specification can be processed by a program. Many tools that connect an API to a language model start from an OpenAPI file: client and SDK generators, API gateways, tools that turn operations into “tools” an agent can call, MCP (Model Context Protocol) servers built on top of an existing API. An accurate file spares an agent from having to infer the parameters from an HTML page.
The file is only useful if it tells the truth and tells enough. An automatically generated specification contains the types, but rarely the use of each operation, its side effects or the meaning of the errors. Yet that is what a model reads to choose which operation to call: an operation's summary and description fields act as its documentation.
The format keeps evolving. Version 3.2.0 of the specification was released in September 2025, after 3.1 (2021), which aligned schemas with JSON Schema. Not every tool reads 3.2 yet: choose the most recent version that your tools and your customers' tools accept, often 3.1 today.
What it improves
- Integrations through agents and tools A machine-readable file plugs into the tools that create clients, tests or agent tools. An indirect effect, which depends on what your users rely on.
- Accuracy Fewer made-up parameters and values when an assistant writes code for your API.
- Internal quality Automatic validation of the file detects inconsistencies between code and documentation.
- Security Some API gateways and firewalls validate incoming requests against the schema.
- Visibility No direct effect on rankings or citations; the HTML documentation remains the page to get indexed.
How to check
1. Does the file exist at a stable address?
curl -s -o /dev/null -w "%{http_code} %{content_type}\n" https://example.com/openapi.json
Compliant result: 200 application/json (or application/yaml for a .yaml file), with no redirect to a sign-in page.
2. Is it valid? With Redocly CLI or Spectral, without a permanent install:
npx @redocly/cli@latest lint https://example.com/openapi.json
npx @stoplight/spectral-cli lint https://example.com/openapi.json
Spectral without a ruleset asks for a .spectral.yaml (see below). No error messages is the minimum; warnings about missing descriptions count too.
3. Is it complete enough for an agent? Count the operations without a description:
curl -s https://example.com/openapi.json | jq '[.paths[][] | objects | select(.operationId != null and (.description // "" | length) < 20)] | length'
A result of 0 is the goal. Also check by hand that each operation has an explicit operationId, that enums are listed and that error responses are described.
4. Is it up to date? Compare the number of public routes in your application with the number of operations in the file.
How to implement
Before you start
Is it relevant? Yes for a public, partner or customer-facing REST or HTTP/JSON API. No for an API used only internally by the front end, for a GraphQL API (which is described by its schema and introspection) or for a site without an API.
What an agent reads first in each operation:
| Field | Role | Example |
|---|---|---|
operationId |
unique name of the operation, often reused as the tool name | creerIntervention |
summary |
short title | Create a job |
description |
use, when to use it, side effects | Schedules a job… Sends a text message to the technician |
parameters[].description, enum, format |
allowed values | type: installation, maintenance, depannage |
requestBody and responses with examples |
real examples | full 201 response |
4xx responses |
possible errors | 409, 422, 429 |
security |
required permissions | interventions:write scope |
A minimal yet complete OpenAPI 3.1 example, to save as openapi.yaml:
openapi: 3.1.1
info:
title: Planifia API
version: "1.4.0"
description: Job scheduling API. Sandbox at https://sandbox.example.com.
contact:
email: [email protected]
servers:
- url: https://api.example.com/v1
paths:
/interventions:
post:
operationId: creerIntervention
summary: Create a job
description: >
Schedules a job at a customer's site. Check the slot first with
listerDisponibilites. Sends a text message to the technician. Charges nothing.
Send an Idempotency-Key header to repeat the request without a duplicate.
tags: [Interventions]
security:
- oauth: [interventions:write]
parameters:
- name: Idempotency-Key
in: header
required: false
description: Unique UUID per logical attempt.
schema:
type: string
format: uuid
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/NouvelleIntervention'
example:
client_id: 42
debut: "2027-03-03T09:00:00+01:00"
type: maintenance
responses:
"201":
description: Job created with status planifiee.
content:
application/json:
schema:
$ref: '#/components/schemas/Intervention'
"409":
description: Slot unavailable. Offer another slot via listerDisponibilites.
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Probleme'
"422":
description: Invalid data. The faulty field is named in errors.
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Probleme'
"429":
description: Quota exceeded. Wait for the duration given by Retry-After.
components:
securitySchemes:
oauth:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://example.com/oauth/authorize
tokenUrl: https://example.com/oauth/token
scopes:
interventions:read: Read jobs
interventions:write: Create, modify and cancel jobs
schemas:
NouvelleIntervention:
type: object
required: [client_id, debut, type]
properties:
client_id:
type: integer
description: ID of an existing customer.
debut:
type: string
format: date-time
description: Start date and time, in the future, with time zone.
duree_minutes:
type: integer
minimum: 15
maximum: 480
default: 60
type:
type: string
enum: [installation, maintenance, depannage]
Intervention:
type: object
properties:
id: { type: integer }
statut: { type: string, enum: [planifiee, en_cours, terminee, annulee] }
debut: { type: string, format: date-time }
Probleme:
type: object
properties:
type: { type: string, format: uri }
title: { type: string }
status: { type: integer }
detail: { type: string }
code: { type: string }
The editorial content of the descriptions (use, effects, errors) follows the method in document existing public APIs (opens in a new tab).
Validate in continuous integration. A .spectral.yaml file at the root of the repository:
extends: ["spectral:oas"]
rules:
operation-operationId: error
operation-description: error
operation-tag-defined: warn
info-contact: warn
oas3-valid-media-example: error
npx @stoplight/spectral-cli lint openapi.yaml --fail-severity=error
Publish at a stable, discoverable address: /openapi.json or /openapi.yaml at the root of the API's domain, accessible without signing in, with a CORS header (Access-Control-Allow-Origin: *) so that online tools can load it. Add the service-desc relation in a Link header and, if you wish, a /.well-known/api-catalog catalog (RFC 9727). Both are described in the previous guide.
Laravel
Versions Laravel 11 to 13.
Scramble generates an OpenAPI 3.1.0 specification from routes, validation requests and resources, with no mandatory annotations:
composer require dedoc/scramble
php artisan scramble:export --path=public/openapi.json
The exported file is served as a static file. Scramble reuses the PHP docblock of controller methods for the operation's summary and description (see its documentation for the exact rules): write the use and the side effects there. Add the export command to your deployment so the file keeps up with the code. Scramble also exposes /docs/api.json, restricted by default to the local environment: open the viewApiDocs gate if you prefer to serve that route in production.
Scribe also produces an openapi.yaml in public/docs on each php artisan scribe:generate.
Symfony
Versions Symfony 7 and 8, API Platform 4.
API Platform generates the specification from the resources; according to its documentation, the documents it produces target OpenAPI 3.2.0, and version 3.0.0 remains available through the spec_version parameter. Export for static publishing:
bin/console api:openapi:export --output=public/openapi.json
Add --yaml for a YAML export (requires the symfony/yaml package). Descriptions go in each operation's openapi option, with ApiPlatform\OpenApi\Model\Operation. If one of your customers' tools does not read 3.2, publish the 3.0 export as well.
Next.js
Versions Next.js 15 and 16 (App Router).
Next.js does not generate an OpenAPI specification. Write the file or generate it with the validation library you already use, place it in public/openapi.json, then add the headers in next.config.ts:
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {
async headers() {
return [
{
source: '/openapi.json',
headers: [
{ key: 'Access-Control-Allow-Origin', value: '*' },
{ key: 'Cache-Control', value: 'public, max-age=300' },
],
},
{
source: '/api/:path*',
headers: [
{ key: 'Link', value: '<https://example.com/openapi.json>; rel="service-desc"' },
],
},
];
},
};
export default nextConfig;
WordPress
Versions WordPress 6.4 and later.
The WordPress REST API describes its routes in its own format at /wp-json/, not in OpenAPI. For a business API built on custom routes, write an openapi.yaml that covers only those routes and upload it to the site root over SFTP. Do not describe WordPress's native routes, which you do not control.
Apache
Versions Apache 2.4.
In the .htaccess file at the site root or in the virtual host:
AddType application/yaml .yaml .yml
<IfModule mod_headers.c>
<FilesMatch "^openapi\.(json|yaml)$">
Header set Access-Control-Allow-Origin "*"
Header set Cache-Control "public, max-age=300"
</FilesMatch>
</IfModule>
<Files "api-catalog">
ForceType application/linkset+json
</Files>
The api-catalog file, with no extension, goes in the site's .well-known directory.
Nginx
Versions Nginx 1.24 and later.
In the site's server block, for example /etc/nginx/sites-available/example.com:
location ~ ^/openapi\.(json|yaml)$ {
types {
application/json json;
application/yaml yaml;
}
add_header Access-Control-Allow-Origin "*" always;
add_header Cache-Control "public, max-age=300" always;
}
location = /.well-known/api-catalog {
types { }
default_type application/linkset+json;
}
sudo nginx -t && sudo systemctl reload nginx
Cloudflare
Versions Cloudflare dashboard, all plans, November 2026.
Nothing to configure to serve the file, but two checks. First, make sure the bot management and firewall rules do not block /openapi.json for automated clients: a request for this file almost always comes from a program. Look at Security Analytics filtered on that path. Then, after each update of the file, purge its URL in Caching > Configuration. On plans that include API Shield, schema validation can rely on an OpenAPI file: see Cloudflare's documentation for the supported versions.
AWS
Versions AWS console, November 2026.
API Gateway can create or update a REST API by importing an OpenAPI definition; the AWS documentation specifies the supported OpenAPI versions and x-amazon-apigateway-* extensions. Check compatibility before publishing a 3.1 or 3.2 file that you also plan to import. To serve the public file, upload it to S3 behind CloudFront, with a CORS response headers policy on that path.
Common mistakes
- Publishing a generator's raw output: correct types, no descriptions. The agent knows how to call, not when or why.
- Missing or automatic
operationIdvalues (post_v1_interventions_store): many tools turn them into tool names; an explicit name helps the model choose. - Undescribed errors: only the 200 response appears in the file.
- Relative or internal
serversaddress:http://localhost:8000or/v1with no domain in a public file. - File behind a login or blocked by the firewall for automated clients.
- Frozen file: published once, never regenerated. Export it on every deployment and validate it in continuous integration.
- Exposing internal routes: review the file before publishing; a publicly documented admin route is an invitation.
Frequently asked questions
Which OpenAPI version should I choose in 2026?
Choose the most recent version that your tools and your customers' tools can read. OpenAPI 3.2.0 was released in September 2025, but part of the ecosystem is still on 3.1 or 3.0. Version 3.1, aligned with JSON Schema, is often the best compromise. If your generator outputs 3.2, test the file in your users' tools before relying on it alone.
Does OpenAPI improve visibility in ChatGPT or Google?
No, not directly. An OpenAPI file is not a ranking signal and no consumer assistant documents reading it on websites. Its value is operational: it lets tools, agent platforms and coding assistants call your API correctly. The HTML documentation page remains the one that can be indexed and cited in answers.
Do I need an OpenAPI file if I already have an MCP server?
Yes, if you have a public API. An MCP server exposes a selection of actions to compatible assistants, while the OpenAPI file describes the whole API for developers, SDK generators, gateways and other tools. The two complement each other, and many MCP servers are in fact built from an existing OpenAPI specification.
Where should the OpenAPI file be published?
Publish it at a stable address that requires no sign-in, for example https://example.com/openapi.json, with a CORS header that lets online tools read it. Link to it from the human documentation, from a Link header with the service-desc relation and, if you wish, from a /.well-known/api-catalog catalog. Regenerate it on every deployment so that it stays true to the code.
Resources
- OpenAPI Initiative: OpenAPI Specification (latest version)spec.openapis.org
- OpenAPI Initiative: learning guidelearn.openapis.org
- Redocly CLI: lint commandredocly.com
- Spectral: built-in OpenAPI rulesdocs.stoplight.io
- Scramble: exporting the specificationscramble.dedoc.co
- API Platform: OpenAPI supportapi-platform.com
- IETF: RFC 9727, API catalogrfc-editor.org
Updated on
Topic checklist (PDF)