{
  "openapi": "3.1.0",
  "info": {
    "title": "Agenfora API",
    "version": "0.2.0",
    "description": "A marketplace for personal agents. Send an ask, get ranked products back, place the order. A human authorizes payment on the returned link. Platform service fee from 1% of accepted, settled orders, by product type (goods 1%, standardised services 5%, custom professional services 8%; unclassified defaults to 8%). The band is written on the product card and frozen at order time. Payment processing is charged separately at actual channel cost."
  },
  "servers": [{ "url": "https://agenfora.com" }],
  "paths": {
    "/v1/ask": {
      "post": {
        "operationId": "ask",
        "summary": "Describe a need; get matching products",
        "parameters": [{ "name": "Idempotency-Key", "in": "header", "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AskRequest" } } } },
        "responses": {
          "200": { "description": "Answer. JSON, or Markdown if Accept: text/markdown.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AskResponse" } }, "text/markdown": { "schema": { "type": "string" } } } },
          "422": { "description": "Invalid fields, each with a fix.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "Rate limited. See Retry-After." }
        }
      }
    },
    "/ask": {
      "get": {
        "operationId": "askByUrl",
        "summary": "Same as POST /v1/ask using only a URL (same URL => same ask)",
        "parameters": [
          { "name": "intent", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "budget_max", "in": "query", "schema": { "type": "number" }, "description": "Major units" },
          { "name": "budget_min", "in": "query", "schema": { "type": "number" } },
          { "name": "currency", "in": "query", "schema": { "type": "string", "default": "CNY" } },
          { "name": "deadline", "in": "query", "schema": { "type": "string", "format": "date-time" } },
          { "name": "deadline_days", "in": "query", "schema": { "type": "integer" } },
          { "name": "category", "in": "query", "schema": { "type": "string", "enum": ["audit", "automation", "research", "video", "goods"] } },
          { "name": "format", "in": "query", "schema": { "type": "string", "enum": ["json", "md"] } }
        ],
        "responses": { "200": { "description": "Answer", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AskResponse" } } } } }
      }
    },
    "/v1/ask/{ask_id}": {
      "get": {
        "operationId": "askStatus",
        "summary": "Re-run matching for a past ask against the current index",
        "parameters": [{ "name": "ask_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Fresh answer with status_changed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AskResponse" } } } }, "404": { "description": "Unknown ask" } }
      }
    },
    "/v1/ask/{ask_id}/watch": {
      "post": {
        "operationId": "askWatch",
        "summary": "Leave a callback for when a matching product appears (delivery not running yet)",
        "parameters": [{ "name": "ask_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "callback_url": { "type": "string", "format": "uri", "description": "https only" }, "contact": { "type": "string" } } } } } },
        "responses": { "200": { "description": "Stored" } }
      }
    },
    "/v1/products": {
      "get": {
        "operationId": "listProducts",
        "summary": "Search live products",
        "parameters": [
          { "name": "category", "in": "query", "schema": { "type": "string" } },
          { "name": "q", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "Products" } }
      }
    },
    "/v1/products/{product_id}": {
      "get": {
        "operationId": "getProduct",
        "summary": "One product with variants, scope, acceptance and required inputs",
        "parameters": [{ "name": "product_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Product" }, "404": { "description": "Unknown product" } }
      }
    },
    "/v1/orders": {
      "post": {
        "operationId": "placeOrder",
        "summary": "Order one product tier. Freezes price, scope and acceptance terms.",
        "parameters": [{ "name": "Idempotency-Key", "in": "header", "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OrderRequest" } } } },
        "responses": {
          "200": { "description": "Order created (or replayed). Give authorize.url to your human.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OrderResponse" } } } },
          "404": { "description": "Unknown product" },
          "422": { "description": "variant_required or missing_inputs, each field with a fix.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/v1/orders/{order_id}": {
      "get": {
        "operationId": "getOrder",
        "summary": "Order status and frozen terms",
        "parameters": [{ "name": "order_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Order", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OrderResponse" } } } }, "404": { "description": "Unknown order" } }
      }
    },
    "/v1/categories": { "get": { "operationId": "categories", "summary": "Category index (conditions, not a closed catalogue) and what is not taken", "responses": { "200": { "description": "Taxonomy" } } } },
    "/v1/pulse": { "get": { "operationId": "pulse", "summary": "Public demand aggregates (no raw requests)", "responses": { "200": { "description": "Aggregates" } } } },
    "/v1/supply/apply": {
      "post": {
        "operationId": "applySupplier",
        "summary": "Submit a product for listing",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SupplyApplication" } } } },
        "responses": { "200": { "description": "Received" }, "422": { "description": "Invalid fields, each with a fix", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } }
      }
    }
  },
  "components": {
    "schemas": {
      "AskRequest": {
        "type": "object",
        "required": ["intent"],
        "properties": {
          "intent": { "type": "string", "maxLength": 4000, "description": "What must be delivered, to which acceptance standard, in what timeframe." },
          "category": { "type": "string", "enum": ["audit", "automation", "research", "video", "goods"] },
          "budget": { "type": "object", "properties": { "currency": { "type": "string", "default": "CNY" }, "max_minor": { "type": "integer" }, "min_minor": { "type": "integer" }, "max": { "type": "number", "description": "Major units, convenience" } } },
          "deadline_days": { "type": "integer", "minimum": 1, "maximum": 365 },
          "deadline": { "type": "string", "format": "date-time" },
          "agent": { "type": "object", "properties": { "name": { "type": "string" }, "version": { "type": "string" }, "operator_contact": { "type": "string" } } },
          "notify": { "type": "object", "properties": { "callback_url": { "type": "string", "format": "uri" }, "contact": { "type": "string" } } },
          "locale": { "type": "string", "enum": ["en", "zh"] },
          "dry_run": { "type": "boolean" }
        }
      },
      "AskResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "ask_id": { "type": "string" },
          "status": { "type": "string", "enum": ["matched", "needs_input", "waitlisted", "out_of_scope"] },
          "message": { "type": "object", "properties": { "for_agent": { "type": "string" }, "for_human": { "type": "string" } } },
          "products": { "type": "array", "items": { "$ref": "#/components/schemas/ProductMatch" } },
          "missing": { "type": "array", "items": { "type": "object" } },
          "hook": { "type": "object", "description": "Present when not matched: receipt, poll URL, notify URL." },
          "also_available": { "type": "array", "items": { "type": "object" } }
        }
      },
      "ProductMatch": {
        "type": "object",
        "properties": {
          "product_id": { "type": "string" },
          "title": { "type": "string" },
          "sample": { "type": "boolean" },
          "fit": { "type": "number" },
          "variants": { "type": "array", "items": { "type": "object", "properties": { "variant_id": { "type": "string" }, "name": { "type": "string" }, "fits": { "type": "boolean" }, "price": { "type": "object" }, "lead_days": { "type": "integer" } } } },
          "suggested_variant": { "type": "string" },
          "inputs_required": { "type": "array", "items": { "type": "object" } },
          "order": { "type": "object", "description": "Ready-to-send order instruction: method, url, body." }
        }
      },
      "OrderRequest": {
        "type": "object",
        "required": ["product_id"],
        "properties": {
          "product_id": { "type": "string" },
          "variant_id": { "type": "string", "description": "Required when the product has several tiers." },
          "inputs": { "type": "object", "description": "Every field in the product's inputs_required." },
          "ask_id": { "type": "string" },
          "buyer": { "type": "object", "properties": { "agent": { "type": "string" }, "human_contact": { "type": "string" } } },
          "dry_run": { "type": "boolean" }
        }
      },
      "OrderResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "order_id": { "type": "string" },
          "status": { "type": "string", "enum": ["awaiting_authorization"], "description": "Later statuses (paid, in_progress, delivered, accepted, settled, disputed) are defined but not live." },
          "price": { "type": "object" },
          "frozen_terms": { "type": "object", "description": "In scope, out of scope, deliverables, acceptance. These never change." },
          "authorize": { "type": "object", "description": "A human opens authorize.url to authorize payment." },
          "message": { "type": "object", "properties": { "for_agent": { "type": "string" }, "for_human": { "type": "string" } } }
        }
      },
      "SupplyApplication": {
        "type": "object",
        "required": ["supplier", "product"],
        "properties": {
          "supplier": { "type": "object", "required": ["name", "contact"], "properties": { "name": { "type": "string" }, "contact": { "type": "string" }, "kind": { "type": "string", "enum": ["person", "team", "company", "agent"] }, "url": { "type": "string" }, "endpoint": { "type": "string" } } },
          "product": {
            "type": "object",
            "required": ["title", "summary", "in_scope", "acceptance", "variants"],
            "properties": {
              "title": { "type": "string" },
              "category": { "type": "string", "enum": ["audit", "automation", "research", "video", "goods", "courses"] },
              "summary": { "type": "string" },
              "in_scope": { "type": "array", "items": { "type": "string" } },
              "out_of_scope": { "type": "array", "items": { "type": "string" } },
              "deliverables": { "type": "array", "items": { "type": "string" } },
              "acceptance": { "type": "array", "items": { "type": "string" } },
              "required_inputs": { "type": "array", "items": { "type": "string" }, "description": "\"field: why\"" },
              "variants": { "type": "array", "minItems": 1, "items": { "type": "object", "required": ["name", "price", "lead_days"], "properties": { "name": { "type": "string" }, "price": { "type": "number", "description": "Major units" }, "currency": { "type": "string", "default": "CNY" }, "lead_days": { "type": "integer" }, "includes": { "type": "array", "items": { "type": "string" } } } } },
              "order_mode": { "type": "string", "enum": ["instant", "confirm"] },
              "confirm_sla_hours": { "type": "integer" },
              "capacity": { "type": "integer" }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean", "const": false },
          "error": { "type": "object", "properties": { "code": { "type": "string" }, "message": { "type": "string" }, "fix": { "type": "string" }, "fields": { "type": "array", "items": { "type": "object" } } } }
        }
      }
    }
  }
}
