{
  "openapi": "3.0.0",
  "info": {
    "title": "Email Enrichment API",
    "version": "1.0.0",
    "description": "API for enriching email addresses with demographic and profile data.\n\n**Open Standards Used:**\n- Countries: ISO 3166-1 (alpha-2 codes and country names)\n- Company Categories: LinkedIn Industry Codes v2\n- Interests Categories: IAB (Interactive Advertising Bureau) Audience Taxonomy v1.1\n- Occupation Categories: LinkedIn or simplified ISCO (International Standard Classification of Occupations)\n\n**String Formatting:**\nAll string values are lowercase except:\n- Proper names (e.g., person names, country names, company names)\n- Abbreviations and codes (e.g., ISO codes, IAB codes)",
    "contact": {
      "email": "support@example.com"
    }
  },
  "servers": [
    {
      "url": "https://your-domain.vercel.app/api/v1",
      "description": "Production server"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/email-enrichment": {
      "get": {
        "summary": "Health check",
        "description": "Check API health and get service information",
        "operationId": "healthCheck",
        "security": [],
        "responses": {
          "200": {
            "description": "API is operational",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Enrich email address",
        "description": "Enrich an email address with demographic and profile data",
        "operationId": "enrichEmail",
        "parameters": [
          {
            "name": "X-Request-ID",
            "in": "header",
            "description": "Optional request correlation ID",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EnrichmentRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully enriched email",
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                },
                "description": "Request correlation ID"
              },
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                },
                "description": "Rate limit maximum requests"
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                },
                "description": "Remaining requests in current window"
              },
              "X-RateLimit-Reset": {
                "schema": {
                  "type": "integer"
                },
                "description": "Unix timestamp when rate limit resets"
              },
              "X-Cache": {
                "schema": {
                  "type": "string",
                  "enum": ["HIT", "MISS"]
                },
                "description": "Cache status"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EnrichmentResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Enrichment failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RateLimitError"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "options": {
        "summary": "CORS preflight",
        "description": "Handle CORS preflight requests",
        "operationId": "corsPreflightEmailEnrichment",
        "security": [],
        "responses": {
          "200": {
            "description": "CORS headers",
            "headers": {
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string"
                }
              },
              "Access-Control-Allow-Methods": {
                "schema": {
                  "type": "string"
                }
              },
              "Access-Control-Allow-Headers": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "API key authentication using Bearer token"
      }
    },
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "properties": {
          "service": {
            "type": "string",
            "example": "Email Enrichment API"
          },
          "version": {
            "type": "string",
            "example": "1.0.0"
          },
          "status": {
            "type": "string",
            "example": "operational"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "rate_limits": {
            "type": "object",
            "properties": {
              "per_api_key": {
                "type": "object",
                "properties": {
                  "requests": {
                    "type": "integer",
                    "example": 100
                  },
                  "window_seconds": {
                    "type": "integer",
                    "example": 60
                  }
                }
              },
              "burst_protection": {
                "type": "object",
                "properties": {
                  "requests": {
                    "type": "integer",
                    "example": 10
                  },
                  "window_seconds": {
                    "type": "integer",
                    "example": 10
                  }
                }
              }
            }
          },
          "pricing": {
            "type": "object",
            "properties": {
              "cost_per_request": {
                "type": "integer",
                "example": 1
              },
              "unit": {
                "type": "string",
                "example": "credits"
              }
            }
          }
        }
      },
      "EnrichmentRequest": {
        "type": "object",
        "required": ["email"],
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "description": "Email address to enrich",
            "example": "john.smith@example.com"
          },
          "force_refresh": {
            "type": "boolean",
            "description": "Skip cache and fetch fresh data",
            "default": false
          }
        }
      },
      "EnrichmentResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "enrichment_data": {
            "$ref": "#/components/schemas/PersonProfile"
          },
          "enriched_at": {
            "type": "string",
            "format": "date-time"
          },
          "credits_used": {
            "type": "integer"
          },
          "credits_remaining": {
            "type": "integer"
          },
          "cached": {
            "type": "boolean"
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PersonProfile": {
        "type": "object",
        "properties": {
          "entity_type": {
            "type": "string",
            "enum": ["person", "organization"],
            "nullable": true
          },
          "name": {
            "type": "string",
            "nullable": true,
            "description": "Full name (proper case)"
          },
          "age": {
            "type": "integer",
            "nullable": true
          },
          "age_source": {
            "type": "string",
            "enum": ["extracted", "inferred"],
            "nullable": true
          },
          "gender": {
            "type": "string",
            "enum": ["male", "female", "other"],
            "nullable": true
          },
          "gender_source": {
            "type": "string",
            "enum": ["extracted", "inferred"],
            "nullable": true
          },
          "city": {
            "type": "string",
            "nullable": true,
            "description": "City name (proper case)"
          },
          "state": {
            "type": "string",
            "nullable": true,
            "description": "State/province name (proper case)"
          },
          "country": {
            "type": "string",
            "nullable": true,
            "description": "Country name (proper case) - ISO 3166-1 standard"
          },
          "country_code": {
            "type": "string",
            "nullable": true,
            "minLength": 2,
            "maxLength": 2,
            "pattern": "^[A-Z]{2}$",
            "description": "ISO 3166-1 alpha-2 country code (uppercase, e.g., 'US', 'GB', 'DE')",
            "example": "US"
          },
          "occupation": {
            "type": "string",
            "nullable": true,
            "description": "Job title or occupation (lowercase except proper nouns)"
          },
          "occupation_category": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Taxonomy"
              }
            ],
            "description": "LinkedIn or simplified ISCO (International Standard Classification of Occupations) occupation categorization"
          },
          "role_seniority": {
            "type": "string",
            "enum": ["Junior", "Mid-level", "Senior", "Director", "VP", "C-suite", "Owner/Founder"],
            "nullable": true
          },
          "company": {
            "type": "string",
            "nullable": true,
            "description": "Company name (proper case)"
          },
          "company_category": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Taxonomy"
              }
            ],
            "description": "LinkedIn Industry Codes v2 categorization"
          },
          "business_email": {
            "type": "string",
            "nullable": true
          },
          "personal_email": {
            "type": "string",
            "nullable": true
          },
          "personal_phone": {
            "type": "string",
            "nullable": true
          },
          "work_phone": {
            "type": "string",
            "nullable": true
          },
          "high_school": {
            "type": "string",
            "nullable": true
          },
          "university": {
            "type": "string",
            "nullable": true
          },
          "instagram_handle": {
            "type": "string",
            "nullable": true
          },
          "instagram_followers": {
            "type": "integer",
            "nullable": true
          },
          "tiktok_handle": {
            "type": "string",
            "nullable": true
          },
          "tiktok_followers": {
            "type": "integer",
            "nullable": true
          },
          "twitter_handle": {
            "type": "string",
            "nullable": true
          },
          "twitter_followers": {
            "type": "integer",
            "nullable": true
          },
          "youtube_handle": {
            "type": "string",
            "nullable": true
          },
          "youtube_followers": {
            "type": "integer",
            "nullable": true
          },
          "linkedin_handle": {
            "type": "string",
            "nullable": true
          },
          "linkedin_followers": {
            "type": "integer",
            "nullable": true
          },
          "interests": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true,
            "description": "Array of interests (lowercase except proper nouns)"
          },
          "interests_category": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Taxonomy"
            },
            "nullable": true,
            "description": "IAB (Interactive Advertising Bureau) Audience Taxonomy v1.1 categorization"
          }
        }
      },
      "Taxonomy": {
        "type": "object",
        "nullable": true,
        "properties": {
          "L1": {
            "type": "string",
            "description": "Top-level category"
          },
          "L2": {
            "type": "string",
            "description": "Second-level category"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Machine-readable error code"
          },
          "message": {
            "type": "string",
            "description": "Human-readable error message"
          },
          "requestId": {
            "type": "string",
            "format": "uuid"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "details": {
            "type": "object",
            "description": "Additional error details"
          }
        }
      },
      "RateLimitError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "example": "rate_limit_exceeded"
          },
          "message": {
            "type": "string"
          },
          "requestId": {
            "type": "string",
            "format": "uuid"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "rateLimit": {
            "type": "object",
            "properties": {
              "limit": {
                "type": "integer"
              },
              "remaining": {
                "type": "integer"
              },
              "reset": {
                "type": "string",
                "format": "date-time"
              },
              "retryAfter": {
                "type": "integer",
                "description": "Seconds until retry"
              }
            }
          }
        }
      }
    }
  }
}
