# Fumadocs (Framework Mode, Waku): createAsyncAPI()
URL: /docs/waku/integrations/asyncapi/server
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/asyncapi/server.mdx

The AsyncAPI server instance.

## AsyncAPI Server [#asyncapi-server]

The main config for Fumadocs AsyncAPI.

> It should not be referenced in browser environments.

### `input` [#input]

The AsyncAPI schemas to read from.

- File Paths
- External URLs
- Functions (see below)

Only schemas listed here can be loaded, other IDs passed to `getSchema()` or preloaded by pages throw an error.

<Callout type="warn">
Do not pass untrusted schemas to `input`, their `$ref`s can read local files and fetch URLs, private hosts included.
</Callout>

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

export const asyncapi = createAsyncAPI({
  input: ['./streetlights.yaml'],
});
```

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

export const asyncapi = createAsyncAPI({
  input: {
    // [id]: downloaded AsyncAPI Schema
    galaxy: async () => {
      const res = await fetch('https://example.com/asyncapi.yaml');
      return res.text();
    },
  },
});
```

### `disableCache` [#disablecache]

Disable caching of loaded schemas. Useful during development when schemas change frequently.

```ts
import { createAsyncAPI } from '@fumadocs/asyncapi/server';

export const asyncapi = createAsyncAPI({
  input: ['./asyncapi.yaml'],
  disableCache: true,
});
```

## Loading Documents Once [#loading-documents-once]

Pages receive the whole document in their props, so every page load, navigation and prefetch sends it again. For large documents, leave it out:

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

export const asyncapi = createAsyncAPI({
  // IDs end up in URLs, keep them URL-safe
  input: { streetlights: './streetlights.yaml' },
  includeDocument: false, // [!code ++]
});
```

Pass `loadDocument` to load each document once per browser session. It also runs during server rendering:

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

export const AsyncAPIPage = createAsyncAPIPage({
  async loadDocument(id) {
    if (import.meta.env.SSR) {
      // the browser starts downloading it with the page
      preload(`/api/asyncapi/${id}`, { as: 'fetch', crossOrigin: 'anonymous' });
      const { asyncapi } = await import('@/lib/asyncapi');
      return (await asyncapi.getSchema(id)).bundled;
    }
    return (await fetch(`/api/asyncapi/${id}`)).json();
  },
});
```

Serve the documents to the browser from a route:

```ts title="src/pages/_api/api/asyncapi/[id].ts"
import type { ApiContext } from 'waku/router';
import { asyncapi } from '@/lib/asyncapi';

export async function GET(_: Request, { params }: ApiContext<'/api/asyncapi/[id]'>) {
  return Response.json((await asyncapi.getSchema(params.id)).bundled);
}
```

- `loadDocument` works with generated MDX files too.
- For the [UI installed by Fumadocs CLI](/docs/waku/integrations/asyncapi/api-page#full-ui), pass `loadDocument` to `createAsyncAPIRenderer()`.
- Browsers keep each document until a reload. With [`disableCache`](#disablecache), leave `includeDocument` on.