{
  "openapi": "3.1.0",
  "info": {
    "title": "HumanDial API",
    "version": "0.1.0",
    "description": "Cold-calling API for AI agents. Post a mission, get structured outcomes from real human callers. Currently in private beta. Email hello@humandial.co for API key access.",
    "contact": {
      "name": "HumanDial",
      "email": "hello@humandial.co",
      "url": "https://humandial.co"
    },
    "license": { "name": "Proprietary" }
  },
  "servers": [
    { "url": "https://api.humandial.co/v1", "description": "Production" }
  ],
  "security": [{ "bearerAuth": [] }],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key (hd_live_…)"
      }
    },
    "schemas": {
      "Lead": {
        "type": "object",
        "required": ["phone"],
        "properties": {
          "name": { "type": "string" },
          "phone": { "type": "string", "description": "E.164 format" },
          "externalId": { "type": "string", "description": "Your own ID for this lead" },
          "fields": { "type": "object", "additionalProperties": true }
        }
      },
      "Mission": {
        "type": "object",
        "required": ["name", "leads", "hookMd", "outcomeSchema"],
        "properties": {
          "name": { "type": "string" },
          "leads": { "type": "array", "items": { "$ref": "#/components/schemas/Lead" } },
          "hookMd": { "type": "string", "description": "Caller reads this verbatim" },
          "scriptMd": { "type": "string", "description": "Full markdown script with ### branches" },
          "outcomeSchema": {
            "type": "object",
            "description": "JSON schema describing the structured outcome form callers fill",
            "additionalProperties": true
          },
          "qualifiedRule": {
            "type": "object",
            "description": "Small expression DSL: which outcomes count as qualified for bonus"
          },
          "qualifiedBonusUsd": { "type": "number", "default": 2 },
          "hourlyRate": { "type": "number", "default": 8 },
          "webhookUrl": { "type": "string", "format": "uri" }
        }
      },
      "MissionResponse": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "msn_8f3a91b4" },
          "status": { "type": "string", "enum": ["draft", "queued", "active", "done"] },
          "callersAssigned": { "type": "integer" }
        }
      },
      "Outcome": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "out_2a1c4e7f" },
          "missionId": { "type": "string" },
          "leadId": { "type": "string" },
          "callerId": { "type": "string" },
          "isQualified": { "type": "boolean" },
          "data": { "type": "object", "additionalProperties": true },
          "recordingUrl": { "type": "string", "format": "uri" },
          "submittedAt": { "type": "string", "format": "date-time" }
        }
      }
    }
  },
  "paths": {
    "/missions": {
      "post": {
        "summary": "Post a new mission",
        "operationId": "createMission",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/Mission" } }
          }
        },
        "responses": {
          "201": {
            "description": "Mission queued",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/MissionResponse" } }
            }
          },
          "501": { "description": "Private beta. Email hello@humandial.co for access." }
        }
      },
      "get": {
        "summary": "List your missions",
        "operationId": "listMissions",
        "responses": {
          "501": { "description": "Private beta. Email hello@humandial.co for access." }
        }
      }
    },
    "/missions/{id}": {
      "get": {
        "summary": "Get one mission",
        "operationId": "getMission",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "501": { "description": "Private beta. Email hello@humandial.co for access." }
        }
      }
    },
    "/missions/{id}/outcomes": {
      "get": {
        "summary": "List outcomes for a mission",
        "operationId": "listOutcomes",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Outcomes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "$ref": "#/components/schemas/Outcome" }
                }
              }
            }
          },
          "501": { "description": "Private beta. Email hello@humandial.co for access." }
        }
      }
    }
  },
  "webhooks": {
    "outcome.submitted": {
      "post": {
        "summary": "Fires when a caller submits a structured outcome",
        "requestBody": {
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/Outcome" } }
          }
        },
        "responses": { "200": { "description": "Acknowledged" } }
      }
    },
    "recording.ready": {
      "post": {
        "summary": "Fires when a call recording is available",
        "responses": { "200": { "description": "Acknowledged" } }
      }
    }
  }
}
