Code · best for

Top picks for Code Documentation (2026)

Writing clear docstrings and READMEs that match the code. Ranked from 405 live models on the OpenRouter catalog, weighted for context window, low cost, reasoning quality.

What this is Ranked by capability match + real benchmark scores (Aider Polyglot, Artificial Analysis Intelligence Index) + live pricing. Models need the right specs for Code Documentation, then benchmark performance refines the order. Full methodology →
#ModelScoreIn / 1MOut / 1MContext
1 Anthropic: Claude Opus 4.7 (batch)anthropic/claude-opus-4.7:batch 152 $2.50 $12.50 1,000,000 Details →
2 Anthropic: Claude Sonnet 4.6 (batch)anthropic/claude-sonnet-4.6:batch 151 $1.50 $7.50 1,000,000 Details →
3 Anthropic: Claude Sonnet 4.6anthropic/claude-sonnet-4.6 149 $3.00 $15.00 1,000,000 Details →
4 OpenAI: GPT-5.4 (batch)openai/gpt-5.4:batch 148 $1.25 $7.50 1,050,000 Details →
5 Anthropic: Claude Opus 4.8 (batch)anthropic/claude-opus-4.8:batch 148 $2.50 $12.50 1,000,000 Details →
6 Z.ai: GLM 5.2 (batch)z-ai/glm-5.2:batch 148 $0.70 $2.20 512,000 Details →
7 DeepSeek: DeepSeek V4 Prodeepseek/deepseek-v4-pro 148 $1.17 $2.34 1,048,576 Details →
8 OpenAI: GPT-5.5 (batch)openai/gpt-5.5:batch 147 $2.50 $15.00 1,050,000 Details →
9 Z.ai: GLM 5.2z-ai/glm-5.2 147 $0.50 $3.15 1,048,576 Details →
10 OpenAI: GPT-5.4openai/gpt-5.4 147 $2.50 $15.00 1,050,000 Details →
11 Google: Gemini 3.1 Pro Preview (batch)google/gemini-3.1-pro-preview:batch 146 $1.00 $6.00 1,048,576 Details →
12 Google: Gemini 3.1 Pro Previewgoogle/gemini-3.1-pro-preview 145 $2.00 $12.00 1,048,576 Details →
13 Anthropic: Claude Opus 4.7anthropic/claude-opus-4.7 144 $5.00 $25.00 1,000,000 Details →
14 SpaceXAI: Grok 4.6x-ai/grok-4.6 144 $2.00 $6.00 500,000 Details →
15 OpenAI: GPT-5 (batch)openai/gpt-5:batch 144 $0.62 $5.00 400,000 Details →

How we ranked these

For Code Documentation, we weight models on context window, low cost, reasoning quality. Scores combine each model's public specs with independent benchmark results (Aider Polyglot coding scores, Artificial Analysis intelligence/coding/agentic indices) and live pricing. See full methodology →

About Code Documentation

yourself.

When to use: Use this when you have working code without documentation, or when you need to update docs to match a recent code change without manually writing every

Common questions

What is the difference between AI documentation and human-written docs?

AI-generated documentation excels at speed and consistency for straightforward functions, but often misses domain context, usage warnings, and examples that experienced developers would include. Models like Claude 3.5 Sonnet handle complex parameter relationships better than older models, but you should always review critical paths and add use-case examples manually.

How much slower is it to use a better model for documentation versus a faster one?

GPT-4 or Claude 3.5 Sonnet are typically 2-4x slower per file than GPT-3.5, but produce fewer errors that require rewrites. For a 500-file codebase, the slower model still finishes in hours rather than minutes, and the time savings from not fixing bad docs usually outweigh the generation delay.

Related tasks