matija2209

payload plugin api guide

by matija2209
APIs & SDKs
v3
>=3.85.0 <4
MIT

Overview

Summary generated from the README

Reads your Payload config and serves project-specific API documentation under a configurable route. It produces an HTML guide, an OpenAPI 3.1 spec, a Scalar-based API browser, agent instructions, a JSON project map, llms.txt and query recipes. Requires Payload 3.85.0 or later and is added through the plugins array.

Features

  • OpenAPI 3.1 spec covering every collection and global
  • Interactive API browser using Scalar UI
  • Markdown and JSON guides written for AI coding agents
  • llms.txt entry point linking all generated resources
  • Per-collection query recipes such as slug lookup, pagination and field selection
  • Options for base path, title, auth collections and enabling or disabling

Use cases

  • Give AI coding agents correct Payload REST query patterns for your project
  • Publish an up-to-date API reference for frontend developers
  • Prevent common mistakes like fetching by slug as a path segment

From the author

Generate a live API reference and agent-first query guide for your Payload CMS project

Installation

npm i @matija2209/payload-agent-api-guide

2

Stars

0

Forks

0

Open Issues

6 months ago

Last Updated

8

Weekly Downloads

v1.0.1

npm Version

121.2 KB

Unpacked Size

0

Dependencies

GitHub stars

20 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20262
Dec 5, 20262
Dec 4, 20262
Dec 3, 20262
Dec 2, 20262
Dec 1, 20262
Nov 30, 20262
Nov 29, 20262
Nov 28, 20262
Nov 27, 20262
Nov 26, 20262
Nov 25, 20262
Nov 24, 20262
Nov 23, 20262
Nov 22, 20262
Nov 21, 20262
Nov 20, 20262
Nov 19, 20262
Nov 18, 20262
Nov 17, 20262
Nov 16, 20262
Nov 15, 20262
Nov 14, 20262
Nov 13, 20262
Nov 12, 20262
Nov 11, 20262
Nov 10, 20262
Nov 9, 20262
Nov 8, 20262
Nov 7, 20262
Nov 6, 20262
Nov 5, 20262
Nov 4, 20262
Nov 3, 20262
Nov 2, 20262
Nov 1, 20262
Oct 31, 20262
Oct 30, 20262
Oct 29, 20262
Oct 28, 20262
Oct 27, 20262
Oct 26, 20262
Oct 25, 20262
Oct 24, 20262
Oct 23, 20262
Oct 22, 20262
Oct 21, 20262
Oct 20, 20262
Oct 19, 20262
Oct 18, 20262
Oct 17, 20262
Oct 16, 20262
Oct 15, 20262
Oct 14, 20262
Oct 13, 20262
Oct 12, 20262
Oct 11, 20262
Oct 10, 20262
Oct 9, 20262
Oct 8, 20262
Oct 7, 20262
Oct 6, 20262
Oct 5, 20262
Oct 4, 20262
Oct 3, 20262
Oct 2, 20262
Oct 1, 20262
Sep 30, 20262
Sep 29, 20262
Sep 28, 20262
Sep 27, 20262
Sep 26, 20262
Sep 25, 20262
Sep 24, 20262
Sep 23, 20262
Sep 22, 20262
Sep 21, 20262
Sep 20, 20262
Sep 19, 20262
Sep 18, 20262
Sep 17, 20262
Sep 16, 20262
Sep 15, 20262
Sep 14, 20262
Sep 13, 20262
Sep 12, 20262
Sep 11, 20262
Sep 10, 20262
Sep 9, 20262
Sep 8, 20262
Sep 7, 20262
npm weekly downloads

8+3 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 20268
Dec 5, 20265
Dec 4, 20266
Dec 3, 20266
Dec 2, 20264
Dec 1, 20265
Nov 30, 20267
Nov 29, 20267
Nov 28, 20266
Nov 27, 20265
Nov 26, 20264
Nov 25, 20264
Nov 24, 20263
Nov 23, 20261
Nov 22, 20263
Nov 21, 20264
Nov 20, 20264
Nov 19, 20264
Nov 18, 20266
Nov 17, 20265
Nov 16, 20265
Nov 15, 20264
Nov 14, 20263
Nov 13, 20263
Nov 12, 20263
Nov 11, 20261
Nov 10, 20263
Nov 9, 20263
Nov 8, 20264
Nov 7, 20266
Nov 6, 20266
Nov 5, 20266
Nov 4, 20268
Nov 3, 20266
Nov 2, 20267
Nov 1, 20266
Oct 31, 20265
Oct 30, 20265
Oct 29, 20265
Oct 28, 20263
Oct 27, 20264
Oct 26, 20263
Oct 25, 20263
Oct 24, 20262
Oct 23, 20262
Oct 22, 20264
Oct 21, 20264
Oct 20, 20263
Oct 19, 20266
Oct 18, 20266
Oct 17, 20266
Oct 16, 20266
Oct 15, 20264
Oct 14, 20264
Oct 13, 20264
Oct 12, 20261
Oct 11, 20261
Oct 10, 20262
Oct 9, 20262
Oct 8, 20262
Oct 7, 20262
Oct 6, 20262
Oct 5, 20262
Oct 4, 20261
Oct 3, 20260
Oct 2, 20260
Oct 1, 20260
Sep 30, 20260
Sep 29, 20260
Sep 28, 20260
Sep 27, 20260
Sep 26, 20265
Sep 25, 20265
Sep 24, 20265
Sep 23, 20265
Sep 22, 20266
Sep 21, 20268
Sep 20, 202611
Sep 19, 20266
Sep 18, 20267
Sep 17, 20268
Sep 16, 20268
Sep 15, 20269
Sep 14, 20267
Sep 13, 20264
Sep 12, 20265
Sep 11, 20264
Sep 10, 20264
Sep 9, 20265
Sep 8, 20264
Sep 7, 20265

Each point is npm's rolling 7-day download count.

Health Score

44/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1258571172-root.svg)](https://payloaddirectory.dev/plugins/1258571172-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1258571172-root"><img src="https://payloaddirectory.dev/badge/1258571172-root.svg" alt="Payload Directory"></a>
Updated Jun 4, 2026Created Jun 3, 2026Published Jun 4, 2026

README

@matija2209/payload-agent-api-guide

Generate a live API reference and agent-first query guide from your Payload CMS configuration.

This plugin reads your live Payload config and turns it into practical API documentation, an OpenAPI reference, and agent-readable instructions — so developers and AI coding agents can understand how to query your project without guessing.


Why

Payload's REST API is powerful, but beginners and AI agents often get the details wrong. They may assume generic REST patterns — for example, fetching a post by slug with /api/posts/my-slug — instead of using Payload's actual query syntax with where.slug.equals.

This plugin solves that by generating project-specific documentation directly from your Payload setup.


Routes

All routes are served under {payload.routes.api}/api-guide (default: /api/api-guide).

RouteDescription
/api/api-guideHuman-readable HTML guide
/api/api-guide/referenceInteractive API browser (Scalar UI)
/api/api-guide/openapi.jsonOpenAPI 3.1 spec
/api/api-guide/agent.mdConcise rules guide for AI coding agents
/api/api-guide/agent.jsonStructured project map (collections, fields, endpoints)
/api/api-guide/llms.txtLLM entry point with links to all resources
/api/api-guide/query-recipes.jsonCommon query patterns per collection

Installation

npm install @matija2209/payload-agent-api-guide
# or
pnpm add @matija2209/payload-agent-api-guide

Peer dependency: payload >= 3.85.0


Usage

import { buildConfig } from 'payload'
import { apiGuidePlugin } from '@matija2209/payload-agent-api-guide'

export default buildConfig({
  plugins: [
    apiGuidePlugin({
      title: 'My Project API Guide',
    }),
  ],
  // ...rest of config
})

Options

type ApiGuidePluginOptions = {
  /** Disable the plugin without removing it. Default: true */
  enabled?: boolean

  /** Base path under the Payload API route. Default: '/api-guide' */
  basePath?: string

  /** Title shown in the HTML guide and OpenAPI spec. Default: 'Payload API Guide' */
  title?: string

  /** Include auth-enabled collections. Default: true */
  includeAuth?: boolean
}

What gets generated

From your collections

For each collection the plugin reads:

  • slug, labels (singular/plural)
  • all field names, types, required status, localization
  • relationship fields and their targets
  • upload fields
  • whether a slug field exists (for slug-based fetch recipes)
  • whether drafts are enabled
  • whether auth is enabled
  • whether it is an upload collection

From your globals

For each global:

  • slug, label
  • all field names and types

Generated outputs

/api/api-guide — A self-contained HTML page explaining how to use the REST API for this specific project. Includes field tables per collection, fetch examples, and a common-mistakes section.

/api/api-guide/reference — Scalar UI loaded from CDN, pointed at the generated OpenAPI spec.

/api/api-guide/openapi.json — A complete OpenAPI 3.1 spec with:

  • Paths for every collection (GET, POST, PATCH, DELETE) and global (GET, POST)
  • Slug-based fetch path for collections that have a slug field
  • Shared query parameter components (where, depth, select, limit, page, sort, locale, draft)
  • Schema components per collection derived from field definitions

/api/api-guide/agent.md — A markdown guide written for AI coding agents. Includes:

  • Critical rules (slug fetch pattern, qs-esm usage, depth, select, pagination)
  • qs-esm code example
  • Per-collection field tables and fetch examples
  • Common mistakes table

/api/api-guide/agent.json — A structured JSON project map. Includes:

  • apiBase, collections, globals
  • Per-collection: field list, endpoint URLs, slug field name, draft/auth/upload traits
  • queryGuide block explaining Payload REST conventions in machine-readable form

/api/api-guide/llms.txt — An entry-point file for LLMs following the llms.txt convention. Lists all generated resources with links.

/api/api-guide/query-recipes.json — An array of concrete query recipes per collection:

  • List documents
  • Fetch by ID
  • Fetch by slug (where-based)
  • Paginated fetch
  • Fetch only published (for draft-enabled collections)
  • Fetch with populated relationships
  • Fetch with selected fields only
  • Fetch global

Agent workflow

The recommended agent workflow when entering a Payload project with this plugin:

  1. Read /api/api-guide/llms.txt for an overview of available resources
  2. Read /api/api-guide/agent.md for the rules of how to query this project
  3. Inspect /api/api-guide/agent.json for collections, fields, and endpoint patterns
  4. Use /api/api-guide/openapi.json for formal endpoint reference
  5. Write fetch code using the project-specific field names and query patterns

Key rule

Never fetch by slug as a path segment.

This is the most common Payload REST mistake:

// Wrong — returns 404 or wrong data
fetch('/api/posts/my-slug')

// Correct — use where query
fetch('/api/posts?where[slug][equals]=my-slug&limit=1')
  .then(r => r.json())
  .then(({ docs }) => docs[0])

Use qs-esm to build where queries safely:

import qs from 'qs-esm'

const query = qs.stringify({
  where: { slug: { equals: 'my-post' } },
  depth: 1,
  limit: 1,
})
const res = await fetch(`/api/posts?${query}`)
const { docs } = await res.json()
const post = docs[0]

Requirements

  • Payload >= 3.85.0
  • Node.js >= 18.20.2

Release process

The package is intended to publish compiled output from dist/.

Before publishing locally:

pnpm install
pnpm build
pnpm test:int
npm pack --dry-run
npm publish --dry-run

For the first public release, publish manually:

npm publish --access public

After the package exists on npm, configure npm trusted publishing for @matija2209/payload-agent-api-guide and use the GitHub Actions workflows in .github/workflows/.

Recommended release flow:

  1. Open a PR and let .github/workflows/ci.yml run build, lint, integration tests, and e2e.
  2. Bump package.json to the next version and commit it.
  3. Create a matching tag like v1.0.1.
  4. Push the commit and the tag.
  5. .github/workflows/publish.yml publishes only if the tag matches the package version exactly.

License

MIT

Similar plugins