# Fumadocs (Framework Mode, Next.js): AsyncAPI
URL: /docs/next/integrations/asyncapi
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/asyncapi/index.mdx

Generating docs for AsyncAPI schema.

## Setup [#setup]

Install the required packages.

```npm
npm i @fumadocs/asyncapi shiki
```

### Generate Styles [#generate-styles]

Add the following line:

```css title="Tailwind CSS"
@import 'tailwindcss';
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';
/* [!code ++] */
@import '@fumadocs/asyncapi/css/preset.css';
```

### Configure Plugin [#configure-plugin]

Create the AsyncAPI server instance and the `<AsyncAPIPage />` component.

```ts tab="lib/asyncapi.ts"
import { createAsyncAPI } from '@fumadocs/asyncapi/server';

// note: this is a server-side API
export const asyncapi = createAsyncAPI({
  // the AsyncAPI schema, you can also give it an external URL.
  input: ['./asyncapi.yaml'],
});
```

```tsx tab="components/api-page.tsx"
'use client';
import { createAsyncAPIPage } from '@fumadocs/asyncapi/ui';

export const AsyncAPIPage = createAsyncAPIPage();
```

See [`createAsyncAPI()`](/docs/next/integrations/asyncapi/server) and [`createAsyncAPIPage()`](/docs/next/integrations/asyncapi/api-page) for their options.

### Generate Pages [#generate-pages]

Pass `staticSource()` to your [`loader()`](/docs/headless/source-api/source). It generates pages without writing files.

```ts title="lib/source.ts"
import { loader } from 'fumadocs-core/source';
import { defineDocs } from 'fumadocs-mdx/macro';
import { asyncapi } from '@/lib/asyncapi'; // [!code ++]

const docs = defineDocs({
  dir: 'content/docs',
});

export const source = loader(
  // [!code ++:6]
  {
    docs: docs.toFumadocsSource(),
    asyncapi: await asyncapi.staticSource({
      baseDir: 'asyncapi',
    }),
  },
  {
    baseUrl: '/docs',
    // [!code ++:2] optional: adds the direction of messages to each page item in page tree
    plugins: [asyncapi.loaderPlugin()],
  },
);
```

`staticSource()` generates a page per operation by default. See [Generating Pages](/docs/next/integrations/asyncapi/generate-files) to customize them.

**Pages of `source` now have two types, `docs` and `asyncapi`.** Update every place that uses `source`, like where you return text for LLMs:

```ts
import { llms } from 'fumadocs-core/source';
import { source } from '@/lib/source';

export const docsLlms = llms(source, {
  renderPage: async (page) => {
    // [!code ++:3]
    if (page.type === 'asyncapi') {
      return `# ${page.data.title}\n\n${await page.data.getText('processed')}`;
    }

    // your original flow below...
  },
});
```

Render AsyncAPI pages with `<AsyncAPIPage />` in your docs page:

```tsx title="app/docs/[[...slug]]/page.tsx"
import { AsyncAPIPage } from '@/components/api-page'; // [!code ++]

export default async function Page(props: PageProps<'/docs/[[...slug]]'>) {
  const params = await props.params;
  const page = source.getPage(params.slug);
  if (!page) notFound();

  // [!code ++:10]
  if (page.type === 'asyncapi') {
    return (
      <DocsPage full>
        <DocsTitle>{page.data.title}</DocsTitle>
        <DocsBody>
          <AsyncAPIPage {...page.data.getAsyncAPIPageProps()} />
        </DocsBody>
      </DocsPage>
    );
  }

  // ...
}
```

<Callout type="warn" title="Ensure the migration is complete!">
Run a type check before continuing:

```npm
npm run types:check
```
</Callout>

To write MDX files into your content directory instead, see [MDX Files](/docs/next/integrations/asyncapi/generate-files#mdx-files).

## Features [#features]

The official AsyncAPI integration supports AsyncAPI 3:

- The direction of messages for readers, the server and channel address of operations
- Messages with their payload and header schemas, including Avro, Protobuf and RAML schemas
- Message examples, from the document or generated from schemas
- Request and reply, correlation IDs
- Security schemes, including OAuth 2.0 flows and SASL mechanisms
- Protocol details from bindings, for the selected server
- A playground for WebSocket, Server-Sent Events and custom transports, with text and binary messages
- Code samples in JavaScript and Python, for WebSocket, MQTT, Kafka, AMQP and NATS
- TypeScript definitions of payloads and headers
- Markdown of pages for LLMs
- Traits

AsyncAPI 2 documents can be converted with `npx @asyncapi/cli convert`.

### Demo [#demo]

See the [AsyncAPI example](/docs/asyncapi).