How to publish an OpenAPI spec AI agents can use
Publish your OpenAPI spec as a public file at a stable URL such as /openapi.json, link it from llms.txt and your API reference, and keep it generated from your code so it never drifts. Give every operation an operationId, a one-line summary, typed parameters and an example response, and describe auth in securitySchemes. An agent or coding assistant with that file can build a correct call without guessing from prose.
From our data: As of 16 Nov 2026, we found a public OpenAPI spec for 39 of the 214 software vendors in our rankings (18%), including Amplitude, Notion, Supabase, beehiiv, Cal.com and Clerk. For 47 vendors it was the single biggest gap in their score.
Why agents need the spec, not just docs
When a coding agent like Claude Code, Cursor or Codex is asked to integrate your product, it looks for a machine-readable contract first. With an OpenAPI file it knows every endpoint, parameter, type and auth method in one fetch. Without one it reads prose docs page by page and guesses, which is where wrong field names and invented endpoints come from.
The same file powers SDK generators, API clients and many MCP servers, which are often generated from an OpenAPI spec. One good spec feeds all of them.
Where to publish it
A stable, public URL
/openapi.json or /openapi.yaml on your main or API domain. No login, no bot wall, no expiring signed link.
Linked from llms.txt
Add a line like "- [OpenAPI spec](https://example.com/openapi.json): full REST API" so agents that start from llms.txt find it.
Linked from the API reference
A visible "Download OpenAPI spec" link on your docs home. Agents and people both look there.
Served with the right type
application/json or application/yaml with a 200. A catch-all route that returns your HTML shell doesn't count.
What makes a spec usable by an agent
operationId on every operation
Short and verb-first, like listContacts or createInvoice. Agents and MCP generators turn these into tool names.
A summary and description
One line on what the call does and when to use it. This text is what an agent reads to pick the right endpoint.
Typed parameters and bodies
Real schemas with required fields, enums and formats, not a bare "object".
Examples
An example request and response for the common calls. Agents copy them.
Auth in securitySchemes
Say whether it's an API key header, bearer token or OAuth, and where to get credentials.
Generated from code
FastAPI, NestJS, Django REST Framework, Spring and others can emit the spec. A hand-written file drifts.
A minimal example
Trimmed to one operation. A real spec lists every public endpoint.
{
"openapi": "3.1.0",
"info": { "title": "Acme API", "version": "2026-11-01" },
"servers": [{ "url": "https://api.acme.com/v1" }],
"components": {
"securitySchemes": { "apiKey": { "type": "http", "scheme": "bearer" } }
},
"security": [{ "apiKey": [] }],
"paths": {
"/contacts": {
"get": {
"operationId": "listContacts",
"summary": "List contacts, newest first",
"parameters": [
{ "name": "limit", "in": "query", "schema": { "type": "integer", "maximum": 100 } }
],
"responses": { "200": { "description": "A page of contacts" } }
}
}
}
}Common failures
The spec only exists inside the docs tool
Many docs platforms render from a spec but never expose the file. Publish the raw file too.
Behind a login
If the spec needs a dashboard session, agents can't read it. Keep the spec public even when the API itself needs a key.
One giant file with no descriptions
Thousands of endpoints and no summaries leave an agent unable to choose. Add summaries, or split by product with links from llms.txt.
Out of date
A stale spec is worse than none, because agents trust it. Regenerate it on every release.
Vendors with a public OpenAPI spec
39 of the vendors in our rankings, from our scan on 16 Nov 2026.
Check it yourself
The first should print 200 and a JSON or YAML content type. The second shows whether your llms.txt points agents to the spec.
curl -s -o /dev/null -w "%{http_code} %{content_type}\n" https://example.com/openapi.json
curl -s https://example.com/llms.txt | grep -i openapiQuestions
Do I need an OpenAPI spec if I have an MCP server?
Yes, if you have a public API. The MCP server covers assistants like Claude and ChatGPT; the spec covers coding agents, SDK generators and anyone building on your API directly. Many teams generate the MCP server from the spec.
OpenAPI 3.0 or 3.1?
Either works for agents. 3.1 aligns with JSON Schema, so new specs should use it.
JSON or YAML?
Either. JSON is slightly easier for tools to fetch and parse; publishing both is fine.
Does publishing the spec expose anything private?
Only what's in it. Publish the public API surface and leave internal or admin endpoints out of the public file.