Skip to main content

Author a Spec

Create a Spec from a document or an export, edit its draft, check it, test it on sample files, publish it and read rows with evidence, all with an API key or OAuth.

Everything you do in the Spec editor you can do over the API: create a Spec, edit its draft, check it, test it on samples, publish it, compare versions, roll back, share it, draft rules and review ground truth. The API calls the same operations as the editor, so a Spec authored here opens in the editor exactly as you left it, and the other way round.

Access

Reads need the specs:read scope and writes specs:write; testing also needs runs:write, because a test is a run. A credential never reaches further than the person it acts for: each write is allowed exactly when that person may make the same change in the Spec editor of this workspace. In a workspace where Spec changes are managed by Talonic, writes return 403 with reason: insufficient_role. Ask GET /v1/specs/authoring first and an agent knows what it can do before it tries.

GET/v1/specs/authoring

Response fields

can_editbooleanMay create Specs and edit drafts.
can_publishbooleanMay publish and roll back.
can_testbooleanMay test on samples (needs runs:write too).
can_importbooleanMay import a Spec JSON export (workspace Admin).

From a sample file to rows with evidence

  1. Upload a sample file (POST /v1/documents or POST /v1/sources/{id}/documents) and keep its document_id.
  2. Create the Spec with its fields: POST /v1/specs with name and a doc.
  3. Check it: POST /v1/specs/{id}/check. Fix every entry in errors with PUT /v1/specs/{id}/draft.
  4. Test it on the sample: POST /v1/specs/{id}/test with document_ids. Poll links.progress, then read links.results with ?include=provenance.
  5. Publish: POST /v1/specs/{id}/publish. New runs now use this version.
  6. Run it on new documents: POST /v1/run with the published schema_id as spec_id, and read the rows the same way.

Create, check, test and publish

# 1. create the Spec with two fields
curl -X POST https://api.talonic.com/v1/specs \
  -H "Authorization: Bearer $TALONIC_API_KEY" -H "Content-Type: application/json" \
  -d '{"name":"Invoices","doc":{"format":1,"name":"Invoices",
        "fields":[
          {"field_id":"f-vendor","name":"vendor_name","data_type":"string","description":"Legal name of the issuing company"},
          {"field_id":"f-total","name":"total_amount","data_type":"number","description":"Invoice total including tax"}],
        "stages":[{"id":"s-source","type":"source"},{"id":"s-extract","type":"extraction","config":{}},{"id":"s-deliver","type":"deliver"}],
        "gates":[],"policies":[]}}'

# 2. check the draft
curl -X POST https://api.talonic.com/v1/specs/$SPEC_ID/check \
  -H "Authorization: Bearer $TALONIC_API_KEY"

# 3. test it on the uploaded sample
curl -X POST https://api.talonic.com/v1/specs/$SPEC_ID/test \
  -H "Authorization: Bearer $TALONIC_API_KEY" -H "Content-Type: application/json" \
  -d '{"document_ids":["'$DOCUMENT_ID'"]}'

# 4. rows with evidence, once the test run completes
curl "https://api.talonic.com/v1/pipelines/$PIPELINE_ID/results?include=provenance" \
  -H "Authorization: Bearer $TALONIC_API_KEY"

# 5. publish
curl -X POST https://api.talonic.com/v1/specs/$SPEC_ID/publish \
  -H "Authorization: Bearer $TALONIC_API_KEY" -H "Content-Type: application/json" \
  -d '{"expected_draft_revision": 1}'
Easiest way to get a valid document: build one Spec in the editor, read it with GET /v1/specs/{id}/draft, and use its doc as your template.

Create, import and rename

POST/v1/specs

Body

name*stringUp to 300 characters.
descriptionstringOptional.
docobjectA complete Spec document (format: 1). Omit for an empty draft.
POST/v1/specs/import

Body

spec_jsonobjectThe file the Spec editor exports. Needs the workspace Admin role.
schema_idstringAn existing schema to turn into a Spec.
overwrite_allbooleanOverwrite every reference table in the export that already exists.
overwritestring[]Reference tables (id or name) that may be overwritten.
PATCH/v1/specs/{id}

Errors

Error responses

400validation_errorThe body or the document is invalid.
403insufficient_scopeThe credential lacks specs:write (or runs:write for a test).
403insufficient_roleThe person this credential acts for may not make this change in the Spec editor of this workspace.
404not_foundNo Spec, schema or document with this ID that you can see.
409conflictThe draft changed since you read it.
422unprocessableThe draft has errors, or there are issues to acknowledge.

Frequently asked questions

Can an API key change a Spec my Admin could not change in the editor?+
No. Every write is allowed exactly when the person behind the credential may make the same change in the Spec editor of this workspace. Scopes only narrow that further.
Is a Spec live as soon as I create it?+
No. Runs use the published version. Create and edit freely, test on samples, then publish.
Where do I get a valid Spec document?+
Read any Spec with GET /v1/specs/{id}/draft and reuse its doc, or import a Spec JSON export the editor produced.