Introducing a new way to review your PRs.

Read the announcement

zipstack / unstract

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

View on GitHub

28 documents · Updated Nov 23, 2026

docs / backend-api-platform

Backend API platform

The Backend API platform is the Django service boundary for tenant data, workflow configuration, published deployments, and asynchronous extraction. It serves browser users, automation clients, trusted workers, and monitoring systems while keeping identity, organization scope, and authority separate.

Platform boundary

The platform separates public, tenant, deployment, extraction, monitoring, and internal traffic. Each surface exposes only the actions and trust level needed by its caller.

Request surfaces

Tenant routes serve organization resources. Public routes serve sign-in and other open functions. Deployment routes run published workflows. Agent-KV routes accept document extraction work. The root metrics route serves monitoring systems. Internal routes support trusted workers and service calls.

The following diagram shows how callers reach shared domain services through the Django boundary.

flowchart TD
    Client[Browser or API client] --> Gateway[Django URL boundary]
    Gateway --> Tenant[Tenant API]
    Gateway --> Deploy[Published deployment API]
    Gateway --> AgentKV[Agent-KV extraction API]
    Monitor[Prometheus or autoscaler] --> Metrics[Root metrics API]
    Worker[Worker or internal service] --> Internal[Internal API]
    Tenant --> Domain[Shared domain services]
    Deploy --> Domain
    AgentKV --> Domain
    Metrics --> Domain
    Internal --> Domain

References: backend/…/base_urls.py• L11-46 backend/…/base.py• L160-181 backend/…/base.py• L647-715

Domain API groups

Tenant routes group product capabilities around the organization and its resources. They cover accounts, connectors, files, tools, workflows, pipelines, Prompt Studio, notifications, usage, audit events, search, metrics, Agent-KV key management, and the user inbox.

The Versioned backend APIs and domain modules page gives the detailed view of these groups. This page treats them as one platform because they share the tenant boundary and request context.

References: backend/…/base_urls.py• L23-30 backend/…/urls_v2.py• L24-72

Account and session API

The account API manages sign-in, sign-out, organization discovery, organization selection, organization creation, and the current session view. The session response gives the client the active organization and user authority needed to enter tenant routes.

Signed-in users can list live browser sessions, end one session, or end every session. Service accounts and platform API keys do not use this browser-session surface. The Versioned backend APIs and domain modules page covers the wider account API.

References: backend/…/ReadMe.md• L28-81 backend/…/views.py• L37-91 backend/…/session_views.py• L36-123

Inbox API

The inbox API gives an authenticated user a view of organization-scoped notices. It returns newest-first pages, an unread total, and optional route data that can lead the client to the related resource.

Users can mark one notice as read or clear all unread notices. A stale single-item read stays unread and returns the current item, so a client does not dismiss a notice that changed after it was listed. The Inbox domain page explains how notices are created and refreshed.

References: backend/…/urls.py• L5-9 backend/…/views.py• L22-102 backend/…/serializers.py• L7-65

Deployment API

The deployment API turns a configured workflow deployment into an external execution surface. A caller supplies a deployment key and documents. The backend starts the work and returns either an immediate result or a status to poll.

The surface supports uploaded files and presigned document URLs. It applies organization limits, validates the deployment and its workflow, and can route results to review queues. The Backend workflow management page explains the resources behind this flow. The Model Context Protocol integration page explains the separate MCP tool boundary.

References: backend/…/api_deployment_views.py• L82-449 backend/…/serializers.py• L45-207 backend/…/destination.py• L883-1068

Published deployment contract

The published deployment contract defines listing, execution, status reads, authentication, request forms, result shapes, and client-actionable errors. Queued work is a normal polling state. Terminal failures and stopped runs use a distinct error response with the terminal state.

The committed OpenAPI document is a client contract. It is generated from the routes that the server exposes, so route or serializer changes must keep that contract aligned.

References: backend/…/README.md• L176-186 backend/…/deployment_spec_urls.py• L1-43 backend/…/openapi_schema.py• L43-157

Platform identity discovery

The whoami endpoint resolves an organization and permission tier from a platform API key. It has no organization segment because the key supplies the organization identity. Clients can call it before they use organization-scoped routes.

Deployment keys are not accepted as platform keys. An organization-qualified alias can apply an additional key-to-organization check.

References: backend/…/whoami_urls.py• L1-15 backend/…/whoami_views.py• L32-85

Agent-KV extraction API

Agent-KV is the key-based API for document extraction. An organization administrator manages extraction keys. A key holder submits a supported document, tracks asynchronous work, reads a terminal result, cancels a job, deletes stored job data, or receives a webhook.

The submit path checks file content, extractor choice, schema, extractor options, adapter roles, page limits, timeout, webhook target, subscription, and rate limits before paid work starts. The API supports table and an optionally enabled kv extractor through one request shape. One request selects one extractor. The caller's organization-owned adapters are recorded by ID for status and cost context.

Job state is guarded so only one terminal outcome wins. A late result can be retained for a cancelled or failed job when the work was already paid for. A separate purge marker prevents a late callback from making deleted data readable again. The Agent key-value extraction page describes this flow in detail.

References: backend/…/execution_serializers.py• L42-68 backend/…/execution_serializers.py• L465-589 backend/…/execution_serializers.py• L592-801 backend/…/execution_views.py• L531-630 backend/…/execution_views.py• L686-921 backend/…/models.py• L81-186 backend/…/0008_agentkvjob_files_purged.py• L1-23

Global search API

Global search gives an authenticated tenant user one search surface for resources that user can open. It returns grouped results with stable type keys, display labels, match context, and route data for the client.

Each provider applies the same visibility rule as its resource list. The search surface can return partial results when one resource type fails, but it does not turn a complete provider failure into a false empty result. The detailed search contract is in backend/…/README.md.

References: backend/…/README.md• L13-31 backend/…/README.md• L59-183 backend/…/oss_providers.py• L73-268

Connection status API

Connection status gives adapters and connectors one way to test saved settings and show the latest result in list and detail views. A profile is connected, failed, or never_tested.

The test uses the same saved credentials as real work. The API stores only the newest test result and keeps failure text bounded. The shared contract is described in backend/…/README.md and summarized in Versioned backend APIs and domain modules.

References: backend/…/README.md• L20-115 backend/…/services.py• L23-111 backend/…/pagination.py• L13-45

Platform metrics endpoint

The platform metrics endpoint exposes platform-wide monitoring data at root-level GET /metrics in Prometheus text format. It sits outside the user API prefixes so monitors can read it from the backend service.

The endpoint can use an optional bearer token and repeated group selection. Metric groups use bounded snapshots shared through Redis. A failed group does not remove healthy groups, and data older than its freshness limit is not presented as current. The Platform metrics page explains the monitoring contract.

References: backend/…/urls.py• L1-5 backend/…/views.py• L1-62 backend/…/exporter.py• L49-116 backend/…/cache.py• L1-29

Domain services

Domain services connect API actions to organization data and workflow resources. They keep cross-resource rules in one place so a browser user and an automation client receive the same product behavior.

Organization context

An organization is the main tenant boundary. Middleware reads it from the URL when present. Query and model access rules then limit visible data to that organization.

Requests without a usable organization context fail closed at the API boundary. Work that spans organizations uses an explicit cross-organization path. Internal workers receive an explicit organization context instead of relying on a missing request URL segment.

References: backend/…/organization_middleware.py• L7-32 backend/…/organization_filter.py• L17-90 backend/…/org_aware_manager.py• L14-116 backend/…/internal_views.py• L17-40

Platform API keys

Platform API keys provide bearer access for automation. Each key belongs to one organization and resolves to a service account. The normal organization and resource rules apply after that identity is established.

Keys have method permission tiers:

PermissionRequest authority
readRead methods
read_writeRead, create, and update methods
full_accessAll supported methods, including delete

The platform checks key format, active state, expiry, service-account link, organization match, and method permission before a view runs. Accepted use feeds usage reporting. The API-key usage page covers that reporting path.

References: backend/…/custom_auth_middleware.py• L40-53 backend/…/custom_auth_middleware.py• L80-230 backend/…/whoami_views.py• L51-85

Agent-KV key authority

Agent-KV keys are separate from platform API keys. An organization administrator creates, lists, updates, rotates, and deletes them. The extraction API resolves the organization from the bearer key because its URL has no organization segment.

Every job lookup, adapter check, storage path, and limit uses the key's organization. Unknown jobs and jobs owned by another organization have the same public not-found response.

References: backend/…/views.py• L18-85 backend/…/key_validator.py• L11-45 backend/…/execution_views.py• L32-45

Workflow domain services

Workflow management owns the resources that describe how work should run. Tenant APIs configure workflows, endpoints, and deployments. Internal APIs carry execution context and state changes between Django and workers.

Pipelines add scheduling and execution on top of workflow definitions. Shared users can use shared resources, while owners control configuration and ownership. The Backend workflow management page explains these lifecycles.

References: backend/…/views.py• L49-181 backend/…/internal_views.py• L45-107 backend/…/views.py• L74-339

Adapter services

Adapter services represent external language models, embeddings, vector stores, and text extraction systems. They expose supported choices, store protected settings, test connections, manage sharing, and prevent retired or unusable choices from entering new work.

Existing retired adapter records remain visible for migration. New use and execution are blocked. Deletion is blocked while workflow tools still refer to an adapter.

References: backend/…/adapter_processor.py• L46-207 backend/…/serializers.py• L43-168 backend/…/views.py• L188-455

Connector services

Connector services connect workflows to external file, database, and application systems. They own connector credentials and OAuth hand-offs while exposing resource access to users who can use a workflow.

Connector profiles share the connection-status contract with adapters. OAuth data is retained only when the create or update flow succeeds, and responses do not expose authentication data.

References: backend/…/serializers.py• L35-182 backend/…/views.py• L72-317 backend/…/README.md• L20-64

Prompt Studio services

Prompt Studio turns projects, prompts, documents, profiles, and adapters into extraction and answer work. Short actions use the API request. Long actions move to workers and return a task state that the client can read later.

The service checks parent and child ownership together. Worker callbacks use a protected internal boundary and must preserve organization scope. The Versioned backend APIs and domain modules page places Prompt Studio beside the other tenant APIs.

References: backend/…/views.py• L128-232 backend/…/views.py• L431-923 backend/…/internal_views.py• L119-433

File management services

File management gives tenant clients a common way to upload, list, and download files through configured storage. It validates the resource relationship and delegates storage work to the connector file system.

API deployment uploads are checked from their bytes before they enter API storage. Unsupported files become per-file failures that remain visible in the execution result and file history. Valid sibling files can continue through the same request.

References: backend/…/views.py• L28-94 backend/…/serializer.py• L7-54 backend/…/source.py• L1206-1251 backend/…/source.py• L1254-1341 backend/…/source.py• L1343-1459

Authorization boundaries

Authorization is layered. A request first needs a valid identity and organization context. Resource rules then decide whether that identity may read, use, or change the target.

Authentication modes

The backend accepts browser sessions and bearer credentials. Sessions represent human users. Platform keys represent automation service accounts. Deployment keys run one published deployment. Agent-KV keys authorize extraction jobs. Internal keys authorize trusted worker calls.

The whoami path is organization-less because the key supplies the organization. The metrics path has its own optional token. Browser session management accepts only a live user session and not a platform key.

References: backend/…/custom_auth_middleware.py• L56-230 backend/…/whoami_views.py• L32-73 backend/…/key_validator.py• L19-45 backend/…/base.py• L1147-1173

Organization and resource access

Organization membership combines with resource access. Administrators have broad access inside their organization. Owners can change their resources. Shared users and groups can receive read or use access without receiving mutation rights.

Sharing never replaces organization scope. Resource-specific rules still apply: a shared user may use a pipeline, while workflow configuration, connector changes, adapter changes, and project deletion remain restricted actions.

References: backend/…/membership_views.py• L20-141 backend/…/resource_share_views.py• L142-297 backend/…/views.py• L70-85 backend/…/views.py• L89-100

Input and output safeguards

Shared validation protects common risks. Writable text fields reject unsafe markup unless the field is meant to preserve content. UUIDs are parsed before database filters. Webhook targets are checked when saved and again before network delivery.

Paid extraction checks input, schema, adapter, page, timeout, webhook, subscription, and rate limits before staging. Worker callbacks also validate identifiers, payload shape, organization scope, and request size before they update domain data.

References: backend/…/sanitization.py• L1-60 backend/…/serializers.py• L43-70 backend/…/internal_views.py• L119-273 backend/…/execution_serializers.py• L592-801

Platform capabilities

The platform provides shared support for discovery, audit, notifications, asynchronous work, metrics, and live events. These capabilities use different boundaries because their callers have different trust levels.

Public access and discovery

Public routes provide login, callbacks, organization entry points, OAuth, documentation, public pipeline access, feature flags, and health checks. The deployment surface provides published execution and deployment-scoped MCP tools.

The committed OpenAPI document describes the client contract. It is not a separate runtime API. The Model Context Protocol integration page describes how MCP adds tool access without changing the core tenant API.

References: backend/…/base_urls.py• L23-45 backend/…/README.md• L176-186 backend/…/deployment_spec_urls.py• L19-31

Platform audit events

Platform audit events let a tenant record and review important administrative activity. The service applies a default readable retention period and allows an organization setting to override it. Reads hide old events, and the purge process removes them.

The Platform audit events page explains the event contract and lifecycle.

References: backend/…/urls_v2.py• L33-36 backend/…/base.py• L547-553

Notification and webhook services

Notification services send execution events from pipelines, deployments, and Agent-KV jobs to configured webhooks. Internal routes provide workers with organization-scoped settings, tests, delivery state, and delivery metrics.

Unsafe targets are rejected before a request is sent. Terminal delivery follows the job or deployment state that won the guarded update.

References: backend/…/internal_views.py• L34-68 backend/…/internal_views.py• L137-324 backend/…/dispatch.py• L23-130

Dashboard metrics

Dashboard metrics turn execution, document, page, language-model, API, and review activity into organization-level product views. Stored summaries support fast reads, while live paths provide current source data when needed.

Aggregation is global by design. Scheduled work iterates organizations explicitly instead of inheriting a request organization. The Platform metrics page covers the separate root Prometheus endpoint.

References: backend/…/README.md• L1-24 backend/…/internal_views.py• L1-158 backend/…/tasks.py• L568-641

Queue-backed execution support

The backend sends long work to workers instead of holding the request open. Deployments, workflows, Prompt Studio operations, notifications, and Agent-KV extraction use this pattern.

The API creates or updates durable state, dispatches work, and returns an accepted response when the work continues outside the request. Worker callbacks and later status reads return progress and terminal results to the client. The Resource usage page covers usage tracking around these operations.

References: backend/…/views.py• L384-460 backend/…/internal_views.py• L119-433 backend/…/dispatch.py• L164-311 backend/…/celery_broker.py• L19-40

Broker and realtime event delivery

Redis and Socket.IO carry execution logs and live results to connected browsers. Session-bound rooms keep live events tied to the user session. Shared event management lets one backend process deliver an event to a browser connected through another process.

Session revocation removes shared socket access after the database change commits. Redis reconnect behavior keeps live delivery available after a temporary cache connection failure.

References: backend/…/log_events.py• L47-117 backend/…/log_events.py• L162-272 backend/…/base.py• L817-1095

Schedule ownership

Scheduled work has one active scheduler owner at a time. The platform can use the PostgreSQL scheduler or the legacy Beat path, but the selected scheduler and its worker capacity must agree.

References: backend/…/README.md• L54-61 backend/…/README.md• L486-600

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep URL mounts, organization middleware, model access, and hand-written lookups aligned. A new resource must remain scoped in every access path.
  • Keep organization-less routes narrowly anchored. A prefix added to the authentication bypass list can remove protection from a larger surface.
  • Keep platform, deployment, internal, and Agent-KV credentials separate. Do not use one key type as another boundary's authority.
  • Keep Agent-KV extractor routes, deployment gates, stage names, result keys, adapter roles, and executor consumers aligned.
  • Keep Agent-KV validation before staging, slot acquisition, dispatch, and billing. Keep the public path and the backend sample setting aligned.
  • Keep Agent-KV terminal guards, cancellation, late-result handling, purge state, webhook ownership, slot release, and retention cleanup aligned.
  • Keep result salvage additive. A failed job must remain failed, and a purged job must never become readable through a late callback.
  • Keep upload MIME checks aligned with the downstream extractor allow-list. Rejected files must remain visible as file-level failures without discarding valid siblings.
  • Keep adapter ownership and type checks tied to the key's organization when the route has no request-local tenant context.
  • Keep OpenAPI route selection aligned with mounted deployment routes.
  • Keep audit retention settings, read filtering, and purge behavior aligned.
  • Keep metric group names, freshness limits, cache keys, failure isolation, and Prometheus access rules aligned.
  • Keep scheduler ownership aligned with the active scheduler and the workers that consume its transport.

Important failure modes

TriggerConsequenceGuard
An Agent-KV prefix is empty or overlaps a wider API prefixAuthentication can be skipped for unrelated routesReject unsafe prefixes during settings load
A routed extractor has no enabled worker gateA request can be accepted into a queue that no worker drainsRequire an explicit deployment gate before submit
A caller names an adapter from another organization or with the wrong typeThe job can fail after staging or reveal adapter existenceCheck organization and role type before paid work
A late callback arrives after a job is cancelled or purgedPaid output can be lost or deleted data can become readableUse guarded result attachment and the explicit purge marker
A cancel releases a slot for an already-dispatched jobMore paid jobs can run than the organization limit allowsRe-read durable dispatch or stage evidence before releasing
A deployment upload trusts the declared content typeUnsupported or renamed files reach extraction and fail lateDetect MIME from file bytes before storage
A Redis or cache setting differs between backend and workersQueues, limits, or live results appear missingBuild shared transports from one endpoint and database contract
A metric group fails during a scrapeHealthy monitoring data disappears or the scrape stallsBound groups, isolate failures, and serve only safe snapshots

Key files

FileWhy to read it
backend/…/base_urls.pyShows the top-level split between tenant, public, deployment, Agent-KV, metrics, health, and internal traffic.
backend/…/urls_v2.pyShows the tenant API groups and major platform mounts.
backend/…/base.pyDefines path prefixes, authentication exceptions, Agent-KV limits, MCP gates, audit retention, metrics settings, and shared transport settings.
backend/…/custom_auth_middleware.pyShows session, platform-key, deployment-key, and internal authentication boundaries.
backend/…/organization_filter.pyDefines request-level organization filtering and fail-closed behavior.
backend/…/api_deployment_views.pyShows published deployment execution and status behavior.
backend/…/openapi_schema.pyDefines the published deployment client contract.
backend/…/execution_serializers.pyDefines Agent-KV admission rules and extractor-specific request contracts.
backend/…/execution_views.pyShows Agent-KV submission, status, cancellation, result reads, and purge behavior.
backend/…/models.pyDefines Agent-KV job state, terminal guards, adapter records, and purge state.
backend/…/source.pyShows API upload validation and per-file rejection behavior.
backend/…/README.mdPublishes the shared connection-test contract.
backend/…/internal_views.pyShows the worker-to-Django callback boundary.
backend/…/views.pyDefines metrics access and response behavior.
backend/…/exporter.pyShows metric group isolation, snapshots, freshness, and failure handling.
backend/…/internal_views.pyShows organization-filtered webhook configuration and delivery support.
backend/…/tasks.pyDefines global metric aggregation behavior.
backend/…/log_events.pyShows session-bound realtime event delivery.