{
  "openapi": "3.1.0",
  "info": {
    "title": "TRACE Search \u2014 Agent API",
    "version": "1.0.0",
    "description": "Accountless, pay-per-request search over x402. Every paid endpoint returns HTTP 402 with Bazaar-compatible payment requirements until a valid X-PAYMENT header is supplied.",
    "x-x402": {
      "network": "eip155:8453",
      "asset": "USDC",
      "facilitator": "https://x402.org/facilitator"
    }
  },
  "servers": [
    {
      "url": "https://trace-cloud.aioniq.ai"
    }
  ],
  "paths": {
    "/agent/v1/search": {
      "post": {
        "summary": "Search an ephemeral private index",
        "description": "Semantic, cross-modal (text\u2192image), or reverse-image search. $0.006 per call.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SearchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Results",
            "headers": {
              "X-PAYMENT-RESPONSE": {
                "description": "Base64 settlement receipt",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResponse"
                }
              }
            }
          },
          "402": {
            "description": "Payment required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentRequired"
                }
              }
            }
          }
        }
      }
    },
    "/agent/v1/ingest": {
      "post": {
        "summary": "Ingest a file ($0.03)",
        "description": "multipart/form-data upload into the payer's ephemeral index.",
        "responses": {
          "200": {
            "description": "Item + job id"
          },
          "402": {
            "description": "Payment required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentRequired"
                }
              }
            }
          }
        }
      }
    },
    "/agent/v1/items/{item_id}": {
      "get": {
        "summary": "Fetch item metadata ($0.002)",
        "parameters": [
          {
            "name": "item_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Item metadata"
          },
          "402": {
            "description": "Payment required"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "SearchRequest": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string",
            "description": "Natural-language query"
          },
          "image_b64": {
            "type": "string",
            "description": "Base64 image for reverse search"
          },
          "families": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "visual | text_semantic | raw"
          },
          "k": {
            "type": "integer",
            "default": 30
          }
        }
      },
      "SearchHit": {
        "type": "object",
        "properties": {
          "item": {
            "type": "object"
          },
          "confidence": {
            "type": "number"
          },
          "family": {
            "type": "string"
          },
          "locator": {
            "type": "object",
            "properties": {
              "time_s": {
                "type": "number"
              },
              "page": {
                "type": "integer"
              }
            }
          }
        }
      },
      "SearchResponse": {
        "type": "object",
        "properties": {
          "hits": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SearchHit"
            }
          },
          "latency_ms": {
            "type": "number"
          }
        }
      },
      "PaymentRequired": {
        "type": "object",
        "properties": {
          "x402Version": {
            "type": "integer"
          },
          "error": {
            "type": "string"
          },
          "resource": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "accepts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "scheme": {
                  "type": "string"
                },
                "network": {
                  "type": "string"
                },
                "payTo": {
                  "type": "string"
                },
                "maxAmountRequired": {
                  "type": "string"
                },
                "resource": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}