{
  "openapi": "3.1.0",
  "info": {
    "title": "Anima API",
    "version": "1.0.0",
    "description": "REST API for Anima identity infrastructure: email, voice, vault, audit. RFC 7807 errors, Idempotency-Key support, X-RateLimit headers, x-correlation-id workflow chains.",
    "contact": {
      "name": "Anima support",
      "email": "support@useanima.sh",
      "url": "https://useanima.sh"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://useanima.sh/terms"
    }
  },
  "servers": [
    {
      "url": "https://api.useanima.sh",
      "description": "Production"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Three key prefixes: ak_ (agent), mk_ (master, org-scoped admin), sk_ (service, internal)."
      }
    },
    "headers": {
      "IdempotencyKey": {
        "description": "Idempotency key for safe retries. 1-255 ASCII printable chars.",
        "schema": {
          "type": "string",
          "maxLength": 255
        }
      },
      "XCorrelationId": {
        "description": "Workflow correlation ID; threads across email + voice + vault + phone.",
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 7807 problem document.",
        "properties": {
          "type": {
            "type": "string",
            "format": "uri"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "instance": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "required": [
          "type",
          "title",
          "status",
          "detail",
          "code"
        ]
      },
      "EmailSendRequest": {
        "type": "object",
        "required": [
          "to",
          "subject",
          "body"
        ],
        "properties": {
          "to": {
            "type": "string",
            "format": "email"
          },
          "subject": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "cc": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "email"
            }
          },
          "bcc": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "email"
            }
          }
        }
      },
      "VoiceCallRequest": {
        "type": "object",
        "required": [
          "to",
          "tier",
          "metadata"
        ],
        "properties": {
          "to": {
            "type": "string",
            "description": "E.164 destination, e.g. +14155550142"
          },
          "tier": {
            "type": "string",
            "enum": [
              "basic",
              "premium"
            ]
          },
          "voiceId": {
            "type": "string"
          },
          "greeting": {
            "type": "string"
          },
          "metadata": {
            "type": "object",
            "required": [
              "consent_source"
            ],
            "properties": {
              "consent_source": {
                "type": "string",
                "description": "TCPA consent assertion. Required by the gate.",
                "enum": [
                  "opt-in:web-form",
                  "opt-in:double-opt-in",
                  "customer-initiated",
                  "business-relationship",
                  "prior-express-consent"
                ]
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/v1/email/send": {
      "post": {
        "summary": "Send outbound email",
        "operationId": "emailSend",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmailSendRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sent"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "402": {
            "description": "Hard-cap or per-tier quota reached",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/voice/calls": {
      "post": {
        "summary": "Place outbound voice call (TCPA + RND + time-of-day gated server-side)",
        "operationId": "voicePlace",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VoiceCallRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Dialing"
          },
          "402": {
            "description": "Per-tier daily call cap reached"
          },
          "403": {
            "description": "Blocked by TCPA / RND / time-of-day gate"
          },
          "503": {
            "description": "Voice unavailable (FEATURE_PHONE_ENABLED off or provider down)"
          }
        }
      }
    },
    "/v1/audit/events": {
      "get": {
        "summary": "Fetch audit-event chain by correlation ID",
        "operationId": "auditByCorrelation",
        "parameters": [
          {
            "name": "correlation_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Chain rendered"
          },
          "404": {
            "description": "Unknown correlation ID"
          }
        }
      }
    },
    "/v1/events/stream": {
      "get": {
        "summary": "Server-Sent Events stream of live agent activity",
        "operationId": "eventsStream",
        "responses": {
          "200": {
            "description": "text/event-stream",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/agent/sign-up": {
      "post": {
        "summary": "Provision a fresh org + agent + inbox + ak_ key",
        "operationId": "agentSignUp",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "human_email",
                  "username"
                ],
                "properties": {
                  "human_email": {
                    "type": "string",
                    "format": "email"
                  },
                  "username": {
                    "type": "string",
                    "pattern": "^[a-z0-9-]+$"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Agent provisioned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "agent_id": {
                      "type": "string"
                    },
                    "organization_id": {
                      "type": "string"
                    },
                    "inbox_id": {
                      "type": "string"
                    },
                    "api_key": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}