# Does 9router Generate API Documentation? A Deep Dive into the Codebase

> Discover if 9router generates API documentation. Learn how to build your own API docs from Next.js route files with this in-depth codebase analysis of decolua/9router.

- Repository: [decolua/9router](https://github.com/decolua/9router)
- Tags: deep-dive
- Published: 2026-05-08

---

**9router does not automatically generate API documentation or ship with an OpenAPI specification, requiring developers to manually construct documentation from the Next.js API route files.**

9router functions as a **router-and-proxy** for LLM, image-generation, and TTS providers, exposing its functionality through a REST interface built on Next.js API routes. While the project provides a robust HTTP surface for interacting with multiple AI providers, it takes an **implementation-centric approach** that omits built-in documentation generators. If you're integrating with 9router and need formal API specifications, you'll need to construct them yourself or employ third-party tooling to introspect the source routes.

## How 9router Handles API Documentation

The repository maintains its public HTTP surface through a collection of **Next.js API route files** located in `src/app/api/v1/`. These files define the actual endpoints that clients interact with, but the project does not include any automatic documentation assembly.

### The Route-Based Architecture

According to the 9router source code, the API is organized as standard Next.js App Router handlers. For example, the model listing endpoint is implemented in [`src/app/api/v1/models/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/models/route.js):

```javascript
// src/app/api/v1/models/route.js
export default async function handler(req, res) {
  // Returns a list of model IDs the router knows about.
  const models = await getAvailableModels();
  res.status(200).json(models);
}

```

Similarly, core functionality resides in files like [`src/app/api/v1/chat/completions/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/chat/completions/route.js) for chat completions and [`src/app/api/v1/embeddings/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/embeddings/route.js) for text embeddings. These plain JavaScript handlers process HTTP requests directly without generating metadata for documentation tools.

### Missing Documentation Tooling

A comprehensive search of the repository reveals **no OpenAPI or Swagger infrastructure**. Specifically, 9router does not include:

- A [`swagger.json`](https://github.com/decolua/9router/blob/main/swagger.json) or [`openapi.yaml`](https://github.com/decolua/9router/blob/main/openapi.yaml) specification file
- Documentation generators such as `swagger-jsdoc`, `express-openapi`, or `next-openapi` in dependencies
- Code comments or JSDoc annotations that automated tools could parse
- An `/api-docs` or `/swagger` endpoint for serving interactive documentation

The project searches for terms like "openapi", "swagger", or "api-docs" return only unrelated external HTTP calls, indicating that documentation generation is deliberately left to downstream consumers.

## Manual Documentation Strategies

Since 9router does not generate API documentation automatically, you must create specifications manually or use third-party scanners. Here are four approaches to documenting the 9router API surface.

### Inspecting Existing Routes

Begin by examining the source route files to understand request methods and response shapes. The [`src/app/api/v1/models/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/models/route.js) handler serves GET requests and returns a JSON array of model identifiers:

```javascript
// src/app/api/v1/models/route.js
export default async function handler(req, res) {
  const models = await getAvailableModels();
  res.status(200).json(models);
}

```

Other critical endpoints follow this pattern in their respective files:
- [`src/app/api/v1/chat/completions/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/chat/completions/route.js) - Handles POST requests for LLM chat completions
- [`src/app/api/v1/embeddings/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/embeddings/route.js) - Processes text embedding requests
- [`src/app/api/v1/usage/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/usage/route.js) - Returns quota and billing statistics
- [`src/app/api/v1/providers/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/providers/route.js) - Lists supported providers and capabilities

### Writing an OpenAPI Specification Manually

Create a handwritten [`openapi.yaml`](https://github.com/decolua/9router/blob/main/openapi.yaml) file that mirrors the route structure. This YAML defines the contract that 9router honors without modifying the source code:

```yaml

# openapi.yaml (partial)

openapi: 3.0.0
info:
  title: 9router API
  version: 1.0.0
paths:
  /api/v1/models:
    get:
      summary: List models known to the router
      responses:
        '200':
          description: An array of model IDs
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string

```

Place this file in your project root and version control it alongside the 9router source.

### Serving the Spec via a Next.js Route

Expose your manual specification through the 9router server itself by creating a new route file at [`src/app/api/v1/openapi/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/openapi/route.js):

```javascript
// src/app/api/v1/openapi/route.js
import fs from 'fs';
import path from 'path';

export default async function handler(_, res) {
  const specPath = path.resolve(process.cwd(), 'openapi.yaml');
  const spec = fs.readFileSync(specPath, 'utf8');
  res.setHeader('Content-Type', 'application/vnd.oai.openapi');
  res.status(200).send(spec);
}

```

This endpoint serves your documentation at `/api/v1/openapi`, making it discoverable to API clients.

### Using Third-Party Generators

Install community tooling to scan the Next.js routes and emit OpenAPI JSON automatically:

```bash

# Install the helper in the repo root

npm install --save-dev next-openapi

```

Configure the scanner to target the API directory:

```javascript
// next-openapi.config.js
module.exports = {
  output: './openapi.json',
  apis: ['./src/app/api/**/*.js'],
};

```

Running `npx next-openapi` introspects the route handlers and generates a specification, though you may need to manually refine the output since 9router lacks JSDoc type annotations that such tools typically require.

## Key Files That Define the API Surface

The following route files collectively constitute 9router's public HTTP API. Documentation efforts should prioritize these endpoints:

- **src/app/api/v1/models/route.js** - Returns available model IDs and provider mappings
- **src/app/api/v1/chat/completions/route.js** - Core LLM chat completion endpoint (OpenAI-compatible)
- **src/app/api/v1/embeddings/route.js** - Text embedding generation interface
- **src/app/api/v1/usage/route.js** - Usage statistics and quota monitoring
- **src/app/api/v1/providers/route.js** - Provider capability discovery and health checks

## Summary

- **9router does not generate API documentation automatically** and ships without OpenAPI, Swagger, or similar specifications.
- The API surface consists of **Next.js route files** in `src/app/api/v1/` that handle requests directly without metadata generation.
- **Manual documentation** requires either handwriting OpenAPI YAML based on route inspection or using third-party scanners like `next-openapi`.
- Key endpoints reside in specific route files such as [`src/app/api/v1/chat/completions/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/chat/completions/route.js) and [`src/app/api/v1/models/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/models/route.js).
- You can serve custom documentation by creating a new route that reads a static spec file and returns it with the appropriate content type.

## Frequently Asked Questions

### Does 9router include Swagger UI or an OpenAPI specification?

No. The repository contains no [`swagger.json`](https://github.com/decolua/9router/blob/main/swagger.json), [`openapi.yaml`](https://github.com/decolua/9router/blob/main/openapi.yaml), or interactive documentation endpoints. The search for documentation-related terms returns only external API calls to provider services, not internal documentation infrastructure.

### How can I generate API documentation for 9router automatically?

You must use third-party tools like `next-openapi` that scan the JavaScript files in `src/app/api/`, or manually write an OpenAPI specification based on the request/response patterns found in route handlers such as [`src/app/api/v1/chat/completions/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/chat/completions/route.js).

### Where are the API endpoints defined in the 9router codebase?

Endpoints are defined as Next.js App Router handlers in the `src/app/api/v1/` directory. Each subfolder contains a [`route.js`](https://github.com/decolua/9router/blob/main/route.js) file that exports a default handler function processing HTTP methods for that specific path segment.

### Is there a Postman collection available for 9router?

No official Postman collection exists in the repository. You would need to manually create collection requests based on the route implementations in files like [`src/app/api/v1/embeddings/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/embeddings/route.js) and [`src/app/api/v1/usage/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/usage/route.js), or generate one from a manually crafted OpenAPI specification.