Best Claude Prompt for “Write API Documentation”
Claude performs best with XML-tagged prompts using <task>, <context>, <requirements>, and <format> blocks. Unlike other models, Claude generalizes well from motivations — explaining WHY you want something, not just WHAT, produces more accurate and nuanced responses. This free template is optimized specifically for Claude, achieving approximately 37% token reduction compared to unoptimized prompts while producing higher quality output.
Optimize Any Prompt Instantly
Stop manually formatting prompts for each AI model. PromptOptimizr auto-restructures your prompts for ChatGPT, Claude, Gemini, Cursor, and Claude Code — with 3 optimization styles.
What Most People Type
Optimized Claude Prompt
<context>
The user has a REST API endpoint and needs comprehensive documentation for it. This documentation will serve as a reference for developers integrating with the API.
</context>
<task>
As a technical writer specializing in API documentation, write clear and concise API documentation for a REST endpoint.
Focus on creating a user-friendly guide that enables developers to understand and utilize the endpoint effectively.
</task>
<requirements>
* **Endpoint Description:**
* Clearly state the HTTP method (e.g., GET, POST, PUT, DELETE).
* Provide the full URL path for the endpoint.
* Offer a brief, 1-2 sentence summary of the endpoint's purpose.
* **Request Details:**
* Describe any required or optional request parameters (query parameters, path parameters, request body).
* For each parameter, specify its data type (string, integer, boolean, object, array), whether it's required, and provide a brief description.
* If a request body is expected (e.g., for POST or PUT), detail its structure, including nested objects and their properties, data types, and required status. Provide 1-2 examples of valid request bodies.
* **Response Details:**
* Document the possible HTTP status codes the endpoint can return (e.g., 200 OK, 201 Created, 400 Bad Request, 404 Not Found, 500 Internal Server Error).
* For each significant status code, describe the structure of the response body.
* Detail the properties within the response body, including their data types and descriptions. Provide 1-2 examples of successful response bodies.
* **Error Handling:**
* Explain how errors are communicated, including the structure of error response bodies if applicable.
* **Code Examples:**
* Include 2-3 practical code examples demonstrating how to call the endpoint using a common programming language or tool (e.g., cURL, Python with `requests`, JavaScript with `fetch`). These examples should be easy to copy and adapt.
* **Clarity and Conciseness:**
* Ensure all explanations are easy to understand, assuming the reader has some familiarity with REST principles but may be new to this specific API. Avoid overly technical jargon where simpler terms suffice.
</requirements>
<format>
Structure the documentation logically using the sections outlined in the requirements. Use markdown for formatting, including code blocks for examples and request/response bodies.
Before finishing, verify your response covers the user's core ask: writing API documentation for a REST endpoint.
</format>Why This Claude Prompt for “Write API Documentation” Works Better
When you type “Write API documentation for my REST endpoint” into Claude, it lacks structure — Claude has to guess what format you want, how detailed to go, and what to prioritize. The optimized version removes that guesswork.
It wraps the request in XML tags (<task>, <requirements>, <format>) that Claude uses to separate context from instructions. It also explains WHY behind each constraint — Claude produces better results when it understands your reasoning.
This Prompt Optimized for Other AI Models
Each AI model processes instructions differently. See how this same prompt is optimized for:
Frequently Asked Questions
What makes a good Claude prompt for write api documentation?
Claude performs best with XML-tagged prompts using <task>, <context>, <requirements>, and <format> blocks. Unlike other models, Claude generalizes well from motivations — explaining WHY you want something, not just WHAT, produces more accurate and nuanced responses.
Can I use this prompt template for free?
Yes — copy the optimized prompt below and paste it directly into Claude. For unlimited prompt optimization across all 5 AI models, try PromptOptimizr free with 10 prompts per month. You can also use the Chrome extension to optimize prompts directly inside Claude.
Why is this prompt different from a generic one?
Each AI model processes instructions differently. Claude has specific formatting preferences — this prompt is structured to work with those preferences, not against them. The result is better output quality with approximately 37% fewer tokens.
More Claude Prompt Templates
Optimize Prompts Without Leaving Claude
The PromptOptimizr Chrome Extension injects directly into Claude's interface. No tab switching — click the optimize button right inside the chat, pick your style, and get a model-specific prompt instantly. Works inside ChatGPT, Claude, and Gemini.
Get the Free Chrome Extension →