{
  "openapi": "3.1.0",
  "info": {
    "title": "AgentSearch Web Search",
    "version": "0.2.4",
    "description": "Pocket Network service agentsearch-web-search-v1 (REST). Live web search for AI agents, LLMs and RAG. JSON in, JSON out. No caller authentication; all inputs arrive in the JSON request body. POST / is an alias of POST /v1/search. Hard 4.5 s answer deadline; backend errors and timeouts come back as HTTP 200 with an `error` object. Up to 5 results per call (max_results is clamped). Up to 12 requests are processed concurrently; when saturated a request waits up to ~2.5 s for a slot before a 429 CAPACITY_LIMIT."
  },
  "servers": [
    {
      "url": "https://relay.agentsearchhq.com",
      "description": "Reference backend (direct)"
    }
  ],
  "paths": {
    "/v1/search": {
      "post": {
        "operationId": "search",
        "summary": "Search the live web and return ranked results as JSON (optionally with page text)",
        "description": "Answers within a hard 4.5 s deadline. Errors reaching the search backend are returned as HTTP 200 with an `error` object and empty results. Compact output by default; add \"debug\": true or ?debug=1 for the full payload.",
        "parameters": [
          {
            "name": "debug",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "1",
                "true",
                "yes"
              ]
            },
            "description": "Full backend payload instead of the compact response."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SearchRequest"
              },
              "examples": {
                "search": {
                  "value": {
                    "query": "Pocket Network",
                    "max_results": 5
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Search results, or an `error` object with empty results when the search could not be completed in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResponse"
                },
                "examples": {
                  "success": {
                    "value": {
                      "query": "Pocket Network",
                      "result_count": 1,
                      "retrieved_at": "2026-09-25T12:00:00Z",
                      "results": [
                        {
                          "title": "Pocket Network",
                          "url": "https://pocket.network/",
                          "content": "Pocket Network is a decentralized ...",
                          "score": 0.91,
                          "published_date": null,
                          "domain": "pocket.network",
                          "retrieved_at": "2026-09-25T12:00:00Z",
                          "trust_level": "high",
                          "trust_score": 0.9
                        }
                      ]
                    }
                  },
                  "timeout": {
                    "value": {
                      "query": "Pocket Network",
                      "result_count": 0,
                      "results": [],
                      "error": {
                        "code": "UPSTREAM_TIMEOUT",
                        "message": "Search did not complete within 4.5 s.",
                        "request_id": "a1b2",
                        "retryable": true
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input: body is not a JSON object with a non-empty query, or max_results is not an integer (INVALID_REQUEST).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "description": "Request body larger than 16 KB (REQUEST_TOO_LARGE).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "All 12 concurrency slots busy for more than ~2.5 s (CAPACITY_LIMIT). Retry shortly.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/": {
      "post": {
        "operationId": "searchRoot",
        "summary": "Alias of POST /v1/search (for relays that arrive without a path)",
        "description": "Answers within a hard 4.5 s deadline. Errors reaching the search backend are returned as HTTP 200 with an `error` object and empty results. Compact output by default; add \"debug\": true or ?debug=1 for the full payload.",
        "parameters": [
          {
            "name": "debug",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "1",
                "true",
                "yes"
              ]
            },
            "description": "Full backend payload instead of the compact response."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SearchRequest"
              },
              "examples": {
                "search": {
                  "value": {
                    "query": "Pocket Network",
                    "max_results": 5
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Search results, or an `error` object with empty results when the search could not be completed in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResponse"
                },
                "examples": {
                  "success": {
                    "value": {
                      "query": "Pocket Network",
                      "result_count": 1,
                      "retrieved_at": "2026-09-25T12:00:00Z",
                      "results": [
                        {
                          "title": "Pocket Network",
                          "url": "https://pocket.network/",
                          "content": "Pocket Network is a decentralized ...",
                          "score": 0.91,
                          "published_date": null,
                          "domain": "pocket.network",
                          "retrieved_at": "2026-09-25T12:00:00Z",
                          "trust_level": "high",
                          "trust_score": 0.9
                        }
                      ]
                    }
                  },
                  "timeout": {
                    "value": {
                      "query": "Pocket Network",
                      "result_count": 0,
                      "results": [],
                      "error": {
                        "code": "UPSTREAM_TIMEOUT",
                        "message": "Search did not complete within 4.5 s.",
                        "request_id": "a1b2",
                        "retryable": true
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input: body is not a JSON object with a non-empty query, or max_results is not an integer (INVALID_REQUEST).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "description": "Request body larger than 16 KB (REQUEST_TOO_LARGE).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "All 12 concurrency slots busy for more than ~2.5 s (CAPACITY_LIMIT). Retry shortly.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/version": {
      "get": {
        "operationId": "version",
        "summary": "Identity probe",
        "responses": {
          "200": {
            "description": "Service identity",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string",
                      "const": "agentsearch-web-search-v1"
                    },
                    "version": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "service"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/health": {
      "get": {
        "operationId": "health",
        "summary": "Readiness probe",
        "responses": {
          "200": {
            "description": "Ready",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "ok"
                    }
                  },
                  "required": [
                    "status"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/capabilities": {
      "get": {
        "operationId": "capabilities",
        "summary": "Routes and limits",
        "responses": {
          "200": {
            "description": "Capabilities",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "SearchRequest": {
        "type": "object",
        "required": [
          "query"
        ],
        "properties": {
          "query": {
            "type": "string",
            "minLength": 1,
            "description": "The search query, in natural language or keywords."
          },
          "max_results": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5,
            "default": 5,
            "description": "How many results to return at most (1-5). Values outside 1-5 are clamped (no error)."
          },
          "debug": {
            "type": "boolean",
            "default": false,
            "description": "Return the full, much larger backend payload (routing telemetry etc.) instead of the compact response. Same as ?debug=1."
          }
        },
        "additionalProperties": true
      },
      "SearchResult": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "content": {
            "type": "string",
            "description": "Snippet or extracted page content."
          },
          "score": {
            "type": "number"
          },
          "published_date": {
            "type": [
              "string",
              "null"
            ]
          },
          "retrieved_at": {
            "type": "string"
          },
          "domain": {
            "type": "string"
          },
          "trust_level": {
            "type": "string"
          },
          "trust_score": {
            "type": "number"
          }
        }
      },
      "SearchResponse": {
        "type": "object",
        "required": [
          "query",
          "result_count",
          "results"
        ],
        "properties": {
          "query": {
            "type": "string",
            "description": "The query as searched."
          },
          "result_count": {
            "type": "integer"
          },
          "retrieved_at": {
            "type": [
              "string",
              "null"
            ],
            "description": "ISO 8601 time of the search."
          },
          "provider": {
            "type": [
              "string",
              "null"
            ],
            "description": "Which search provider answered."
          },
          "results": {
            "type": "array",
            "maxItems": 5,
            "items": {
              "$ref": "#/components/schemas/SearchResult"
            }
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "UPSTREAM_TIMEOUT (no answer inside the 4.5 s deadline), UPSTREAM_UNAVAILABLE, UPSTREAM_NON_JSON, UPSTREAM_HTTP_ERROR, or a code passed through from the search backend (e.g. RATE_LIMITED)."
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              },
              "retryable": {
                "type": "boolean"
              },
              "upstream_status": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "HTTP status from the search backend, when there was one."
              }
            },
            "description": "Present only when the search could not be completed: HTTP status is still 200, results is empty."
          }
        }
      },
      "SearchError": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "UPSTREAM_TIMEOUT (no answer inside the 4.5 s deadline), UPSTREAM_UNAVAILABLE, UPSTREAM_NON_JSON, UPSTREAM_HTTP_ERROR, or a code passed through from the search backend (e.g. RATE_LIMITED)."
          },
          "message": {
            "type": "string"
          },
          "request_id": {
            "type": "string"
          },
          "retryable": {
            "type": "boolean"
          },
          "upstream_status": {
            "type": [
              "integer",
              "null"
            ],
            "description": "HTTP status from the search backend, when there was one."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "examples": [
                  "INVALID_REQUEST",
                  "REQUEST_TOO_LARGE",
                  "CAPACITY_LIMIT"
                ]
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
