DeepWiki Backend API Endpoints: Complete Reference Guide

The DeepWiki backend exposes REST and WebSocket endpoints including /chat/completions/stream for LLM streaming, /export/wiki for documentation export, and /api/wiki_cache for caching, all implemented in a FastAPI application.

DeepWiki is an open-source tool that automatically generates documentation for code repositories using large language models. The backend API, found in the AsyncFuncAI/deepwiki-open repository, provides the core infrastructure for streaming chat completions, managing wiki caches, and exporting documentation. Understanding these DeepWiki backend API endpoints is essential for developers integrating with the service or extending its functionality.

Core DeepWiki Backend API Endpoints

The FastAPI application registers several high-level routes that handle repository analysis, chat streaming, and data persistence.

Streaming Chat Completion (/chat/completions/stream)

The /chat/completions/stream endpoint handles real-time LLM interactions for repository-specific questions. Located in api/simple_chat.py at line 76, this POST endpoint accepts a JSON payload containing the repository URL, chat history, and optional file-path hints.

The implementation parses the request, builds a RAG (Retrieval-Augmented Generation) instance, and streams responses using Server-Sent Events (text/event-stream). It supports multiple providers including Google Gemini, OpenAI, Ollama, Azure AI, and DashScope.

curl -X POST http://localhost:8001/chat/completions/stream \
  -H "Content-Type: application/json" \
  -d '{
        "repo_url":"https://github.com/AsyncFuncAI/deepwiki-open",
        "messages":[{"role":"user","content":"Summarize the project"}],
        "provider":"google",
        "model":"gemini-2.5-flash"
      }' --no-buffer

Wiki Export (/export/wiki)

The /export/wiki endpoint, defined in api/api.py at line 227, enables downloading generated documentation as Markdown or JSON files. This POST endpoint returns a downloadable file with the Content-Disposition: attachment header set.

The request body must include the repository URL, an array of page objects (each with id, title, and content), and the desired format.

curl -X POST http://localhost:8001/export/wiki \
  -H "Content-Type: application/json" \
  -d '{
        "repo_url":"https://github.com/AsyncFuncAI/deepwiki-open",
        "pages":[
          {"id":"1","title":"Intro","content":"..."},
          {"id":"2","title":"Installation","content":"..."}
        ],
        "format":"markdown"
      }' -OJ

The -OJ flag instructs curl to use the server-provided filename, typically formatted as {repo_name}_wiki_{timestamp}.{ext}.

Wiki Cache Management (/api/wiki_cache)

The /api/wiki_cache endpoint provides full CRUD operations for persisting generated wiki data, implemented across multiple methods in api/api.py.

GET (line 461): Retrieves cached wiki structure and generated pages for a specific repository and language. Returns null when no cache exists.

curl "http://localhost:8001/api/wiki_cache?owner=AsyncFuncAI&repo=deepwiki-open&repo_type=github&language=en"

POST (line 486): Stores a fresh wiki cache including repository metadata, language, wiki structure, generated pages, and the LLM provider information used for generation.

curl -X POST http://localhost:8001/api/wiki_cache \
  -H "Content-Type: application/json" \
  -d '{
        "repo":{"owner":"AsyncFuncAI","repo":"deepwiki-open","type":"github"},
        "language":"en",
        "wiki_structure":{...},
        "generated_pages":{...},
        "provider":"google",
        "model":"gemini-2.5-flash"
      }'

DELETE (line 504): Removes a specific cache file, protected by an optional authentication code.

Project Listing and Utilities

/api/processed_projects (line 577 in api/api.py): Returns an array of all repositories that currently have cached wiki files. Each entry includes the cache ID, owner, repository name, type, submission timestamp, and language code.

curl http://localhost:8001/api/processed_projects

/local_repo/structure (line 275 in api/api.py): Returns a JSON representation of a local repository's file tree along with its README content, useful for analyzing repositories not yet hosted on remote Git servers.

/health (line 540 in api/api.py): A simple health-check endpoint returning status 200, used by Docker and Kubernetes probes to verify service availability.

WebSocket Real-Time Communication

In addition to REST endpoints, DeepWiki provides WebSocket support for interactive chat sessions.

/ws/chat Endpoint

The /ws/chat WebSocket endpoint, defined in api/websocket_wiki.py, handles bi-directional communication for real-time streaming chat. This endpoint is used by the DeepWiki UI to maintain persistent connections during documentation queries, allowing for incremental token delivery without the overhead of repeated HTTP requests.

The WebSocket handler processes incoming messages containing repository context and chat history, then streams LLM responses back to the client as they are generated.

Implementation Architecture

The DeepWiki backend organizes its functionality across several key modules:

  • api/api.py: Core FastAPI application registering all REST routes, wiki-cache helpers (get_wiki_cache_path, read_wiki_cache, save_wiki_cache), export logic, health checks, and the root endpoint.
  • api/simple_chat.py: Implements the streaming chat completion endpoint with RAG integration.
  • api/websocket_wiki.py: Manages WebSocket connections for real-time chat.
  • api/rag.py: Core retrieval-augmented generation logic, building retrievers and managing memory.
  • api/config.py: Central configuration for language settings, authentication modes, and default model providers.

Cache files are stored as JSON under the directory returned by get_adalflow_default_root_path() in a wikicache/ subdirectory.

Summary

  • DeepWiki backend API endpoints provide comprehensive functionality for automated documentation generation, including streaming LLM chat, wiki export, and cache management.
  • The /chat/completions/stream endpoint in api/simple_chat.py handles real-time chat with multiple LLM providers via Server-Sent Events.
  • The /export/wiki endpoint generates downloadable Markdown or JSON documentation files with proper content disposition headers.
  • The /api/wiki_cache endpoint supports full CRUD operations for persisting generated wiki data, located at lines 461, 486, and 504 in api/api.py.
  • WebSocket support via /ws/chat in api/websocket_wiki.py enables bi-directional real-time communication for interactive documentation queries.

Frequently Asked Questions

What authentication does the DeepWiki backend API require?

Most DeepWiki backend API endpoints are open by default, but the DELETE method on /api/wiki_cache supports an optional authentication code for protection. The authentication mode and codes are configured in api/config.py. For production deployments, you should implement additional middleware or reverse proxy authentication as the codebase does not include built-in JWT or OAuth flows.

How does the streaming chat endpoint handle different LLM providers?

The /chat/completions/stream endpoint abstracts provider differences through a RAG class defined in api/rag.py. The endpoint accepts a provider parameter (e.g., "google", "openai", "ollama") and a model string, then instantiates the appropriate client wrapper from files like api/openai_client.py, api/azureai_client.py, or api/dashscope_client.py. All providers return responses through a unified streaming interface using Server-Sent Events.

What is the difference between the REST chat endpoint and the WebSocket endpoint?

The REST endpoint /chat/completions/stream in api/simple_chat.py uses HTTP POST with Server-Sent Events for one-way streaming from server to client, suitable for stateless request-response cycles. The WebSocket endpoint /ws/chat in api/websocket_wiki.py maintains a persistent bi-directional connection, allowing the client to send multiple messages and receive incremental updates without re-establishing connections, which is preferred for interactive UI chat interfaces.

How is the wiki cache storage organized on disk?

Wiki caches are stored as JSON files in a wikicache/ subdirectory under the path returned by get_adalflow_default_root_path(). The filename is generated from repository metadata using the pattern deepwiki_cache_{repo_type}_{owner}_{repo}_{language}.json. The WikiCacheData schema includes fields for repository info, language code, wiki structure, generated pages, and the LLM provider details used during generation.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →