How to build AI-ready API documentation with OpenAPI and Mintlify

How to build AI-ready API documentation with OpenAPI and Mintlify

Learn how to build AI-ready API documentation with OpenAPI, Redocly, Git, Mintlify, grounding guidance, llms.txt, and MCP tools

I built TaskSocial, a full-stack application with a working API, to test what AI-ready API documentation looks like in practice. I wanted the documentation to support developers using the API and AI agents working with the same information.

I started with the API and created an OpenAPI specification as its source of truth. Redocly validated the specification, Git provided version control for the documentation, and Mintlify handled deployment. I then tested the documentation with Mintlify’s AI Assistant to see whether the assistant could retrieve the correct API details and use them accurately.

One test exposed a problem. When I asked the assistant how to handle an ambiguous task update, it correctly recognized that the request needed clarification but suggested GET /api/v1/tasks, an endpoint that did not exist. The documented endpoint was GET /api/v1/tasks/my-tasks.

That finding shaped the rest of the workflow. In this article, I show how to build an API documentation pipeline with OpenAPI, Redocly, Git, and Mintlify, then make it usable by AI agents through operational guidance, API grounding, machine-readable documentation, and MCP tools.

What you'll learn

By the end of this article, you'll know how to:

  • turn a working API into an OpenAPI contract

  • validate that contract with Redocly

  • build a Git-backed documentation workflow with Mintlify

  • test whether an AI assistant could use the same documentation

  • find and fix an incorrect API assumption through grounding guidance

  • explorellms.txt, AI discovery, and MCP tools

  • turn the experiment into a workflow you can apply to your own API

The main question behind the project was:

What happens when you build a Git-backed API documentation pipeline from a working API and then make that documentation useful for both developers and AI tools?

From TaskSocial to an API contract

TaskSocial is a social accountability application where users can create tasks, track their progress, and share them on a task feed. A task can have a status such as pending or completed, and shared tasks can be visible to other users through the feed.

TaskSocial task feed and task management interface

The API behind TaskSocial handles the main task operations. For this documentation experiment, I documented:

POST   /api/v1/tasks/create
GET    /api/v1/tasks/my-tasks
GET    /api/v1/tasks/feed
PUT    /api/v1/tasks/{id}
DELETE /api/v1/tasks/{id}

Working with a API showed me the actual problem of keeping the backend and documentation in sync. The backend changes. Endpoints can change. Documentation also needs to be updated.

The next step was creating an OpenAPI specification for TaskSocial.

Before this project, I mostly treated OpenAPI as a generic specification that described an API. After using it throughout this experiment, I know that OpenAPI file could become a structured source of truth for the API.

It contained the endpoint paths, HTTP methods, request bodies, responses, and authentication requirements.

What I found useful was that I did not have to think about the API documentation separately for every platform. Once the API was described in OpenAPI, that same contract could be used across different tools.

For this project, I also used Redocly for linting, validation, and bundling the specification. YAML is indentation-sensitive, so a small formatting or structural mistake can take time to find.

Working API
    ↓
OpenAPI specification
    ↓
Redocly validation
    ↓
Validated API contract

Redocly validating the TaskSocial OpenAPI specification

This changed how I thought about the documentation process. Instead of manually maintaining endpoint information separately, I could first create and validate the API contract, then use that contract as the foundation.

Building the Git-backed documentation workflow

I wanted a Git-backed workflow so documentation changes could be managed in the repository and reflected on the live documentation site after merging and deployment. I wanted documentation to follow the same kind of workflow as the project itself.

TaskSocial API
    ↓
OpenAPI specification
    ↓
Redocly validation
    ↓
Git branch
    ↓
Pull request
    ↓
Review
    ↓
Merge
    ↓
Mintlify
    ↓
Production documentation

adding openAPI specification doc

The OpenAPI specification became the foundation for the API reference, but I also needed regular documentation pages around it. I created .mdx files for guides such as authentication, creating a first task, and testing the API.

A simple page looked like this:

---
title: Create your first task
description: Learn how to create a task using the TaskSocial API.
---

# Create your first task

Use the `POST /api/v1/tasks/create` endpoint to create a new task.

The API reference described what operations existed, while the guides explained how someone could use them.

Validating the documentation locally

Before deployment, I used the Mintlify CLI to validate and preview the documentation:

mint validate
mint dev

mint validatechecked the documentation configuration, while mint dev previewed it locally.

Mintlify validation checkingMintlify documentation project running locally

I also ran into setup problems. For example, mint new failed during starter extraction even though the CLI itself was installed and running. I continued with the setup manually.

I also found configuration issues while testing the API through the documentation. A login request initially failed because the required server URL was missing from the configuration.

TaskSocial API login request failing because the server URL is missing

That was one reason I wanted to test the documentation in a real environment instead of generating it and assuming everything worked.

At this point, I had a working pipeline:

Working API
    ↓
OpenAPI contract
    ↓
Redocly validation
    ↓
MDX guides + API reference
    ↓
Git workflow
    ↓
Mintlify deployment
    ↓
Live documentation

The documentation was doing what I originally built it for: helping developers understand authentication, endpoints, and task operations.

Then I started testing whether the same documentation could work for another consumer: AI.

Testing whether the documentation works for AI

Mintlify includes an AI Assistant directly inside the documentation site. This made the next part of the experiment easier because I could update the documentation and test how the assistant responded to it.

I started with a simple question.

Experiment 1: Basic API retrieval with Mintlify's AI Assistant

How do I create a task?

Mintlify AI Assistant explaining how to create a TaskSocial task

The result was yes. The assistant could retrieve information from the API reference and guides and explain how to create a task.

But the next experiment showed that knowing what an API operation does is not always enough.

Experiment 2: Operational guidance with Mintlify's AI Assistant

I tested a more ambiguous request:

Update my documentation task.

The API reference showed that an update operation exists:

PUT /api/v1/tasks/{id}

But the request was incomplete. Which task should be updated, what should be changed, and does the authenticated user own the task?

So I added an Agent-Oriented Task Update guide. The API reference still described what operations existed. The additional guide described what the AI should consider before deciding to use one.

I tested the same request again.

Mintlify AI Assistant asking for clarification before updating a task

This time, the assistant recognized that the request was ambiguous and asked for clarification instead of immediately jumping to the update endpoint.

That gave me an important distinction:

  • API reference: What operations exist?
  • Operational guidance: Should this operation be performed right now?

The next experiment showed why I also needed another layer.

The grounding problem I found

This is where I found a problem I did not expect. The assistant correctly understood that "Update my documentation task" was ambiguous. It recommended asking for clarification.

But while reading the response more carefully, I found this:

GET /api/v1/tasks

The problem was that this endpoint did not exist. The documented operation was:

GET /api/v1/tasks/my-tasks

AI Assistant using the incorrect GET /api/v1/tasks endpoint

The reasoning was correct. The API detail was not.

That led me to separate two different things.

Operational reasoning

Should this action be performed?

In this case, no. The request was ambiguous, so clarification was needed.

API contract validation

What exact documented operation should be used?

The assistant knew it needed task information, but it generated a plausible-looking endpoint instead of using the documented one. Correct reasoning did not guarantee correct technical details.

So I added a Grounding and API Validation guide that explicitly told the AI to verify:

  • the HTTP method

  • the exact endpoint path

  • required parameters

  • authentication requirements

  • operational preconditions

If an operation could not be confirmed in the documented contract, it should not invent one.

Testing operational guidance and API grounding

I tested the same questions again after adding the grounding guide.

This time, the assistant correctly used:

GET /api/v1/tasks/my-tasks

It also rejected the assumption that this endpoint existed:

GET /api/v1/tasks

And it explained that undocumented operations should not be invented.

AI Assistant using the documented GET /api/v1/tasks/my-tasks endpoint

After adding the grounding guidance, the assistant changed its behavior:

Before grounding guidance

Correct operational reasoning
        +
Possible incorrect technical detail
        ↓
GET /api/v1/tasks
After grounding guidance

Operational reasoning
        +
API contract validation
        ↓
GET /api/v1/tasks/my-tasks

This does not mean the AI can never produce an incorrect detail, as these were controlled tests based on the questions I asked. But the change in behavior was enough to show why explicit grounding mattered.

I then combined both layers in one end-to-end workflow.

User:
"Update my documentation task."
        ↓
Request is ambiguous
        ↓
Ask for clarification
        ↓
Identify the task
        ↓
GET /api/v1/tasks/my-tasks
        ↓
Find the exact task ID
        ↓
Validate preconditions
        ↓
PUT /api/v1/tasks/{id}

AI Assistant following the TaskSocial task update workflow

This became the core finding of the article for me.

Operational guidance helps answer whether an action should happen. API grounding helps answer what exact documented operation should be used.

For this workflow, both mattered.

llm.txt and llms-full.txt: availability is not discovery

Mintlify also provides llms.txt and llms-full.txt.

These files give AI systems machine-readable access to the documentation without requiring them to navigate the fully styled documentation site in the same way a human does.

I wanted to see what would happen when another AI agent encountered a problem while using the TaskSocial MCP server.

During testing, I discovered that I had accidentally configured an incorrect endpoint in one of the MCP tools. The request failed.

The agent tried to recover by looking for information elsewhere, but it did not automatically discover and use the TaskSocial documentation portal.

The correct information was already present in the documentation and available through machine-readable formats. But availability alone did not guarantee discovery or retrieval.

So if you publish AI-readable documentation, test the next layer too:

  • Can the AI find it?

  • Can it retrieve the relevant information?

  • Does it use the documented API contract?

  • What does it do when the documentation does not contain the answer?

A small MCP extension

After testing whether the documentation could guide an AI assistant, I wanted to see what happens if the documented API operations are exposed as actual tools?

I built a small MCP server around TaskSocial with:

  • get_my_tasks

  • get_shared_task_feed

  • create_task

  • update_task

  • delete_task

These tools mapped back to API operations already defined in the contract. For example:

GET /api/v1/tasks/my-tasks
            ↓
       get_my_tasks

A simplified tool definition looked like this:

server.registerTool(
  "get_my_tasks",
  {
    title: "Get My Tasks",
    description:
      "Retrieve all tasks belonging to the authenticated user. Use this to identify the exact task ID before updating or deleting it.",
    inputSchema: {},
  },
  async () => {
    return successResult(
      await request("/api/v1/tasks/my-tasks")
    );
  }
);

Codex CLI showing the TaskSocial tools available to the AI agent

The MCP server extended the documentation experiment.

It helped me test another layer:

API contract
    ↓
Documentation
    ↓
Operational guidance
    ↓
Grounding
    ↓
MCP tools

The tool descriptions also mattered. Once an API operation becomes a tool, the description becomes another piece of context that helps an agent understand what the tool does and when it should use it.

How to apply this to your own API documentation

Everything in this article was tested using TaskSocial, but the workflow applies to other APIs.

You do not need to build everything at once. Start with the contract and add each layer step by step.

1. Start with a reliable API contract

Create a structured source of truth for your API. For me, that was OpenAPI.

Your contract should describe:

  • endpoint paths

  • HTTP methods

  • request and response schemas

  • parameters

  • authentication requirements

Then validate it before using it as the basis for documentation.

Working API
    ↓
OpenAPI specification
    ↓
Linting and validation
    ↓
Documentation

This becomes more important when AI systems are involved. An endpoint can look reasonable without actually existing:

GET /api/v1/tasks

The documented operation is:

GET /api/v1/tasks/my-tasks

The contract should be the source of truth.

2. Keep documentation inside the development workflow

Keep documentation in Git and manage changes through branches and pull requests.

Documentation change
    ↓
Git branch
    ↓
Pull request
    ↓
Review
    ↓
Merge
    ↓
Deployment

This makes documentation changes visible and reviewable. When the API changes, update the contract or documentation, validate it, review the change, and deploy it.

3. Document more than endpoint descriptions

An API reference answers:

  • What endpoint exists?

  • What parameters are required?

  • What response does it return?

But AI systems also need to answer, "Should this operation be performed right now?" For an update request, operational guidance should document:

  • when clarification is required

  • what information must be identified first

  • ownership requirements

  • preconditions

  • error handling

For example:

If the target resource is unclear, do not perform the operation.

Ask the user for clarification or retrieve the information
required to identify the correct resource first.

This does not replace the API reference. It adds context around when an operation should be used.

4. Add explicit grounding rules

My experiment showed that correct reasoning can still produce an incorrect API detail.

Use a rule like this:

Before recommending or performing an API operation:

1. Verify the exact endpoint path.
2. Verify the HTTP method.
3. Check required parameters.
4. Check authentication requirements.
5. Check operational preconditions.

If the operation cannot be confirmed in the documented API contract,
do not invent an endpoint.

A plausible-looking API path is not the same as a documented API operation.

5. Make documentation machine-readable, but test discovery

Formats such as llms.txt and llms-full.txt make documentation easier for AI systems to consume.

But test whether the system actually finds and uses them.

Documentation available
        ≠
Documentation discovered
        ≠
Documentation actually used

6. Carry the same contract into AI tools

If you expose your API through MCP or another tool interface, map the tools back to the documented contract.

OpenAPI contract
      ↓
Developer documentation
      ↓
Operational guidance
      ↓
API grounding
      ↓
Machine-readable access
      ↓
AI tools

Architecture showing the flow from OpenAPI contract to AI tools

The important part is that these layers should reinforce the same API contract.

A practical checklist

If you want to try a similar workflow, start here:

  • Create or update an OpenAPI specification.

  • Validate and lint the contract.

  • Use the contract as the source for your API reference.

  • Keep documentation in Git.

  • Review documentation changes through pull requests.

  • Add guides for authentication and common workflows.

  • Document operational rules, not only endpoint descriptions.

  • Add explicit guidance against inventing undocumented operations.

  • Test AI answers against the documented contract.

  • Provide machine-readable documentation where appropriate.

  • Test whether AI systems can actually discover and retrieve it.

  • If you expose operations as tools, map them back to the contract.

  • Test the complete workflow instead of assuming it works.

You do not need to implement everything at once. I started with a working API. Then I created an OpenAPI contract, moved the documentation into Git, deployed it, and only then started testing how AI used it.

That testing is how I found the incorrect GET /api/v1/tasks assumption in the first place.

Final takeaway

The tools I used were OpenAPI, Redocly, GitHub, Mintlify, and a small MCP server. You can use whichever tooling works for your project. The important part is the workflow and the questions you ask while testing it.

AI is becoming another consumer of technical documentation. That does not make developer documentation less important. It gives the same documentation another consumer with different requirements.

Developers need to understand and use the API. AI assistants need accurate information. Agents may need operational rules. Tools need clear descriptions and reliable mappings.

Those are connected problems, but they are not exactly the same problem.

As I keep exploring how documentation changes when autonomous agents become more common consumers of APIs, my biggest takeaway is that documentation for AI should be designed, grounded, and tested.

About author

Book A Call!

Reach Your Technical Audience And Drive Product Adoption.

We are engineers, developer advocates, and marketers passionate about creating lasting value for SaaS teams. Partner with us to create the human-written developer marketing, SEO, demand-gen, and documentation content.

Get started

*35% less cost, risk-free, no lock-in.

Logo 1
Logo 2
Logo 3
Logo 4
Logo 5
Logo 6
Logo 7
Logo 8
Logo 9
Logo 10
Logo 11
Logo 12
Logo 13
Logo 14
Logo 15
Logo 16
Logo 17
Logo 18