DEV Community

zhaochangbo888
zhaochangbo888

Posted on

I Built an API That Writes Code Documentation in 13 Languages — Here's How

I’ve always disliked writing documentation. Not because it’s hard, but because it’s repetitive. You write a function, you describe what it does, you give an example, and then you realize you need the same thing in another language because half your users don’t speak English.

So I decided to automate it.

The result is an API that takes source code as input and returns a clean Markdown README, API reference, or inline comments — in any of 13 languages. No templates, no manual translation.

curl -X POST "https://ai-code-documentation-generator.p.rapidapi.com/demo" \
  -H "x-rapidapi-host: ai-code-documentation-generator.p.rapidapi.com" \
  -H "x-rapidapi-key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"code":"def add(a,b): return a+b","code_language":"python","doc_language":"en"}'
Enter fullscreen mode Exit fullscreen mode
{
  "success": true,
  "documentation": "# Add Utility\n\n## Overview\nA simple function to add two numbers...",
  "quality_score": 9,
  "target_language": "en"
}
Enter fullscreen mode Exit fullscreen mode

It auto-detects the programming language (Python, JavaScript, Go, Rust…) and spits out a polished doc. The English output is solid, but seeing it generate accurate Japanese or German READMEs from the same code still feels like magic.

The Tech Behind It
Backend: Python + FastAPI, hosted on Northflank.

AI Model: DeepSeek (via API). The model actually understands code structure, so generated docs aren’t just generic wrappers.

Language Detection: Pygments for syntax highlighting + language guessing.

Caching: 24-hour cache to avoid redundant calls and save cost.

Security: Sensitive strings (API keys, passwords) are automatically redacted from the output.

The whole thing is open source:
https://github.com/zhaochangbo888/docgen-api

Why I Didn’t Just Use ChatGPT
You could absolutely paste your code into ChatGPT and ask for docs. But integrating an LLM directly into a CI/CD pipeline, or a VS Code extension, or a platform that needs programmatic access gets messy with rate limits, authentication, and output consistency.

This API gives you a predictable JSON schema, reliable caching, and optional overrides for detail level and format. It’s designed to be called by other tools, not just by humans.

What It Cost Me to Run
DeepSeek’s pricing is absurdly cheap. A 2,000-word README costs less than $0.001. Even with the free tier (50 req/month), I’m not worried about losing money while people test it.

Try It Yourself
There’s a demo endpoint with no subscription required (5 requests/day). Just grab a free RapidAPI key and start playing:

👉 https://rapidapi.com/zhaochangbo0/api/ai-code-documentation-generator

Plans:

Free: 50 requests/month

Basic: $9.99/month for 5,000 requests

Pro: $49/month for 50,000 requests

All plans include all 13 languages and all doc formats (readme, api_doc, inline comments).

What I’d Love Feedback On
I’m actively improving the output quality. If you try it on your own code, let me know:

Does the generated doc actually save you time?

What languages or doc formats are missing?

Does the quality hold up for larger, real-world codebases?

Drop a comment or open an issue on GitHub. I’ll be hanging out in the replies.

Top comments (0)