{
  "openapi": "3.1.0",
  "info": {
    "title": "GeoEval Clean-Room AI Search & GEO Evaluation API",
    "version": "1.0.0",
    "description": "Enterprise clean-room API for capturing real consumer-UI answers, query fan-out, ranked web_results, inline citations, and optional raw HTML evidence across global AI search engines.",
    "contact": {
      "name": "GeoEval Engineering",
      "url": "https://geoeval.com/docs/"
    }
  },
  "servers": [
    {
      "url": "https://api.geoeval.com",
      "description": "Production API"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/v1/capture": {
      "post": {
        "operationId": "createCapture",
        "summary": "Run a synchronous clean-room AI search capture",
        "description": "Captures a fresh, zero-cache, stateless consumer-UI response from the specified AI search engine. Credits are deducted only on HTTP 200 success.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CaptureRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validated structured AI search capture",
            "headers": {
              "X-Request-Id": { "schema": { "type": "string" } },
              "X-Credits-Charged": { "schema": { "type": "integer" } },
              "X-Credits-Remaining": { "schema": { "type": "integer" } },
              "X-RateLimit-Remaining": { "schema": { "type": "integer" } }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CaptureResponse"
                }
              }
            }
          },
          "400": { "description": "Invalid request parameters (0 credits charged)" },
          "401": { "description": "Unauthorized API key (0 credits charged)" },
          "402": { "description": "Insufficient credits (0 credits charged)" },
          "429": { "description": "Rate limit exceeded (0 credits charged, retryable)" },
          "504": { "description": "Upstream capture timeout (0 credits charged, retryable)" }
        }
      }
    },
    "/v1/batches": {
      "post": {
        "operationId": "createBatch",
        "summary": "Submit an asynchronous high-throughput evaluation batch",
        "description": "Queues a clean-room matrix job across Prompts x Engines x Countries x Repeat Count with lower async credit rates and webhook completion callbacks.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BatchRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Batch job accepted and queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchResponse"
                }
              }
            }
          },
          "402": { "description": "Insufficient credit balance for estimated matrix size" },
          "422": { "description": "Plan quota exceeded with structured {resource, limit, used, plan}" }
        }
      }
    },
    "/v1/engines": {
      "get": {
        "operationId": "listEngines",
        "summary": "Discover live engines, supported countries, and credit rates",
        "responses": {
          "200": {
            "description": "Active engine registry",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "engines": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/EngineInfo"
                      }
                    }
                  },
                  "required": ["engines"]
                }
              }
            }
          }
        }
      }
    },
    "/v1/account/balance": {
      "get": {
        "operationId": "getAccountBalance",
        "summary": "Retrieve workspace credit balance, active plan, and concurrency limits",
        "responses": {
          "200": {
            "description": "Current workspace balance and quota details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountBalance"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key generated in https://console.geoeval.com"
      }
    },
    "schemas": {
      "CaptureRequest": {
        "type": "object",
        "required": ["engine", "prompt"],
        "properties": {
          "engine": {
            "type": "string",
            "enum": ["chatgpt", "google-ai-overview", "perplexity", "gemini", "grok", "claude"]
          },
          "prompt": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000
          },
          "country": {
            "type": "string",
            "enum": ["us", "jp", "kr", "gb", "de"],
            "default": "us"
          },
          "language": {
            "type": "string",
            "default": "en"
          },
          "web_search": {
            "type": "boolean",
            "default": true
          },
          "include_raw_html": {
            "type": "boolean",
            "default": false
          },
          "include_screenshot": {
            "type": "boolean",
            "default": false
          },
          "auth_mode": {
            "type": "string",
            "enum": ["anonymous", "dedicated_pool"],
            "default": "anonymous"
          },
          "zero_retention": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "CaptureResponse": {
        "type": "object",
        "required": [
          "request_id",
          "status",
          "collected_at",
          "timing",
          "billing",
          "execution_policy",
          "client_context",
          "input",
          "result",
          "evidence"
        ],
        "properties": {
          "request_id": { "type": "string" },
          "status": { "type": "string", "enum": ["success"] },
          "collected_at": { "type": "string", "format": "date-time" },
          "timing": {
            "type": "object",
            "properties": {
              "request_ms": { "type": "integer" },
              "parse_ms": { "type": "integer" },
              "total_ms": { "type": "integer" }
            }
          },
          "billing": {
            "type": "object",
            "properties": {
              "credits_charged": { "type": "integer" },
              "credits_remaining": { "type": "integer" },
              "mode": { "type": "string", "enum": ["sync", "async"] }
            }
          },
          "execution_policy": {
            "type": "object",
            "properties": {
              "cache_used": { "type": "boolean" },
              "memory_enabled": { "type": "boolean" },
              "session_reused": { "type": "boolean" },
              "auth_mode": { "type": "string", "enum": ["anonymous", "dedicated_pool"] },
              "web_search_requested": { "type": "boolean" },
              "is_web_search_performed": { "type": "boolean" }
            }
          },
          "client_context": {
            "type": "object",
            "properties": {
              "engine": { "type": "string" },
              "model_detected": { "type": "string" },
              "surface": { "type": "string", "enum": ["web", "ios", "android"] },
              "device_type": { "type": "string" },
              "app_version": { "type": ["string", "null"] },
              "country": { "type": "string" },
              "language": { "type": "string" }
            }
          },
          "input": {
            "type": "object",
            "properties": {
              "prompt": { "type": "string" }
            }
          },
          "result": {
            "type": "object",
            "properties": {
              "answer_markdown": { "type": "string" },
              "text_blocks": { "type": "array", "items": { "type": "object" } },
              "is_truncated": { "type": "boolean" },
              "search_queries": { "type": "array", "items": { "type": "string" } },
              "web_results": { "type": "array", "items": { "type": "object" } },
              "reference_links": { "type": "array", "items": { "type": "object" } },
              "citations": { "type": "array", "items": { "type": "object" } }
            }
          },
          "evidence": {
            "type": "object",
            "properties": {
              "raw_html_url": { "type": ["string", "null"] },
              "screenshot_url": { "type": ["string", "null"] },
              "expires_at": { "type": ["string", "null"], "format": "date-time" }
            }
          }
        }
      },
      "BatchRequest": {
        "type": "object",
        "required": ["engines", "prompts"],
        "properties": {
          "name": { "type": "string" },
          "engines": {
            "type": "array",
            "items": { "type": "string" },
            "minItems": 1
          },
          "countries": {
            "type": "array",
            "items": { "type": "string" },
            "default": ["us"]
          },
          "repeat_count": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "default": 1
          },
          "web_search": { "type": "boolean", "default": true },
          "include_raw_html": { "type": "boolean", "default": false },
          "prompts": {
            "type": "array",
            "items": { "type": "string" },
            "minItems": 1
          },
          "webhook_url": { "type": "string", "format": "uri" },
          "export_format": {
            "type": "string",
            "enum": ["jsonl", "csv", "parquet"],
            "default": "jsonl"
          }
        }
      },
      "BatchResponse": {
        "type": "object",
        "properties": {
          "batch_id": { "type": "string" },
          "status": { "type": "string", "enum": ["queued", "running", "completed", "failed"] },
          "total_items": { "type": "integer" },
          "estimated_max_credits": { "type": "integer" },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "EngineInfo": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "status": { "type": "string", "enum": ["live", "roadmap"] },
          "countries": { "type": "array", "items": { "type": "string" } },
          "credits_async": { "type": "integer" },
          "credits_sync": { "type": "integer" },
          "credits_evidence_addon": { "type": "integer" },
          "supports_web_search_toggle": { "type": "boolean" }
        }
      },
      "AccountBalance": {
        "type": "object",
        "properties": {
          "plan": { "type": "string" },
          "subscription_credits_remaining": { "type": "integer" },
          "payg_credits_remaining": { "type": "integer" },
          "total_credits_remaining": { "type": "integer" },
          "concurrency_limit": { "type": "integer" }
        }
      }
    }
  }
}
