Generations API – POST /api/generate-code-tests

This endpoint generates a complete test suite for a single source-code file using DocuWriter.ai’s AI engine. It accepts optional hints for test framework and test type, and returns generated tests as a single code snippet.

Authentication

All generation endpoints require a valid API token.

Requests without authentication return HTTP 401 Unauthorized.

Authorization: Bearer <your_sanctum_token>

• Ensure your user has remaining credits.

Request

Endpoint

POST https://app.docuwriter.ai/api/generate-code-tests

Headers

Key Value Required
Authorization Bearer `` Yes
Content-Type application/json Yes
User-Agent Optional; used to detect MCP client No

Body Parameters

Field Type Description
source_code string Required. The raw code to generate tests for.
filename string Required. Filename (with extension) of the source code.
name string Optional custom name for this generation (max 255 chars).
test_framework string Optional hint: e.g. phpunit, jest. Defaults to auto-detect.
test_type string Optional hint: e.g. unit tests, integration tests. Defaults to unit tests.

*** If no⁣ **test_framework** is provided, the generator selects the best framework automatically.**

Response

Success (200 OK)

{
  "success": true,
  "data": {
    "generation": "/* Entire generated test suite as a single code snippet */"
  }
}
  • generation: The full test suite code, ready to run.

Error Responses

Status Code Condition Example Body
422 Unprocessable Entity Validation failed (source_code, filename missing) { "message": "The sourcecode field is required.", "errors": { "sourcecode": [...] } }
403 Forbidden User has no remaining credits { "success": false, "message": "You have no remaining credits. Please upgrade your plan." }
400 Bad Request Code too large for processing (token limit exceeded) { "success": false, "message": "The provided code is too large for processing. Please reduce the amount of code and try again." }
500 Internal Server Error Exception { "success": false, "message": "Error generating tests. Please try again." }or{ "success": false, "message": "No message content found in the API response." }