openapi: 3.1.0
info:
  title: Manifolds API
  version: 0.1.0
  description: |
    v0 API for Manifolds enrichments.

    This version exposes endpoints to submit single-contact and batch
    enrichment requests, and to check their processing status. Requests are
    processed asynchronously; submission endpoints return a 202 Accepted
    response with a receipt. Enrichment results are delivered to the
    destinations you configure (webhook or Slack), never in API responses.

servers:
  - url: https://api.manifolds.run
    description: Production

paths:
  /v0/enrichments:
    post:
      operationId: submitEnrichmentRequest
      summary: Submit an enrichment request
      description: >
        Submit identifiers to be enriched.

        **In v0, `email` is required and is the only field used by the enrichment
        pipeline.**
        The `github_username` field is accepted for forward-compatibility but is
        not yet used to look up or compute enrichment data.
        Optionally supply `external_user_id` to correlate the result with a user
        in your system.

        The request is processed asynchronously. On success, the API returns
        `202 Accepted` with a submission receipt. Requests can be made
        idempotent via the `Idempotency-Key` header.

        The receipt never contains enrichment data. Matched results are pushed
        to the destinations you configure (webhook or Slack). To check whether
        a submission is still queued, processing, finished, or was denied, use
        `status_url` (`GET /v0/enrichments/submissions/{submissionId}`).
      security:
        - bearerAuth: []
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          description: >
            Optional idempotency key used to make this request idempotent for
            the authenticated account. If a matching request has already been processed,
            the existing submission ID is returned and `idempotency_replayed`
            is set to true.
          schema:
            type: string
      requestBody:
        description: >
          JSON object containing an email address to enrich.

          In v0, `email` is required. The `github_username` field is accepted
          for forward-compatibility, but is currently ignored.
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/EnrichmentRequest"
            examples:
              withEmail:
                summary: Submit with email only
                value:
                  email: "foo@bar.com"
              withGithub:
                summary: Submit with email and GitHub username
                value:
                  email: "foo@bar.com"
                  github_username: "octocat"
      responses:
        "202":
          description: Enrichment request accepted
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SubmissionAccepted"
              examples:
                default:
                  value:
                    status: "accepted"
                    submission_id: "subm_11111111-1111-1111-1111-111111111111"
                    status_url: "/v0/enrichments/submissions/subm_11111111-1111-1111-1111-111111111111"
                    received_at: "2025-10-17T00:12:34Z"
                    idempotency_replayed: false
                    processing_status: "queued"
                withWarning:
                  value:
                    status: "accepted"
                    submission_id: "subm_11111111-1111-1111-1111-111111111111"
                    received_at: "2025-10-17T00:12:34Z"
                    idempotency_replayed: false
                    warnings:
                      - code: "github_username_ignored"
                        message: "github_username is accepted in v0 but does not affect enrichment yet."
        "400":
          description: Bad request (invalid JSON or identifiers)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                invalidIdentifier:
                  summary: Missing required email
                  value:
                    type: "https://docs.manifolds.run/errors/invalid-identifier"
                    title: "Invalid request"
                    status: 400
                    detail: "Provide email. github_username may also be sent, but is ignored in v0."
                    request_id: "req_01PQRS..."
        "401":
          description: Unauthorized (missing or invalid API key)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                unauthorized:
                  value:
                    type: "https://docs.manifolds.run/errors/unauthorized"
                    title: "Unauthorized"
                    status: 401
                    detail: "Invalid or missing API key."
                    request_id: "req_01PQRS..."
        "403":
          description: >
            Enrichment unavailable for this organization. `code` gives the
            reason (see `EnrichmentDenialCode`). Do not retry automatically;
            the same request will be denied until the organization's access
            changes.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                allowanceExhausted:
                  value:
                    type: "https://docs.manifolds.run/errors/trial_allowance_exhausted"
                    title: "Enrichment unavailable"
                    status: 403
                    code: "trial_allowance_exhausted"
                    detail: "Your enrichment allowance has been used. Contact us for more attempts."
                organizationBlocked:
                  value:
                    type: "https://docs.manifolds.run/errors/organization_blocked"
                    title: "Enrichment unavailable"
                    status: 403
                    code: "organization_blocked"
                    detail: "Enrichment access is blocked. Contact us for assistance."
        "409":
          description: The Idempotency-Key was already used for a different request.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                idempotencyConflict:
                  value:
                    type: "https://docs.manifolds.run/errors/idempotency-conflict"
                    title: "Idempotency conflict"
                    status: 409
                    detail: "This Idempotency-Key was already used for a different request."
        "500":
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                internalError:
                  value:
                    type: "https://docs.manifolds.run/errors/internal-error"
                    title: "Internal Error"
                    status: 500
                    detail: "Failed to ingest submission."
        "503":
          description: >
            The submission could not be recorded. Retry with the same
            Idempotency-Key.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                unavailable:
                  value:
                    type: "https://docs.manifolds.run/errors/unavailable"
                    title: "Temporarily unavailable"
                    status: 503
                    detail: "Could not persist this submission. Retry using the same Idempotency-Key."
                    request_id: "req_01PQRS..."

  /v0/enrichments/batch:
    post:
      operationId: submitEnrichmentBatch
      summary: Submit a batch enrichment request
      description: >
        Submit up to 10,000 contacts for enrichment in one request.

        Batch requests are staged and drained into the enrichment pipeline
        asynchronously at a controlled rate. On success, the API returns
        `202 Accepted` with a batch receipt and a status URL.

        Send one batch at a time. For large lists, split them into batches
        of up to about 1,000 rows and wait for each batch's status to reach
        `completed` or `completed_with_errors` before sending the next. Both
        are terminal drain states; inspect rejected and failed row counts
        before retrying individual rows. Batch idempotency is not supported in v0, so do not retry a batch POST automatically; a retry
        that reaches the server stages the rows again.

        JSON batches accept an `items` array. In v0, each item should contain
        an `email`; missing or malformed row emails are counted as rejected
        rows rather than rejecting the whole batch. The `github_username` field
        is accepted in JSON for forward-compatibility but is currently ignored.
        Each item can also include an optional `external_user_id`.

        For CSV batches, the parser looks for a column named
        `email`, `email address`, `email_address`, or `e-mail`; if none is
        present, it uses the first column. With a recognized email header,
        include a column named `external_user_id` to supply per-row IDs.
        An empty CSV cell omits the ID. An invalid ID returns `400`.

        Batch requests are limited to 10 MB. Batch idempotency is not supported
        in v0.
      security:
        - bearerAuth: []
      requestBody:
        description: >
          Batch payload as JSON, raw CSV, or multipart CSV upload.
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/EnrichmentBatchRequest"
            examples:
              default:
                summary: Submit JSON batch
                value:
                  items:
                    - email: "alice@example.com"
                    - email: "bob@example.com"
              withWarning:
                summary: JSON batch with ignored GitHub username
                value:
                  items:
                    - email: "alice@example.com"
                      github_username: "octocat"
          text/csv:
            schema:
              type: string
              description: Raw CSV body. CSV v1 reads email only.
            examples:
              withHeader:
                summary: CSV with email header
                value: |
                  email
                  alice@example.com
                  bob@example.com
              firstColumnFallback:
                summary: CSV using first-column fallback
                value: |
                  alice@example.com,Alice
                  bob@example.com,Bob
          application/csv:
            schema:
              type: string
              description: Raw CSV body. CSV v1 reads email only.
            examples:
              withHeader:
                summary: CSV with email header
                value: |
                  email
                  alice@example.com
                  bob@example.com
          multipart/form-data:
            schema:
              type: object
              required:
                - file
              properties:
                file:
                  type: string
                  format: binary
                  description: CSV file to upload in the `file` form field.
      responses:
        "202":
          description: Batch queued for staged draining
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/EnrichmentBatchQueued"
              examples:
                default:
                  value:
                    status: "queued"
                    batch_id: "00000000-0000-0000-0000-000000000000"
                    received_at: "2026-04-30T00:00:00.000Z"
                    total_count: 1000
                    accepted_count: 990
                    rejected_count: 10
                    status_url: "/v0/enrichments/batch/00000000-0000-0000-0000-000000000000"
                withWarning:
                  value:
                    status: "queued"
                    batch_id: "00000000-0000-0000-0000-000000000000"
                    received_at: "2026-04-30T00:00:00.000Z"
                    total_count: 1
                    accepted_count: 1
                    rejected_count: 0
                    status_url: "/v0/enrichments/batch/00000000-0000-0000-0000-000000000000"
                    warnings:
                      - code: "github_username_ignored"
                        message: "github_username is accepted in v0 but does not affect batch enrichment yet."
        "400":
          description: Bad request (invalid JSON, CSV, or content type)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                invalidRequest:
                  value:
                    type: "https://docs.manifolds.run/errors/invalid-request"
                    title: "Invalid request"
                    status: 400
                    detail: "Request body must be an object with an items array."
        "401":
          description: Unauthorized (missing, invalid, or non-live API key)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                unauthorized:
                  value:
                    type: "https://docs.manifolds.run/errors/unauthorized"
                    title: "Unauthorized"
                    status: 401
                    detail: "Invalid or missing API key."
                environmentMismatch:
                  value:
                    type: "https://docs.manifolds.run/errors/unauthorized"
                    title: "Unauthorized"
                    status: 401
                    detail: "API key environment mismatch."
        "413":
          description: Batch body or row count is too large
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                bodyTooLarge:
                  value:
                    type: "https://docs.manifolds.run/errors/batch-too-large"
                    title: "Payload Too Large"
                    status: 413
                    detail: "Batch request bodies are limited to 10485760 bytes."
                tooManyRows:
                  value:
                    type: "https://docs.manifolds.run/errors/batch-too-large"
                    title: "Payload Too Large"
                    status: 413
                    detail: "Batch contains 10001 records; the maximum is 10000."
        "403":
          description: >
            Enrichment unavailable for this organization. The last path segment
            of `type` is the reason (see `EnrichmentDenialCode`). Rows can also
            be denied individually after acceptance; those appear in the batch
            status as `rejected` or `failed` rows.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                organizationBlocked:
                  value:
                    type: "https://docs.manifolds.run/errors/organization_blocked"
                    title: "Enrichment unavailable"
                    status: 403
                    detail: "Enrichment access is blocked. Contact us for assistance."
        "500":
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                internalError:
                  value:
                    type: "https://docs.manifolds.run/errors/internal-error"
                    title: "Internal Error"
                    status: 500
                    detail: "Failed to stage enrichment batch."

  /v0/enrichments/batch/{batchId}:
    get:
      operationId: getEnrichmentBatchStatus
      summary: Get batch ingestion status
      description: >
        Return ingestion and drain progress for a previously submitted batch.

        This endpoint reports whether accepted rows have been staged and
        drained into the enrichment pipeline. It does not report full enrichment
        completion.
      security:
        - bearerAuth: []
      parameters:
        - name: batchId
          in: path
          required: true
          description: Batch ID returned by `POST /v0/enrichments/batch`.
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: Batch ingestion status
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/EnrichmentBatchStatus"
              examples:
                draining:
                  value:
                    status: "draining"
                    batch_id: "00000000-0000-0000-0000-000000000000"
                    created_at: "2026-04-30T00:00:00.000Z"
                    updated_at: "2026-04-30T00:00:00.000Z"
                    total_count: 1000
                    counts:
                      pending: 890
                      processing: 0
                      submitted: 100
                      duplicate_replayed: 0
                      rejected: 10
                      failed: 0
                    rejected_samples:
                      - input_index: 7
                        raw_email: "not-an-email"
                        normalized_email: null
                        reason: "malformed_email"
                completed:
                  value:
                    status: "completed"
                    batch_id: "00000000-0000-0000-0000-000000000000"
                    created_at: "2026-04-30T00:00:00.000Z"
                    updated_at: "2026-04-30T00:05:00.000Z"
                    total_count: 1000
                    counts:
                      pending: 0
                      processing: 0
                      submitted: 970
                      duplicate_replayed: 20
                      rejected: 10
                      failed: 0
                    rejected_samples: []
        "400":
          description: Bad request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                missingBatchId:
                  value:
                    type: "https://docs.manifolds.run/errors/invalid-request"
                    title: "Invalid request"
                    status: 400
                    detail: "Missing batch ID."
        "401":
          description: Unauthorized (missing, invalid, or non-live API key)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                unauthorized:
                  value:
                    type: "https://docs.manifolds.run/errors/unauthorized"
                    title: "Unauthorized"
                    status: 401
                    detail: "Invalid or missing API key."
        "404":
          description: Batch not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                notFound:
                  value:
                    type: "https://docs.manifolds.run/errors/not-found"
                    title: "Not Found"
                    status: 404
                    detail: "Batch not found."
        "500":
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /v0/enrichments/submissions/{submissionId}:
    get:
      operationId: getEnrichmentSubmissionStatus
      summary: Get processing status for a single submission
      description: >
        Return where a single submission is in processing. This is the
        `status_url` from the `POST /v0/enrichments` receipt.

        This endpoint never returns enrichment data. Matched results are pushed
        to your configured destinations. `finished` means processing ended; it
        does not mean a match was found (no-match results are only sent to
        destinations that opt in to `submission.completed`). Poll sparingly
        (every 30 seconds or slower) if you poll at all; most integrations only
        need the webhook.
      security:
        - bearerAuth: []
      parameters:
        - name: submissionId
          in: path
          required: true
          description: >
            `submission_id` from the receipt (`subm_` prefix), or the bare UUID.
          schema:
            type: string
            example: "subm_11111111-1111-1111-1111-111111111111"
      responses:
        "200":
          description: Submission processing status
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SubmissionStatus"
              examples:
                processing:
                  value:
                    submission_id: "subm_11111111-1111-1111-1111-111111111111"
                    received_at: "2025-10-17T00:12:34Z"
                    processing_status: "processing"
                denied:
                  value:
                    submission_id: "subm_11111111-1111-1111-1111-111111111111"
                    received_at: "2025-10-17T00:12:34Z"
                    processing_status: "denied"
                    error:
                      code: "trial_allowance_exhausted"
                      detail: "Your enrichment allowance has been used. Contact us for more attempts."
        "400":
          description: Invalid submission ID
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                invalidId:
                  value:
                    type: "https://docs.manifolds.run/errors/invalid-request"
                    title: "Invalid request"
                    status: 400
                    detail: "Invalid submission ID."
        "401":
          description: Unauthorized (missing, invalid, or non-live API key)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: No submission with this ID belongs to your organization
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                notFound:
                  value:
                    type: "https://docs.manifolds.run/errors/not-found"
                    title: "Not Found"
                    status: 404
                    detail: "Submission not found."

webhooks:
  enrichmentCardCreated:
    post:
      operationId: receiveEnrichmentCardCreatedWebhook
      summary: Receive a matched enrichment result
      description: >
        Manifolds sends this outbound webhook to a customer-provided HTTPS
        endpoint when an enrichment card is ready to broadcast. The request body
        is JSON. Return any 2xx response after accepting the event. Delivery is
        retryable, so handlers should dedupe by `delivery_id`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/EnrichmentCardCreatedWebhook"
            examples:
              default:
                value:
                  event: "enrichment_card.created"
                  version: 1
                  enrichment_id: "enr_33333333-3333-3333-3333-333333333333"
                  submission_id: "subm_77777777-7777-7777-7777-777777777777"
                  organization_id: "22222222-2222-2222-2222-222222222222"
                  occurred_at: "2026-04-13T16:00:00.000Z"
                  delivery_id: "66666666-6666-6666-6666-666666666666"
                  data:
                    person:
                      email: "ada@example.com"
                      workEmail: null
                      fullName: "Ada Lovelace"
                      linkedinUrl: "https://www.linkedin.com/in/ada"
                      githubUrl: null
                      jobTitle: "Founder"
                      roleFunctionTags: ["engineering"]
                      roleSeniority: "c_level"
                      emailAffiliation: "work_current_employer"
                    company:
                      name: "Analytical Engines Inc."
                      website: "https://example.com"
                      linkedinUrl: "https://www.linkedin.com/company/example"
                      isYc: false
                      totalFundingUsd: "200000"
                      summary: "Short company summary..."
                      sizeBucket: "2-10"
                      sizeMin: 2
                      sizeMax: 10
                      verticalTags: ["software_it"]
                      capabilityTags: ["custom_software_services"]
                      potentialUseCases: null
      responses:
        "2XX":
          description: Event accepted by the customer endpoint.
        default:
          description: >
            Non-2xx responses, network errors, and timeouts are treated as
            failed delivery attempts and may be retried.

  submissionCompleted:
    post:
      operationId: receiveSubmissionCompletedWebhook
      summary: Receive a terminal no-match result
      description: >
        Manifolds sends this outbound webhook when a webhook destination is
        configured to receive terminal no-match results and a submitted contact
        completes without a matched enrichment card.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SubmissionCompletedWebhook"
            examples:
              noMatch:
                value:
                  event: "submission.completed"
                  version: 1
                  delivery_id: "66666666-6666-6666-6666-666666666666"
                  organization_id: "22222222-2222-2222-2222-222222222222"
                  occurred_at: "2026-04-13T16:00:00.000Z"
                  data:
                    submission:
                      id: "subm_77777777-7777-7777-7777-777777777777"
                      received_at: "2026-04-13T15:59:00.000Z"
                      identifiers:
                        - type: "email"
                          value: "ada@example.com"
                    result:
                      outcome: "no_match"
      responses:
        "2XX":
          description: Event accepted by the customer endpoint.
        default:
          description: >
            Non-2xx responses, network errors, and timeouts are treated as
            failed delivery attempts and may be retried.

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: api_key
      description: |
        Pass your Manifolds API key in the Authorization header:

          Authorization: Bearer mf_live_...

  schemas:
    EnrichmentRequest:
      type: object
      required:
        - email
      properties:
        email:
          type: string
          format: email
          description: >
            Email address to enrich. In v0, this is required and is the only
            identifier that actually drives enrichment.
          example: "foo@bar.com"
        github_username:
          type: string
          description: >
            Reserved for future use. Accepted in the request for
            forward-compatibility, but **currently not used** by the enrichment
            pipeline. Do not rely on it for behavior yet.
        external_user_id:
          $ref: "#/components/schemas/ExternalUserId"
      additionalProperties: false
      description: >
        In v0, `email` is required and drives enrichment.
        `github_username` is accepted for forward-compatibility, but does not
        yet affect the enrichment results.

    ExternalUserId:
      type: string
      minLength: 1
      maxLength: 255
      description: >
        The contact's case-sensitive user ID in your system. Omit this field
        when you have no ID. The string must contain a non-whitespace character
        and cannot contain NUL. Webhook projections preserve the exact value.
        CSV exports prefix a single apostrophe on IDs that start with an
        apostrophe or could be interpreted as a spreadsheet formula. After
        parsing the CSV, remove one leading apostrophe, if present, to recover
        the original ID.
      example: "usr_123"

    SubmissionAccepted:
      type: object
      required:
        - status
        - submission_id
        - received_at
        - idempotency_replayed
      properties:
        status:
          type: string
          enum: ["accepted"]
          description: Receipt status for the submitted request.
          example: "accepted"
        submission_id:
          type: string
          description: Identifier of the submitted enrichment request.
          example: "subm_11111111-1111-1111-1111-111111111111"
        received_at:
          type: string
          format: date-time
          description: Timestamp when the request was received.
          example: "2025-10-17T00:12:34Z"
        idempotency_replayed:
          type: boolean
          description: >
            True if this response was returned from a previous request with
            the same Idempotency-Key, rather than creating a new request.
          example: false
        warnings:
          type: array
          description: Optional warnings about fields that were accepted but ignored.
          items:
            $ref: "#/components/schemas/Warning"
        status_url:
          type: string
          description: >
            Path of `GET /v0/enrichments/submissions/{submissionId}` for this
            submission, relative to the API host.
          example: "/v0/enrichments/submissions/subm_11111111-1111-1111-1111-111111111111"
        processing_status:
          type: string
          enum: ["queued"]
          description: >
            Present when the submission is waiting to start processing. Use
            `status_url` for later states.
          example: "queued"

    SubmissionStatus:
      type: object
      required:
        - submission_id
        - received_at
        - processing_status
      properties:
        submission_id:
          type: string
          example: "subm_11111111-1111-1111-1111-111111111111"
        received_at:
          type: string
          format: date-time
        processing_status:
          type: string
          enum: ["queued", "processing", "finished", "denied", "unknown"]
          description: >
            `queued`: accepted and waiting to start (including while
            processing is paused). `processing`: research is running.
            `finished`: processing ended; this does not mean a match was found.
            `denied`: the organization's access did not allow this submission;
            see `error`. `unknown`: no processing record is available, which can
            happen for submissions made before status tracking existed.
        error:
          type: object
          description: Present when `processing_status` is `denied`.
          required:
            - code
            - detail
          properties:
            code:
              $ref: "#/components/schemas/EnrichmentDenialCode"
            detail:
              type: string
              example: "Your enrichment allowance has been used. Contact us for more attempts."

    EnrichmentDenialCode:
      type: string
      description: >
        Why enrichment was not allowed for this organization.
        `free_matches_exhausted`: the organization's free matches are used up
        (lookups that find no match are free; add a card or contact us for
        more). `trial_allowance_exhausted`: the lookup limit was reached.
      enum:
        - free_matches_exhausted
        - trial_allowance_exhausted
        - organization_blocked
        - organization_paused
        - customer_data_deleting
        - customer_data_retired
        - enrichment_context_invalid

    EnrichmentBatchRequest:
      type: object
      required:
        - items
      properties:
        items:
          type: array
          maxItems: 10000
          description: >
            Contacts to stage for enrichment. Each item should include an
            `email`; missing or malformed row emails are counted as rejected
            rows rather than rejecting the whole batch.
          items:
            $ref: "#/components/schemas/EnrichmentBatchItem"
      additionalProperties: false
      description: >
        JSON batch payload. Batch idempotency is not supported in v0.

    EnrichmentBatchItem:
      type: object
      properties:
        email:
          type: string
          format: email
          description: >
            Email address to enrich. This is the intended v0 batch item field.
            Missing or malformed values are staged as rejected rows.
          example: "alice@example.com"
        github_username:
          type: string
          description: >
            Reserved for future use. Accepted in JSON batch items for
            forward-compatibility, but currently ignored.
          example: "octocat"
        external_user_id:
          $ref: "#/components/schemas/ExternalUserId"
      additionalProperties: true
      description: >
        One contact row in a JSON batch. In v0, only `email` affects
        enrichment.

    EnrichmentBatchQueued:
      type: object
      required:
        - status
        - batch_id
        - received_at
        - total_count
        - accepted_count
        - rejected_count
        - status_url
      properties:
        status:
          type: string
          enum: ["queued"]
          description: Receipt status for the submitted batch.
          example: "queued"
        batch_id:
          type: string
          format: uuid
          description: Identifier for the staged batch.
          example: "00000000-0000-0000-0000-000000000000"
        received_at:
          type: string
          format: date-time
          description: Timestamp when the batch was staged.
          example: "2026-04-30T00:00:00.000Z"
        total_count:
          type: integer
          format: int32
          minimum: 0
          description: Number of rows received after parsing the request body.
          example: 1000
        accepted_count:
          type: integer
          format: int32
          minimum: 0
          description: Number of rows accepted for draining.
          example: 990
        rejected_count:
          type: integer
          format: int32
          minimum: 0
          description: Number of rows rejected during staging.
          example: 10
        status_url:
          type: string
          description: Relative URL for checking batch drain progress.
          example: "/v0/enrichments/batch/00000000-0000-0000-0000-000000000000"
        warnings:
          type: array
          description: Optional warnings about fields that were accepted but ignored.
          items:
            $ref: "#/components/schemas/Warning"

    EnrichmentBatchStatus:
      type: object
      required:
        - status
        - batch_id
        - created_at
        - updated_at
        - total_count
        - counts
        - rejected_samples
      properties:
        status:
          type: string
          enum: ["draining", "completed", "completed_with_errors"]
          description: Ingestion/drain status for the batch.
          example: "draining"
        batch_id:
          type: string
          format: uuid
          description: Batch identifier.
          example: "00000000-0000-0000-0000-000000000000"
        created_at:
          type: string
          format: date-time
          nullable: true
          description: Timestamp when the batch was created.
          example: "2026-04-30T00:00:00.000Z"
        updated_at:
          type: string
          format: date-time
          nullable: true
          description: Timestamp when the batch was last updated.
          example: "2026-04-30T00:05:00.000Z"
        total_count:
          type: integer
          format: int32
          minimum: 0
          description: Total staged rows in the batch.
          example: 1000
        counts:
          $ref: "#/components/schemas/EnrichmentBatchCounts"
        rejected_samples:
          type: array
          description: Small sample of rejected or failed rows.
          items:
            $ref: "#/components/schemas/RejectedBatchRowSample"

    EnrichmentBatchCounts:
      type: object
      required:
        - pending
        - processing
        - submitted
        - duplicate_replayed
        - rejected
        - failed
      properties:
        pending:
          type: integer
          format: int32
          minimum: 0
          description: Rows waiting to be drained.
          example: 890
        processing:
          type: integer
          format: int32
          minimum: 0
          description: Rows currently claimed by a drain job.
          example: 0
        submitted:
          type: integer
          format: int32
          minimum: 0
          description: Rows submitted into the enrichment pipeline.
          example: 100
        duplicate_replayed:
          type: integer
          format: int32
          minimum: 0
          description: Rows handled by duplicate-submission replay.
          example: 20
        rejected:
          type: integer
          format: int32
          minimum: 0
          description: Rows rejected during staging.
          example: 10
        failed:
          type: integer
          format: int32
          minimum: 0
          description: Rows that failed while draining into the enrichment pipeline.
          example: 0

    RejectedBatchRowSample:
      type: object
      required:
        - input_index
        - raw_email
        - normalized_email
        - reason
      properties:
        input_index:
          type: integer
          format: int32
          minimum: 0
          description: Zero-based row index from the parsed batch input.
          example: 7
        raw_email:
          type: string
          description: Email value as received in the input row.
          example: "not-an-email"
        normalized_email:
          type: string
          format: email
          nullable: true
          description: Normalized email when one could be parsed.
          example: null
        reason:
          type: string
          nullable: true
          description: >
            Reason the row was rejected or failed. Common values include
            `malformed_email`, `duplicate_in_batch`, and `ingest_failed`.
            Runtime failures may contain other error text.
          examples:
            - "malformed_email"
            - "duplicate_in_batch"
            - "ingest_failed"

    Warning:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: Machine-readable warning code.
          example: "github_username_ignored"
        message:
          type: string
          description: Human-readable warning message.
          example: "github_username is accepted in v0 but does not affect enrichment yet."

    WebhookEvent:
      oneOf:
        - $ref: "#/components/schemas/EnrichmentCardCreatedWebhook"
        - $ref: "#/components/schemas/SubmissionCompletedWebhook"
      description: Outbound Manifolds webhook event.

    EnrichmentCardCreatedWebhook:
      type: object
      required:
        - event
        - version
        - enrichment_id
        - submission_id
        - organization_id
        - occurred_at
        - delivery_id
        - data
      properties:
        event:
          type: string
          enum: ["enrichment_card.created"]
        version:
          type: integer
          enum: [1]
        enrichment_id:
          type: string
          description: API-facing enrichment identifier.
          example: "enr_33333333-3333-3333-3333-333333333333"
        submission_id:
          type: string
          nullable: true
          description: API-facing submission identifier, when available.
          example: "subm_77777777-7777-7777-7777-777777777777"
        organization_id:
          type: string
          format: uuid
          example: "22222222-2222-2222-2222-222222222222"
        occurred_at:
          type: string
          format: date-time
          example: "2026-04-13T16:00:00.000Z"
        delivery_id:
          type: string
          format: uuid
          description: Stable delivery identifier. Use this as an idempotency key.
          example: "66666666-6666-6666-6666-666666666666"
        data:
          $ref: "#/components/schemas/EnrichmentCardWebhookData"
      additionalProperties: false

    EnrichmentCardWebhookData:
      type: object
      description: >
        Default matched-enrichment data projection. This object can be tailored
        per destination, so consumers should ignore fields they do not need.
      properties:
        person:
          $ref: "#/components/schemas/EnrichmentWebhookPerson"
        company:
          $ref: "#/components/schemas/EnrichmentWebhookCompany"
        submission:
          type: object
          properties:
            external_user_id:
              $ref: "#/components/schemas/ExternalUserId"
      additionalProperties: true

    EnrichmentWebhookPerson:
      type: object
      properties:
        email:
          type: string
          format: email
          nullable: true
        workEmail:
          type: string
          format: email
          nullable: true
          description: Work email discovered when the organization has opted into this field.
        fullName:
          type: string
          nullable: true
        linkedinUrl:
          type: string
          format: uri
          nullable: true
        githubUrl:
          type: string
          format: uri
          nullable: true
        jobTitle:
          type: string
          nullable: true
        roleFunctionTags:
          type: array
          nullable: true
          items:
            type: string
        roleSeniority:
          type: string
          nullable: true
        emailAffiliation:
          type: string
          nullable: true
      additionalProperties: true

    EnrichmentWebhookCompany:
      type: object
      properties:
        name:
          type: string
          nullable: true
        website:
          type: string
          format: uri
          nullable: true
        linkedinUrl:
          type: string
          format: uri
          nullable: true
        isYc:
          type: boolean
          nullable: true
        totalFundingUsd:
          type: string
          nullable: true
          description: Decimal string because large funding values may exceed JSON integer precision.
        summary:
          type: string
          nullable: true
        sizeBucket:
          type: string
          nullable: true
        sizeMin:
          type: integer
          nullable: true
        sizeMax:
          type: integer
          nullable: true
        verticalTags:
          type: array
          nullable: true
          items:
            type: string
        capabilityTags:
          type: array
          nullable: true
          items:
            type: string
        potentialUseCases:
          type: string
          nullable: true
      additionalProperties: true

    SubmissionCompletedWebhook:
      type: object
      required:
        - event
        - version
        - delivery_id
        - organization_id
        - occurred_at
        - data
      properties:
        event:
          type: string
          enum: ["submission.completed"]
        version:
          type: integer
          enum: [1]
        delivery_id:
          type: string
          format: uuid
          description: Stable delivery identifier. Use this as an idempotency key.
          example: "66666666-6666-6666-6666-666666666666"
        organization_id:
          type: string
          format: uuid
          example: "22222222-2222-2222-2222-222222222222"
        occurred_at:
          type: string
          format: date-time
          example: "2026-04-13T16:00:00.000Z"
        data:
          $ref: "#/components/schemas/SubmissionCompletedWebhookData"
      additionalProperties: false

    SubmissionCompletedWebhookData:
      type: object
      required:
        - submission
        - result
      properties:
        submission:
          $ref: "#/components/schemas/WebhookSubmission"
        result:
          $ref: "#/components/schemas/WebhookSubmissionResult"
      additionalProperties: false

    WebhookSubmission:
      type: object
      required:
        - id
        - received_at
        - identifiers
      properties:
        id:
          type: string
          example: "subm_77777777-7777-7777-7777-777777777777"
        received_at:
          type: string
          format: date-time
          example: "2026-04-13T15:59:00.000Z"
        external_user_id:
          $ref: "#/components/schemas/ExternalUserId"
        identifiers:
          type: array
          items:
            $ref: "#/components/schemas/WebhookSubmissionIdentifier"
      additionalProperties: false

    WebhookSubmissionIdentifier:
      type: object
      required:
        - type
        - value
      properties:
        type:
          type: string
          example: "email"
        value:
          type: string
          example: "ada@example.com"
      additionalProperties: false

    WebhookSubmissionResult:
      type: object
      required:
        - outcome
      properties:
        outcome:
          type: string
          enum: ["no_match"]
      additionalProperties: false

    ErrorResponse:
      type: object
      required:
        - type
        - title
        - status
        - detail
      properties:
        type:
          type: string
          format: uri
          description: Machine-readable error type URL.
          example: "https://docs.manifolds.run/errors/invalid-identifier"
        title:
          type: string
          description: Short, human-readable summary of the problem.
          example: "Invalid request"
        status:
          type: integer
          format: int32
          description: HTTP status code.
          example: 400
        detail:
          type: string
          description: Human-readable explanation of the specific error.
          example: "Provide email. github_username may also be sent, but is ignored in v0."
        code:
          type: string
          description: >
            Machine-readable reason, present on `403` responses from
            `POST /v0/enrichments` (see `EnrichmentDenialCode`).
          example: "trial_allowance_exhausted"
        request_id:
          type: string
          nullable: true
          description: >
            Optional request identifier for debugging and support.
          example: "req_01PQRS..."
