Skip to content

API Reference

Docentric Copilot edited this page Nov 6, 2026 · 2 revisions

API Reference

REST API v1 · OpenAPI 3.1 · base URL http://localhost:8000

The interactive contract is served at /docs and the machine-readable document at /openapi.json. A snapshot is committed as docs/openapi.json.

Endpoint overview

Method Endpoint Purpose
POST /api/v1/sources Upload a DDSP package (multipart)
GET /api/v1/sources/{id}/schema Normalized schema for a source
POST /api/v1/templates/plan Brief → validated Template IR
POST /api/v1/templates/validate Validate an IR (V1–V5)
POST /api/v1/templates/compile IR → DOCX artifact
POST /api/v1/templates/revise New IR version from an instruction
POST /api/v1/templates/preview HTML preview
POST /api/v1/reference/inspect Read-only reference template inspection (multipart file or confined corpus path)
POST /api/v1/reference/graph Read-only ReferenceGraph and optional reference projection
POST /api/v1/reference/d365 Embedded D365 schema extraction and canonical binding resolution
POST /api/v1/reference/diff ReferenceDiff v1.0 from two uploads or two confined corpus paths
POST /api/v1/reference/import-ir Safe Reference → Generic Template IR subset with skipped[]
POST /api/v1/reference/reports Persist an inspection (+graph), graph or diff envelope
GET /api/v1/reference/reports/{id} Reopen a persisted reference report by id
GET /api/v1/reference/reports/{id}/export Export the report as JSON or safe HTML
GET /api/v1/templates/{id}/versions Version history
GET /api/v1/templates/{id}/export/{version} Export a version's IR and reports
GET /api/v1/jobs/{id} Job record
GET /api/v1/artifacts/{id} Download an artifact
GET /api/v1/artifacts/{id}/view Inline view for HTML artifacts
GET /api/v1/providers Provider catalogue and configuration state
GET /api/v1/capabilities Compilers, features and limits
GET /api/v1/health Service health

Reference inspection accepts a multipart file (.docx, .zip, .axpp) with an optional ddsp, or ?path= inside DC_REFERENCE_CORPUS_ROOTS. The diff endpoint accepts multipart left/right files (optional shared ddsp) or left_path/right_path query parameters. The D365 endpoint returns template_id, platform, schema_source (projectdata|ddsp|unavailable), schema_evidence, binding_results and runtime_compatibility: "not_tested"; each binding status is one of resolved, ambiguous, unknown_path, type_mismatch, schema_unavailable, unsupported_expression. All reference endpoints are read-only, default to no nested archive recursion over HTTP, and never claim runtime compatibility.

POST /api/v1/reference/import-ir returns ir, skipped[], provenance[], validation, summary and runtime_compatibility: "not_tested"; strict mode returns HTTP 422 with reference_import_blocked when anything is unsupported, while ?allow_unsupported=true keeps the supported subset. POST /api/v1/reference/reports?kind=inspection|graph|diff runs server-side and persists the envelope under the artifact TTL; GET /reports/{id} reopens it and GET /reports/{id}/export?format=json|html downloads JSON or a safe, escaped HTML export. A missing or expired id is HTTP 404 with reference_report_not_found. See Reference Templates and Safe IR import and visual diff.

Error envelope

Every expected failure uses one shape:

{
  "error": {
    "code": "validation_failed",
    "message": "The template failed validation",
    "details": { "validation": { "semantic": "failed" } }
  }
}
HTTP Code Meaning
400 input_invalid, security_violation, XML001 Malformed or hostile input
404 not_found Unknown source, template or job
409 target_unsupported Gated Docentric AX target
410 artifact_unavailable Artifact expired or missing
415 input_unsupported Wrong file type
422 validation_failed Validation rejected the plan
502/503 provider_error, provider_not_configured LLM provider problems

Typical flow

1. Upload

curl -s -F "file=@examples/quotation/sales-quotation.ddsp" \
  http://localhost:8000/api/v1/sources
{
  "source_id": "src_1mxsqvj9cxf4lm3qoav2",
  "schema_id": "sales_quotation",
  "sections": ["MainData", "GeneralData", "Parameters"],
  "stats": { "node_count": 34, "scalar_count": 28, "collection_count": 1, "max_depth": 3 },
  "sample_data_available": true,
  "diagnostics": [{ "code": "INFO002", "severity": "info", "message": "ZIP container with 3 entries" }]
}

2. Plan

curl -s -X POST http://localhost:8000/api/v1/templates/plan \
  -H "Content-Type: application/json" \
  -d '{"source_id":"src_…","prompt":"Create a professional sales quotation","provider":"mock"}'

Response highlights:

{
  "job_id": "job_…",
  "template_id": "tpl_…",
  "version": 1,
  "ir_digest": "9f8d8ad1…",
  "validation": {
    "structural": "passed", "semantic": "passed", "logical": "passed",
    "visual": "passed", "docentric_compatibility": "not_tested"
  },
  "artifacts": [{ "kind": "ir", "url": "/api/v1/artifacts/art_…" }]
}

templates/plan writes a version, publishes artifacts and records a job. It is synchronous; the job record exists for auditability.

3. Compile

curl -s -X POST http://localhost:8000/api/v1/templates/compile \
  -H "Content-Type: application/json" \
  -d '{"source_id":"src_…","template_id":"tpl_…","options":{"document_name":"quotation.docx"}}'

Then GET /api/v1/artifacts/{artifact_id} returns the DOCX with Content-Disposition: attachment, X-Content-Type-Options: nosniff and X-Artifact-Digest (SHA-256 of the served bytes).

4. Revise

curl -s -X POST http://localhost:8000/api/v1/templates/revise \
  -H "Content-Type: application/json" \
  -d '{"source_id":"src_…","template_id":"tpl_…","instruction":"Move bank details to the footer."}'

Returns version: 2, a structural change_summary and the new artifact bundle. The previous version stays exportable.

Request options worth knowing

Field Default Effect
provider mock mock, openai, anthropic, gemini
model provider default Model identifier
design_style modern modern, classic, minimal
target generic-docx docentric-ax is gated and returns 409
options.strict_validation true Reject plans that fail V1–V3
options.max_generation_cost_usd 0.50 Pre-flight budget ceiling
options.max_repair_attempts 1 Automatic repair attempts on invalid output

Artifact lifecycle

Property Value
TTL DC_ARTIFACT_TTL_SECONDS (3600 by default)
Storage Local file store, metadata in SQLite
Download attachment disposition, digest header
Inline view HTML only (/view), otherwise 415
Cleanup Expired artifacts removed on startup and on access

Rate limits and size limits

Limit Default Variable
Upload size 10 MB DC_MAX_DDSP_BYTES
Uncompressed content 64 MB DC_MAX_UNCOMPRESSED_BYTES
ZIP entries 512 DC_MAX_ZIP_ENTRIES
Schema nodes 5,000 DC_MAX_SCHEMA_NODES
IR blocks 5,000 DC_MAX_IR_BLOCKS

No application-level rate limiting is implemented in the MVP; put the API behind your gateway if it is exposed beyond localhost.

Clone this wiki locally