Generations API: POST /api/generate-code-documentation
This endpoint generates AI-powered documentation for a single source code file.
Authentication 🔒
All /api/* routes require a valid API token. Include this header in every request:
- Authorization:
Bearer
Headers
- Content-Type:
application/json - Authorization:
Bearer(required) - User-Agent: determines the generation source (
APIvsMCP)
Request Payload 📦
Provide a JSON body with the following fields:
| Field | Type | Required? | Description |
|---|---|---|---|
source_code |
string | yes | Raw contents of the file to document. |
filename |
string | yes | Name of the source file (with extension). |
name |
string | no | Custom title for this generation (max 255 chars). |
output_language |
string | no | Language for the documentation (default “English”). |
documentation_type |
string | no | One of the configured doc types (e.g., “API Documentation”, “General Documentation”). |
additional_instructions |
string | no | Free-form instructions to guide the AI beyond defaults. |
Example Request Body
{
"source_code": "<?php\nclass Calculator {\n public function add($a, $b) { return $a + $b; }\n}",
"filename": "Calculator.php",
"name": "Calculator Docs",
"output_language": "English",
"documentation_type": "API Documentation",
"additional_instructions": "Focus on input validation details."
}
API Definition 🔧
{
"title": "Generate Code Documentation",
"description": "Produces markdown documentation for a single source code file via AI",
"method": "POST",
"baseUrl": "https://app.docuwriter.ai",
"endpoint": "/api/generate-code-documentation",
"headers": [
{
"key": "Authorization",
"value": "Bearer <token>",
"required": true
},
{
"key": "User-Agent",
"value": "@docuwriter/mcp-client | Any",
"required": false
}
],
"queryParams": [],
"pathParams": [],
"bodyType": "json",
"requestBody": "{\n \"source_code\": \"...\",\n \"filename\": \"...\",\n \"name\": \"...\",\n \"output_language\": \"...\",\n \"documentation_type\": \"...\",\n \"additional_instructions\": \"...\"\n}",
"formData": [],
"rawBody": "",
"responses": {
"200": {
"description": "Documentation generated successfully",
"body": "{\n \"success\": true,\n \"data\": {\n \"generation\": \"# Calculator\\n...\",\n \"generation_id\": 42\n }\n}"
},
"400": {
"description": "Payload too large or invalid processing",
"body": "{\n \"success\": false,\n \"message\": \"The provided code is too large for processing...\"\n}"
},
"403": {
"description": "No remaining credits or unauthorized role",
"body": "{\n \"success\": false,\n \"message\": \"You have no remaining credits...\"\n}"
},
"422": {
"description": "Validation error",
"body": "{\n \"message\": \"The given data was invalid.\",\n \"errors\": {\n \"source_code\": [\"The source_code field is required.\"],\n \"filename\": [\"The filename field is required.\"]\n }\n}"
},
"500": {
"description": "Internal server error or AI service failure",
"body": "{\n \"success\": false,\n \"message\": \"There was an error generating the documentation. Please try again.\"\n}"
}
}
}
Updated