openapi: 3.1.0
info:
  title: AI Reality Check Partner API
  version: 1.0.0
  description: >-
    AI Reality Check -- Continuity Assurance for AI Workflows. Use this
    tenant-governed API to compare approved baselines against changed AI outputs,
    score continuity drift, and generate audit-ready evidence. Every protected
    /api/v1 operation passes through the Enterprise Authority Boundary and Arc
    Ingress Router, which resolves a Supabase JWT or scoped API key to one
    tenant, loads active policy per request, and enforces server-side role,
    scope, and module entitlement.
servers:
  - url: https://airealitycheck.co
security:
  - SupabaseBearer: []
  - ArcApiKey: []
paths:
  /api/v1/smi/score:
    post:
      summary: Run a deterministic tenant-authorized SMI score
      description: >-
        Launch continuity-check route. Send an approved baseline and changed
        output to receive continuity scores, reason codes, correction guidance,
        audit hash, usage/audit status, and a report id when persistence is
        enabled by tenant policy. Raw baseline/output storage remains
        policy-controlled.
      parameters:
        - $ref: '#/components/parameters/TenantId'
        - $ref: '#/components/parameters/RequestId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [goal, prompt]
              properties:
                goal: { type: string }
                prompt: { type: string }
                output: { type: string }
                aiOutput:
                  type: string
                  description: Accepted alias for changed/new AI output. changedOutput is preferred for launch walkthroughs.
                approvedBaseline:
                  type: string
                  description: Approved or expected output for continuity comparison.
                changedOutput:
                  type: string
                  description: Changed/new AI output. If omitted, output is used.
                baselineOutput:
                  type: string
                  deprecated: false
                  description: Alias retained for existing integrations; approvedBaseline is preferred for launch walkthroughs.
                expectedFormat: { type: string }
                targetAudience: { type: string }
                platform: { type: string }
                painPoints: { type: array, items: { type: string } }
                metadata:
                  type: object
                  description: General caller metadata. For AI operating metadata, aiOperatingMetadata remains the explicit documented structure.
                aiOperatingMetadata:
                  type: object
                  description: Caller-declared operating metadata. Exact token counts are never treated as verified without a trusted server-side source.
                  properties:
                    platformClass: { type: string, enum: [chat_interface, api_model_call, agent_framework, code_generation_tool, workflow_automation, enterprise_copilot, custom_internal_assistant, browser_extension, ide_assistant, unknown] }
                    toolName: { type: string, maxLength: 100 }
                    providerName: { type: string, maxLength: 100 }
                    modelName: { type: string, maxLength: 100 }
                    aiMode: { type: string, enum: [single_turn, multi_turn, agentic, batch, workflow, retrieval_augmented, tool_augmented, unknown] }
                    agentProfile: { type: string }
                    contextProfile: { type: string }
                    iterationProfile: { type: string }
                    iterationIndex: { type: integer, minimum: 0 }
                    workflowId: { type: string, maxLength: 100 }
                    industryContext: { type: string }
                    useCase: { type: string, maxLength: 120 }
                    tokenInputCount: { type: integer, minimum: 0 }
                    tokenOutputCount: { type: integer, minimum: 0 }
                    tokenTotalCount: { type: integer, minimum: 0 }
                    metadataConfidence: { type: string, enum: [verified, declared, inferred, unknown] }
      responses:
        '200':
          description: Deterministic continuity score, usage, and audit status
          content:
            application/json:
              examples:
                launchContinuityCheck:
                  summary: Approved-baseline continuity check
                  value:
                    requestId: launch-demo-001
                    tenantId: tenant_example
                    persisted: true
                    reportId: report_example
                    result:
                      caseId: unlabeled-case
                      engineVersion: smi-morphology-v1
                      scores:
                        resonanceScore: 62
                        driftPressure: 72
                        morphologyAlignment: 58
                      reasonCodes: [MISSING_CONSTRAINT, UNSUPPORTED_FACTUAL_CLAIM]
                      trinaryDecision: revise
                      recommendation:
                        action: revise_with_constraints
                      confidence: medium
                      auditRecord:
                        canonicalHash: hash_example
                    usageRecorded: true
                    auditRecorded: true
        '401': { $ref: '#/components/responses/SafeError' }
        '403': { $ref: '#/components/responses/SafeError' }
        '429': { $ref: '#/components/responses/SafeError' }
  /api/v1/usage:
    get: { summary: List tenant-scoped usage events, responses: { '200': { description: Usage events } } }
  /api/v1/audit:
    get: { summary: List tenant-scoped audit events, responses: { '200': { description: Audit events } } }
  /api/v1/me/capabilities:
    get: { summary: Return server-issued tenant capability snapshot, responses: { '200': { description: Capability snapshot } } }
  /api/v1/reports/{id}/unlock:
    post:
      summary: Server-authoritatively unlock a tenant report
      parameters: [{ $ref: '#/components/parameters/ReportId' }]
      responses:
        '200': { description: Idempotent unlock receipt }
        '402': { $ref: '#/components/responses/SafeError' }
        '403': { $ref: '#/components/responses/SafeError' }
        '404': { $ref: '#/components/responses/SafeError' }
  /api/v1/reports/{id}:
    get:
      summary: Read a tenant-scoped report summary
      description: >-
        Returns safe report summary, metadata, input hash, storage mode, unlock
        status, and raw-input inclusion status. Raw report input is returned only
        when the current tenant policy explicitly allows raw report input.
      parameters:
        - $ref: '#/components/parameters/TenantId'
        - $ref: '#/components/parameters/ReportId'
      responses:
        '200':
          description: Tenant-scoped report summary
          content:
            application/json:
              example:
                requestId: report-read-001
                tenantId: tenant_example
                report:
                  id: report_example
                  status: locked
                  storageMode: summary_only
                  hasRawInput: false
                  rawInputIncluded: false
                  inputHash: sha256-example
                  resultSummary: { engineVersion: smi-morphology-v1 }
        '403': { $ref: '#/components/responses/SafeError' }
        '404': { $ref: '#/components/responses/SafeError' }
  /api/v1/jobs:
    post:
      summary: Create a tenant-governed synchronous batch preview
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [cases], properties: { cases: { type: array, maxItems: 100, items: { type: object } } } }
      responses: { '201': { description: Completed or failed preview job }, '413': { $ref: '#/components/responses/SafeError' } }
  /api/v1/jobs/{id}:
    get:
      summary: Read a tenant-scoped batch preview job
      parameters: [{ $ref: '#/components/parameters/JobId' }]
      responses: { '200': { description: Batch preview job }, '404': { $ref: '#/components/responses/SafeError' } }
  /api/v1/api-keys:
    get: { summary: List API keys without raw secrets, responses: { '200': { description: API key records } } }
    post: { summary: Create one API key and return its raw value once, responses: { '201': { description: One-time API key response } } }
  /api/v1/api-keys/{id}/rotate:
    post: { summary: Revoke and replace an API key, parameters: [{ $ref: '#/components/parameters/ApiKeyId' }], responses: { '201': { description: One-time replacement key response } } }
  /api/v1/api-keys/{id}/revoke:
    post: { summary: Revoke an API key, parameters: [{ $ref: '#/components/parameters/ApiKeyId' }], responses: { '200': { description: Revocation receipt } } }
components:
  parameters:
    TenantId: { name: X-ARC-Tenant-Id, in: header, required: true, schema: { type: string } }
    RequestId: { name: X-Request-Id, in: header, required: false, schema: { type: string } }
    ApiKeyId: { name: id, in: path, required: true, schema: { type: string } }
    ReportId: { name: id, in: path, required: true, schema: { type: string, format: uuid } }
    JobId: { name: id, in: path, required: true, schema: { type: string } }
  securitySchemes:
    SupabaseBearer: { type: http, scheme: bearer, bearerFormat: JWT }
    ArcApiKey: { type: apiKey, in: header, name: X-ARC-API-Key }
  responses:
    SafeError:
      description: Safe structured error
      content:
        application/json:
          schema:
            type: object
            properties:
              requestId: { type: string }
              error: { type: object, properties: { code: { type: string }, message: { type: string } } }
