{
 "openapi": "3.1.0",
 "info": {
  "title": "Ni Biashara Directory API",
  "version": "1.3.0",
  "description": "JSON of the Ni Biashara diaspora business directory: every listing, search, a listed-and-verified check and public counts. Reading needs no credentials. The two sign-up routes and the security schemes are the ways to a higher check limit; the paid route sells directory counts over x402. CC BY 4.0 for curation; attribute Ni Biashara. Errors a machine can act on are application/problem+json: an unknown path under /api/v1 answers 404, and a route asked with a method it does not take answers 405 with Allow.",
  "contact": {
   "name": "Ni Biashara",
   "email": "twe@nibiashara.biz",
   "url": "https://nibiashara.com/auth.md"
  }
 },
 "servers": [
  {
   "url": "https://nibiashara.com/api/v1"
  }
 ],
 "paths": {
  "/businesses.json": {
   "get": {
    "operationId": "listBusinesses",
    "summary": "All diaspora business listings",
    "responses": {
     "200": {
      "description": "Object containing directory metadata and a businesses array",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "count",
          "businesses"
         ],
         "properties": {
          "version": {
           "type": "string"
          },
          "generated": {
           "type": "string"
          },
          "license": {
           "$ref": "#/components/schemas/License"
          },
          "source": {},
          "count": {
           "type": "integer"
          },
          "businesses": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Listing"
           }
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "The catalog is unavailable right now",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "description": "The static catalog plus every published addition, de-duplicated. count is the number of rows returned. Cached for two minutes."
   }
  },
  "/businesses/{id}.json": {
   "get": {
    "operationId": "getBusiness",
    "summary": "One listing by id",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Listing id, as in a /b/<id>/ link or a search result.",
      "schema": {
       "type": "string",
       "pattern": "^[a-z0-9][a-z0-9-]{0,199}$"
      },
      "example": "224-cafe-atlanta"
     }
    ],
    "responses": {
     "200": {
      "description": "The listing",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "version",
          "license",
          "business"
         ],
         "properties": {
          "version": {
           "type": "string"
          },
          "license": {
           "$ref": "#/components/schemas/License"
          },
          "business": {
           "$ref": "#/components/schemas/Listing"
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "No published listing has that id",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The catalog is unavailable right now",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/search": {
   "get": {
    "operationId": "searchBusinesses",
    "summary": "Keyword search of listings (name, blurb, category, city, metro)",
    "parameters": [
     {
      "name": "q",
      "in": "query",
      "required": false,
      "description": "Keywords, max 20 words; all must match. One-letter words are ignored. A close spelling can match, and a place name can narrow the search.",
      "schema": {
       "type": "string",
       "maxLength": 100
      }
     },
     {
      "name": "city",
      "in": "query",
      "required": false,
      "description": "A whole city or metro name, for example Dallas or DFW. Part of a name does not match.",
      "schema": {
       "type": "string",
       "maxLength": 100
      }
     },
     {
      "name": "category",
      "in": "query",
      "required": false,
      "description": "Category words; part of a word matches unless category_exact is set.",
      "schema": {
       "type": "string",
       "maxLength": 100
      }
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 20
      }
     },
     {
      "name": "metro",
      "in": "query",
      "required": false,
      "description": "A whole metro name, for example DFW. Part of a name does not match.",
      "schema": {
       "type": "string",
       "maxLength": 100
      }
     },
     {
      "name": "offset",
      "in": "query",
      "required": false,
      "description": "Results to skip, for paging.",
      "schema": {
       "type": "integer",
       "minimum": 0,
       "default": 0
      }
     },
     {
      "name": "category_exact",
      "in": "query",
      "required": false,
      "description": "Set to 1 to match the whole category name only.",
      "schema": {
       "type": "string",
       "enum": [
        "1"
       ]
      }
     },
     {
      "name": "facets",
      "in": "query",
      "required": false,
      "description": "Set to 1 to include counts by metro and category for the whole catalog.",
      "schema": {
       "type": "string",
       "enum": [
        "1"
       ]
      }
     },
     {
      "name": "id",
      "in": "query",
      "required": false,
      "description": "A listing id to return in selected, alongside the results.",
      "schema": {
       "type": "string",
       "maxLength": 200
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Search results",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "version": {
           "type": "string"
          },
          "query": {
           "type": "object"
          },
          "total": {
           "type": "integer"
          },
          "license": {
           "$ref": "#/components/schemas/License"
          },
          "results": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Listing"
           }
          },
          "match": {
           "type": "object",
           "description": "How the query was read",
           "properties": {
            "similar": {
             "type": "boolean"
            },
            "location": {
             "type": [
              "object",
              "null"
             ]
            },
            "exact_name": {
             "type": "boolean"
            }
           }
          },
          "selected": {
           "description": "The listing named by id, when id is given.",
           "oneOf": [
            {
             "$ref": "#/components/schemas/Listing"
            },
            {
             "type": "null"
            }
           ]
          },
          "facets": {
           "type": "object",
           "description": "Present when facets=1.",
           "properties": {
            "total": {
             "type": "integer"
            },
            "metros": {
             "type": "object"
            },
            "categories": {
             "type": "object"
            }
           }
          },
          "links": {
           "$ref": "#/components/schemas/Links"
          }
         }
        }
       }
      },
      "headers": {
       "RateLimit-Policy": {
        "$ref": "#/components/headers/RateLimit-Policy"
       }
      }
     },
     "400": {
      "description": "Parameter too long, too many words, or an invalid listing id",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "405": {
      "description": "Method not allowed",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/BurstBlocked"
     },
     "502": {
      "description": "The listing index could not be loaded",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "description": "Free, with no daily limit and no key. The only limit is the short burst limit at the edge, named in RateLimit-Policy. Going over it gets the caller blocked at the edge for a time: see the 429 answer."
   }
  },
  "/verify": {
   "get": {
    "operationId": "verifyBusiness",
    "summary": "Check whether a business is listed and whether it is verified",
    "description": "Provide at least one of name, phone or website. Free, with a fair limit of 60 checks a day per visitor. An API key or an agent linked to a person is not held to it; see https://nibiashara.com/auth.md. Every answer names the limit the caller is held to (RateLimit-Policy) and what is left (RateLimit). A 429 from this API is a problem document with the ways forward; a 429 from the edge's burst block is the edge's own answer and has none of them (see the 429 answer).",
    "parameters": [
     {
      "name": "name",
      "in": "query",
      "required": false,
      "description": "Business name. Everyday forms match, for example without a trailing \"& Bar\" or \"LLC\".",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "phone",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "website",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "metro",
      "in": "query",
      "required": false,
      "description": "Narrows a match: a different metro lowers it.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The result and up to 5 matches",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "result",
          "matches",
          "plan",
          "note",
          "source",
          "links"
         ],
         "properties": {
          "result": {
           "type": "string",
           "description": "LISTED for a strong match, POSSIBLE_MATCH for a possible one, NOT_LISTED for none",
           "enum": [
            "LISTED",
            "POSSIBLE_MATCH",
            "NOT_LISTED"
           ]
          },
          "matches": {
           "type": "array",
           "maxItems": 5,
           "items": {
            "type": "object",
            "required": [
             "id",
             "name",
             "url",
             "listed",
             "status",
             "verified",
             "ownership_verified",
             "match"
            ],
            "properties": {
             "id": {
              "type": "string"
             },
             "name": {
              "type": "string"
             },
             "category": {
              "type": "string"
             },
             "metro": {
              "type": "string"
             },
             "city": {
              "type": "string"
             },
             "phone": {
              "type": [
               "string",
               "null"
              ]
             },
             "website": {
              "type": [
               "string",
               "null"
              ]
             },
             "url": {
              "type": "string"
             },
             "listed": {
              "type": "boolean"
             },
             "status": {
              "type": "string",
              "description": "The listing status on a strong match. Always listed on a possible match.",
              "enum": [
               "listed",
               "claimed",
               "verified_business",
               "verified_client"
              ]
             },
             "verified": {
              "type": "boolean",
              "description": "True when the owner confirmed the listing, or Ni Biashara has dealt with the business directly. Always false on a possible match: the name may belong to a different business."
             },
             "ownership_verified": {
              "type": "boolean",
              "description": "Older name for verified, with the same value. Use verified.",
              "deprecated": true
             },
             "match": {
              "type": "string",
              "description": "How the query matched this listing",
              "enum": [
               "strong",
               "possible"
              ]
             }
            }
           }
          },
          "plan": {
           "type": "string",
           "description": "The access tier used for this check"
          },
          "note": {
           "type": "string"
          },
          "source": {
           "type": "string"
          },
          "links": {
           "$ref": "#/components/schemas/Links"
          }
         }
        }
       }
      },
      "headers": {
       "RateLimit-Policy": {
        "$ref": "#/components/headers/RateLimit-Policy"
       },
       "RateLimit": {
        "$ref": "#/components/headers/RateLimit"
       }
      }
     },
     "400": {
      "description": "None of name, phone or website was given, or a token was sent in the URL",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Invalid, expired or revoked API key or token",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Access blocked",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "405": {
      "$ref": "#/components/responses/MethodNotAllowed"
     },
     "429": {
      "$ref": "#/components/responses/LimitReached"
     },
     "503": {
      "description": "Access or the limit could not be checked right now. Retry-After, when present, says when to try again.",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "security": [
     {},
     {
      "apiKey": []
     },
     {
      "agentToken": [
       "directory.read"
      ]
     }
    ]
   }
  },
  "/stats": {
   "get": {
    "operationId": "getStats",
    "summary": "Public counts: listings, claims this week, AI reads",
    "description": "Aggregate counters only: no names and no contacts. listings.total is the one public listing count. Cached for a minute.",
    "responses": {
     "200": {
      "description": "Counts",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "week_start",
          "week_start_tz",
          "claims_this_week",
          "listings"
         ],
         "properties": {
          "week_start": {
           "type": "string",
           "description": "Start of the week the claim counts cover: Monday 00:00 America/Chicago, as a UTC timestamp",
           "format": "date-time"
          },
          "week_start_tz": {
           "type": "string"
          },
          "claims_this_week": {
           "type": "integer",
           "description": "Claims saved since week_start"
          },
          "verified_this_week": {
           "type": [
            "integer",
            "null"
           ],
           "description": "Claims verified since week_start"
          },
          "listings": {
           "type": [
            "object",
            "null"
           ],
           "description": "The public listing count and its parts",
           "properties": {
            "total": {
             "type": "integer",
             "description": "Every published listing"
            },
            "metros": {
             "type": "integer",
             "description": "Metro areas with at least one listing"
            },
            "static": {
             "type": "integer",
             "description": "Listings in the static catalog"
            },
            "found": {
             "type": "integer",
             "description": "Published additions not yet claimed"
            },
            "claimed": {
             "type": "integer",
             "description": "Published additions claimed by their owner"
            },
            "verified": {
             "type": "integer",
             "description": "Verified listings"
            },
            "snapshot": {
             "type": [
              "string",
              "null"
             ],
             "description": "Date of the static catalog"
            }
           }
          },
          "agents": {
           "type": [
            "object",
            "null"
           ],
           "description": "Agent traffic on Ni Biashara Shelves, from its public aggregate (source names the URL). Null when it cannot be read."
          },
          "directory_ai": {
           "type": [
            "object",
            "null"
           ],
           "description": "Reads of the directory by named AI crawlers and assistants",
           "properties": {
            "definition": {
             "type": "string"
            },
            "ai_reads_7d": {
             "type": "integer"
            },
            "ai_reads_30d": {
             "type": "integer"
            }
           }
          },
          "searches": {
           "type": [
            "object",
            "null"
           ],
           "description": "Searches answered by /api/v1/search, counted server-side in the search log: rolling totals, how many found nothing, and how many came from a real browser. Null until the search log table exists, or when a count cannot be read",
           "properties": {
            "last_7d": {
             "type": "integer",
             "description": "Searches answered in the last 7 days"
            },
            "last_30d": {
             "type": "integer",
             "description": "Searches answered in the last 30 days"
            },
            "misses_7d": {
             "type": "integer",
             "description": "Searches in the last 7 days that returned no results"
            },
            "human_7d": {
             "type": "integer",
             "description": "Searches in the last 7 days from a real browser rather than an agent or tool"
            }
           }
          },
          "turnstile": {
           "type": "string",
           "description": "Health of the form check"
          },
          "mail": {
           "type": "string",
           "description": "Health of system mail"
          }
         }
        }
       }
      }
     },
     "405": {
      "$ref": "#/components/responses/MethodNotAllowed"
     },
     "503": {
      "description": "Counts are unavailable right now",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/reads": {
   "get": {
    "operationId": "getAiReads",
    "summary": "Public AI-read counts, for the directory or for one listing",
    "description": "Counts of directory pages and API answers read by named AI crawlers and assistants, one per visitor, page and day. Counts only: no user agents, no queries, nothing per visitor. Cached for two minutes.",
    "parameters": [
     {
      "name": "business",
      "in": "query",
      "required": false,
      "description": "A listing id. With it the answer is that listing's counts; without it, directory totals and 7-day breakdowns.",
      "schema": {
       "type": "string",
       "maxLength": 200
      },
      "example": "224-cafe-atlanta"
     }
    ],
    "responses": {
     "200": {
      "description": "Counts for one listing when business is given, otherwise directory totals",
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "$ref": "#/components/schemas/ListingReads"
          },
          {
           "$ref": "#/components/schemas/DirectoryReads"
          }
         ]
        }
       }
      }
     },
     "405": {
      "description": "GET only",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Counts are unavailable right now",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/cf-traffic": {
   "get": {
    "operationId": "getCloudflareTraffic",
    "summary": "Live traffic to nibiashara.com, counted by Cloudflare",
    "description": "Cloudflare's own analytics for the nibiashara.com zone, the same figures as the Cloudflare dashboard: all requests in the last 24 hours and the last hour, the last 7 complete UTC days with a daily series, and requests from named AI crawler and assistant families in the last 24 hours (from the top 1,000 user-agent groups; a floor). Counts only: no IPs, no raw user agents, nothing per visitor. Read live on every request and edge-cached for five minutes; no figure is typed by hand.",
    "responses": {
     "200": {
      "description": "Cloudflare's current figures",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/CloudflareTraffic"
        }
       }
      }
     },
     "503": {
      "description": "Cloudflare did not answer; nothing is shown in place of a real figure",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/report": {
   "get": {
    "operationId": "getAiReadReport",
    "summary": "Weekly AI-read report: this week against last week",
    "description": "The trailing 7 days compared with the 7 days before, by AI family, listing, metro and category, with a 14-day daily series. Counts only. Cached for five minutes.",
    "responses": {
     "200": {
      "description": "The report",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "as_of": {
           "type": "string",
           "format": "date-time"
          },
          "window_days": {
           "type": "integer"
          },
          "definition": {
           "type": "string"
          },
          "totals": {
           "type": "object",
           "properties": {
            "week": {
             "type": "integer"
            },
            "prev_week": {
             "type": "integer"
            },
            "wow_pct": {
             "type": [
              "number",
              "null"
             ],
             "description": "Week over week change in percent; null when last week was 0"
            },
            "daily_avg": {
             "type": "integer"
            }
           }
          },
          "daily": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "day": {
              "type": "string",
              "format": "date"
             },
             "reads": {
              "type": "integer"
             }
            }
           }
          },
          "families": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "family": {
              "type": "string"
             },
             "week": {
              "type": "integer"
             },
             "prev_week": {
              "type": "integer"
             },
             "delta": {
              "type": "integer"
             }
            }
           }
          },
          "new_families": {
           "type": "array",
           "items": {
            "type": "string"
           }
          },
          "risers": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "business": {
              "type": "string",
              "description": "Listing id"
             },
             "name": {
              "type": "string"
             },
             "url": {
              "type": "string",
              "description": "Path of the listing page"
             },
             "week": {
              "type": "integer"
             },
             "prev_week": {
              "type": "integer"
             },
             "delta": {
              "type": "integer"
             }
            }
           }
          },
          "top_listings": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "business": {
              "type": "string",
              "description": "Listing id"
             },
             "name": {
              "type": "string"
             },
             "url": {
              "type": "string",
              "description": "Path of the listing page"
             },
             "week": {
              "type": "integer"
             },
             "prev_week": {
              "type": "integer"
             },
             "delta": {
              "type": "integer"
             }
            }
           }
          },
          "metros": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "name": {
              "type": "string"
             },
             "week": {
              "type": "integer"
             },
             "prev_week": {
              "type": "integer"
             },
             "delta": {
              "type": "integer"
             }
            }
           }
          },
          "categories": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "name": {
              "type": "string"
             },
             "week": {
              "type": "integer"
             },
             "prev_week": {
              "type": "integer"
             },
             "delta": {
              "type": "integer"
             }
            }
           }
          },
          "truncated": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "405": {
      "description": "GET only",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The report is unavailable right now",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/agents/signup": {
   "post": {
    "operationId": "signUpAgentKey",
    "summary": "Sign an agent up for an API key (a person completes this)",
    "description": "Issues an API key once; only its hash is stored. The key has 0 checks a month until the emailed code is confirmed with /agents/confirm, then 3,000. One active key per email. Answers only to the form on https://nibiashara.com/agents: the request must come from that page and carry a Cloudflare Turnstile token, so a person completes it. An agent that cannot use a browser registers itself instead (securitySchemes.agentToken) and asks its person to link it.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "name",
         "contact_email",
         "consent",
         "cf-turnstile-response"
        ],
        "properties": {
         "name": {
          "type": "string",
          "description": "The agent's name",
          "maxLength": 120
         },
         "kind": {
          "type": "string",
          "enum": [
           "agent",
           "operator",
           "agency"
          ],
          "default": "agent"
         },
         "homepage": {
          "type": "string",
          "maxLength": 200
         },
         "contact_email": {
          "type": "string",
          "description": "Plain ASCII email address of the person who runs the agent; the confirmation code goes here",
          "format": "email",
          "maxLength": 200
         },
         "consent": {
          "type": "boolean",
          "description": "Must be true",
          "const": true
         },
         "cf-turnstile-response": {
          "type": "string",
          "description": "Turnstile token from the form"
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "The key, shown once",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "ok",
          "api_key",
          "account_id",
          "monthly_quota",
          "confirmation",
          "message"
         ],
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "api_key": {
           "type": "string",
           "description": "Send it as the X-API-Key header. Shown once."
          },
          "account_id": {
           "type": "string",
           "format": "uuid"
          },
          "monthly_quota": {
           "type": "integer",
           "description": "0 until the emailed code is confirmed"
          },
          "confirmation": {
           "type": "string",
           "description": "Whether the code email went out",
           "enum": [
            "code_sent",
            "pending"
           ]
          },
          "message": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "A field is missing or not valid",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Not sent from the form, the check was not completed, or access is blocked",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "405": {
      "$ref": "#/components/responses/MethodNotAllowed"
     },
     "409": {
      "description": "This email already has a key",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many sign-ups from this network today",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Sign-up is unavailable right now",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/agents/confirm": {
   "post": {
    "operationId": "confirmAgentKey",
    "summary": "Confirm the emailed code to turn the key's monthly quota on",
    "description": "The 32-character code is emailed to contact_email. It is single use, good for 24 hours, with at most 5 tries. Answers only to the form on https://nibiashara.com/agents: the request must come from that page and carry a Cloudflare Turnstile token, so a person completes it. An agent that cannot use a browser registers itself instead (securitySchemes.agentToken) and asks its person to link it.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "account_id",
         "code",
         "cf-turnstile-response"
        ],
        "properties": {
         "account_id": {
          "type": "string",
          "description": "From the sign-up answer",
          "format": "uuid"
         },
         "code": {
          "type": "string",
          "description": "The emailed code",
          "pattern": "^[0-9a-f]{32}$"
         },
         "cf-turnstile-response": {
          "type": "string",
          "description": "Turnstile token from the form"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Confirmed",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "ok",
          "status",
          "monthly_quota"
         ],
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "status": {
           "type": "string",
           "enum": [
            "confirmed"
           ]
          },
          "monthly_quota": {
           "type": "integer",
           "description": "Checks a month the key now has"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The account id or code is missing, wrong, expired, used or locked",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Not sent from the form, or the check was not completed",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "405": {
      "$ref": "#/components/responses/MethodNotAllowed"
     },
     "429": {
      "description": "Too many tries from this network today",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The code could not be checked right now",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/api": {
   "servers": [
    {
     "url": "https://nibiashara.com"
    }
   ],
   "get": {
    "operationId": "getPaidDirectoryCounts",
    "summary": "Paid directory counts by metro and category (x402)",
    "description": "Listing counts by metro and category, sold per call over x402. An unpaid call answers 402 with the terms; the amount, asset, network and pay-to address are in that answer and nowhere else. Pay with any x402 client and repeat the call with the payment header. The sale is fulfilled and settled by Ni Biashara Shelves; nibiashara.com passes the request through. No account: the wallet is the credential. Free counts stay free at /stats. The 402 answer names the resource as its seller does: resource.url is https://agents.nibiashara.biz/shelf/diaspora-metro-snapshot, not this address, because nibiashara.com only passes the call through and Shelves writes the terms, checks the payment and settles it. The 402 body and the PAYMENT-REQUIRED header come back unchanged, and on the paid repeat nibiashara.com forwards PAYMENT-SIGNATURE, X-PAYMENT and X-SHELF-PASS to that shelf and returns its answer. A client that only pays when resource.url equals the address it called should call the Shelves address directly, with the same metro and category parameters.",
    "externalDocs": {
     "description": "Ni Biashara Shelves OpenAPI (the fulfilling service)",
     "url": "https://agents.nibiashara.biz/openapi.json"
    },
    "parameters": [
     {
      "name": "metro",
      "in": "query",
      "required": false,
      "description": "Metro to filter, for example DFW, Houston or Toronto",
      "schema": {
       "type": "string",
       "maxLength": 100
      }
     },
     {
      "name": "category",
      "in": "query",
      "required": false,
      "description": "Category to filter, for example Restaurants",
      "schema": {
       "type": "string",
       "maxLength": 100
      }
     },
     {
      "name": "PAYMENT-SIGNATURE",
      "in": "header",
      "required": false,
      "description": "x402 v2 payment payload, base64. Sent on the paid repeat of the call.",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "X-PAYMENT",
      "in": "header",
      "required": false,
      "description": "x402 v1 payment payload, for older clients",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "X-SHELF-PASS",
      "in": "header",
      "required": false,
      "description": "A Ni Biashara Shelves pass, in place of a payment",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Paid: the counts",
      "headers": {
       "PAYMENT-RESPONSE": {
        "description": "x402 settlement receipt, base64 JSON",
        "schema": {
         "type": "string"
        }
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "description": "Counts only, no business-level fields. The fulfilling service defines the full shape.",
         "properties": {
          "query": {
           "type": "object"
          },
          "total_listings": {
           "type": "integer"
          },
          "by_metro": {
           "type": "array",
           "items": {
            "type": "object"
           }
          },
          "by_category": {
           "type": "array",
           "items": {
            "type": "object"
           }
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "Payment required: the x402 terms",
      "headers": {
       "PAYMENT-REQUIRED": {
        "description": "The same terms as the body, as base64 JSON (x402 v2)",
        "schema": {
         "type": "string"
        }
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PaymentRequired"
        }
       }
      }
     },
     "405": {
      "description": "GET only",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/BurstBlocked"
     },
     "502": {
      "description": "The payment service could not be reached; pay_direct names the upstream URL",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-x402": {
     "passThrough": true,
     "upstream": "https://agents.nibiashara.biz/shelf/diaspora-metro-snapshot",
     "resourceUrlInChallenge": "https://agents.nibiashara.biz/shelf/diaspora-metro-snapshot"
    }
   }
  }
 },
 "externalDocs": {
  "description": "How agents get access, limits and sign-up (auth.md)",
  "url": "https://nibiashara.com/auth.md"
 },
 "components": {
  "securitySchemes": {
   "apiKey": {
    "type": "apiKey",
    "in": "header",
    "name": "X-API-Key",
    "description": "An API key from /agents/signup, confirmed with the emailed code. 0 checks a month until it is confirmed, then 3,000. Invalid or revoked: 401. Used up: 429."
   },
   "agentToken": {
    "type": "oauth2",
    "description": "OAuth 2.0 access token (prefix nbat_, one hour) for an agent that registered itself, sent as Authorization: Bearer. The grant is RFC 7523 jwt-bearer: POST https://nibiashara.com/agent/identity with {\"type\":\"anonymous\"} returns identity_assertion; POST it to the token URL as grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer and assertion=<identity_assertion>. OpenAPI 3.1 has no flow object for this grant, so it is given as x-jwtBearer. Registering adds attribution and revocation, not volume: linking the agent to a person is what lifts the limit. Steps: https://nibiashara.com/auth.md.",
    "flows": {
     "x-jwtBearer": {
      "grantType": "urn:ietf:params:oauth:grant-type:jwt-bearer",
      "assertionUrl": "https://nibiashara.com/agent/identity",
      "tokenUrl": "https://nibiashara.com/oauth2/token",
      "refreshUrl": "https://nibiashara.com/oauth2/token",
      "scopes": {
       "directory.read": "Read the directory API"
      }
     }
    },
    "x-oauth2MetadataUrl": "https://nibiashara.com/.well-known/oauth-authorization-server"
   }
  },
  "headers": {
   "RateLimit-Policy": {
    "description": "Every limit the caller is held to, as \"name\";q=<quota>;w=<window in seconds> (IETF RateLimit header fields). Names: network (free daily limit per network), key (an API key's monthly quota), agent (a registered agent's quota), burst (short-term limit at the edge; going over it gets the caller blocked there for a time, see the BurstBlocked answer).",
    "schema": {
     "type": "string"
    },
    "example": "\"network\";q=60;w=86400, \"burst\";q=30;w=10"
   },
   "RateLimit": {
    "description": "What is left, as \"name\";r=<remaining>;t=<seconds until it resets>. No count is sent for burst. When a count could not be read it is left out and the policy still holds.",
    "schema": {
     "type": "string"
    },
    "example": "\"network\";r=41;t=21032"
   },
   "Retry-After": {
    "description": "Seconds to wait before trying again",
    "schema": {
     "type": "integer",
     "minimum": 0
    }
   },
   "Allow": {
    "description": "The methods the route takes",
    "schema": {
     "type": "string"
    },
    "example": "POST, OPTIONS"
   }
  },
  "responses": {
   "LimitReached": {
    "description": "Fair limit or quota reached. The body says which, when it resets and the ways forward. This is this API's own 429. The edge can answer 429 as well, when the burst limit is passed: that answer has a different body and no RateLimit fields, and is described in BurstBlocked (#/components/responses/BurstBlocked).",
    "headers": {
     "Retry-After": {
      "$ref": "#/components/headers/Retry-After"
     },
     "RateLimit-Policy": {
      "$ref": "#/components/headers/RateLimit-Policy"
     },
     "RateLimit": {
      "$ref": "#/components/headers/RateLimit"
     }
    },
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "NotFound": {
    "description": "No API route at that path. docs links this document.",
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "MethodNotAllowed": {
    "description": "The route exists but does not take that method. Allow, and allow in the body, list the ones it takes.",
    "headers": {
     "Allow": {
      "$ref": "#/components/headers/Allow"
     }
    },
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "BurstBlocked": {
    "description": "Blocked at the edge for going over the burst limit. The edge, in front of this API, allows 30 requests in 10 seconds per IP address, counted together across the routes it guards (among them /api/v1/search, /api/v1/verify, /api, /mcp and /a2a). Over that, it blocks the caller on those routes for 600 seconds. This answer is the edge's own (Cloudflare error 1015), not this API's: it carries no RateLimit fields and none of the links in Problem. It is an HTML page by default; ask with Accept: application/json or application/problem+json to get it as JSON. Its Retry-After may say less than the block has left: stop and wait 600 seconds.",
    "headers": {
     "Retry-After": {
      "$ref": "#/components/headers/Retry-After"
     }
    },
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/EdgeBlock"
      }
     },
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/EdgeBlock"
      }
     },
     "text/html": {
      "schema": {
       "type": "string"
      }
     }
    }
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "required": [
     "error"
    ],
    "properties": {
     "error": {
      "type": "string",
      "description": "What went wrong, in one line"
     }
    }
   },
   "Problem": {
    "type": "object",
    "description": "RFC 9457 problem details, with the links that apply.",
    "required": [
     "type",
     "title",
     "status",
     "detail"
    ],
    "properties": {
     "type": {
      "type": "string",
      "description": "Names the problem; an anchor in https://nibiashara.com/auth.md",
      "format": "uri"
     },
     "title": {
      "type": "string"
     },
     "status": {
      "type": "integer"
     },
     "detail": {
      "type": "string",
      "description": "What happened and what helps"
     },
     "error": {
      "type": "string",
      "description": "The short message older clients read"
     },
     "retry_after": {
      "type": "integer",
      "description": "Seconds to wait; the same value as Retry-After"
     },
     "limit": {
      "type": "object",
      "description": "The limit that ran out",
      "properties": {
       "policy": {
        "type": "string",
        "enum": [
         "network",
         "key",
         "agent"
        ]
       },
       "quota": {
        "type": "integer"
       },
       "window_seconds": {
        "type": "integer"
       }
      }
     },
     "allow": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "On a 405: the methods the route takes"
     },
     "signup": {
      "type": "string",
      "description": "The API key sign-up route (POST; a person completes it on https://nibiashara.com/agents)",
      "format": "uri"
     },
     "agent_identity": {
      "type": "string",
      "description": "On a 429 for a caller with no credential. The route an agent can call by itself to register: POST the JSON body {\"type\":\"anonymous\"}, with no captcha, no email and no form. Registering alone adds attribution, not volume; the limit rises once a person links the agent (see docs).",
      "format": "uri"
     },
     "confirm": {
      "type": "string",
      "description": "The route that confirms an emailed code, for a key that is not confirmed yet",
      "format": "uri"
     },
     "link_a_person": {
      "type": "string",
      "description": "The route that links a registered agent to a person",
      "format": "uri"
     },
     "docs": {
      "type": "string",
      "format": "uri",
      "description": "Where to read next: the section of auth.md on getting a higher limit, or this document for a 404 or 405"
     },
     "paid": {
      "type": "string",
      "description": "The paid directory counts (x402). A link only: the price is in its 402 answer.",
      "format": "uri"
     }
    }
   },
   "License": {
    "type": "object",
    "description": "CC BY 4.0 covers what Ni Biashara wrote (curation, categories, hubs, data structure). Business facts are compiled from public sources and are not licensed by Ni Biashara.",
    "properties": {
     "name": {
      "type": "string"
     },
     "url": {
      "type": "string",
      "format": "uri"
     },
     "attribution": {
      "type": "string"
     },
     "scope": {
      "type": "string"
     },
     "not_licensed": {
      "type": "string"
     }
    }
   },
   "Listing": {
    "type": "object",
    "description": "One published listing. Facts are compiled from public sources.",
    "required": [
     "id",
     "name"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "Stable id, used in /b/<id>/ and /businesses/<id>.json"
     },
     "name": {
      "type": "string"
     },
     "category": {
      "type": "string"
     },
     "metro": {
      "type": "string"
     },
     "city": {
      "type": "string"
     },
     "country": {
      "type": "string",
      "description": "Present on listings added after the static catalog"
     },
     "website": {
      "type": "string"
     },
     "facebook": {
      "type": "string"
     },
     "instagram": {
      "type": "string"
     },
     "phone": {
      "type": "string"
     },
     "blurb": {
      "type": "string",
      "description": "One or two lines about the business"
     },
     "badge": {
      "type": "string",
      "description": "Present when the listing has a status",
      "enum": [
       "found",
       "claimed",
       "verified"
      ]
     },
     "claim_open": {
      "type": "boolean",
      "description": "Whether the owner can still claim this listing: true until it is claimed or verified. Worked out at request time, the same way on every route."
     },
     "claim_url": {
      "type": [
       "string",
       "null"
      ],
      "format": "uri",
      "description": "On search results (and over MCP and A2A): the page where the owner claims the listing, free. null when the listing is not open to a claim. The bulk catalog and the detail route carry claim_open only."
     },
     "page": {
      "type": "string",
      "description": "The listing page",
      "format": "uri"
     },
     "api": {
      "type": "string",
      "description": "This listing as JSON",
      "format": "uri"
     },
     "source": {
      "type": "string",
      "description": "added on listings added after the static catalog"
     },
     "added_at": {
      "type": "string",
      "description": "When an added listing was published"
     }
    }
   },
   "ListingReads": {
    "type": "object",
    "required": [
     "business"
    ],
    "properties": {
     "business": {
      "type": "string",
      "description": "Listing id"
     },
     "ai_reads_7d": {
      "type": [
       "integer",
       "null"
      ]
     },
     "ai_reads_30d": {
      "type": [
       "integer",
       "null"
      ]
     },
     "definition": {
      "type": "string"
     }
    }
   },
   "DirectoryReads": {
    "type": "object",
    "required": [
     "as_of",
     "window_days"
    ],
    "properties": {
     "as_of": {
      "type": "string",
      "format": "date-time"
     },
     "window_days": {
      "type": "integer"
     },
     "definition": {
      "type": "string"
     },
     "ai_families": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "The AI crawlers and assistants that are counted"
     },
     "ai_reads_7d": {
      "type": "integer"
     },
     "ai_reads_30d": {
      "type": "integer"
     },
     "by_family": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "family": {
         "type": "string"
        },
        "reads": {
         "type": "integer"
        }
       }
      }
     },
     "top_listings": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "business": {
         "type": "string",
         "description": "Listing id"
        },
        "name": {
         "type": "string"
        },
        "reads": {
         "type": "integer"
        },
        "url": {
         "type": "string",
         "description": "Path of the listing page"
        }
       }
      }
     },
     "top_metros": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "name": {
         "type": "string"
        },
        "reads": {
         "type": "integer"
        }
       }
      }
     },
     "top_categories": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "name": {
         "type": "string"
        },
        "reads": {
         "type": "integer"
        }
       }
      }
     },
     "truncated": {
      "type": "boolean"
     }
    }
   },
   "PaymentRequired": {
    "type": "object",
    "description": "x402 v2 payment terms. Read the amount from accepts; no price is written in this document.",
    "required": [
     "x402Version",
     "accepts"
    ],
    "properties": {
     "x402Version": {
      "type": "integer",
      "description": "2"
     },
     "error": {
      "type": "string"
     },
     "sku": {
      "type": "string",
      "description": "The Shelves shelf that fulfils the call"
     },
     "description": {
      "type": "string"
     },
     "resource": {
      "type": "object",
      "description": "The resource being sold",
      "properties": {
       "url": {
        "type": "string",
        "format": "uri",
        "description": "The resource as its seller names it. For GET https://nibiashara.com/api this is https://agents.nibiashara.biz/shelf/diaspora-metro-snapshot, the Shelves shelf the call is passed through to."
       },
       "description": {
        "type": "string"
       },
       "mimeType": {
        "type": "string"
       },
       "serviceName": {
        "type": "string"
       }
      }
     },
     "accepts": {
      "type": "array",
      "description": "Ways to pay",
      "items": {
       "type": "object",
       "required": [
        "scheme",
        "network",
        "amount",
        "asset",
        "payTo"
       ],
       "properties": {
        "scheme": {
         "type": "string"
        },
        "network": {
         "type": "string",
         "description": "CAIP-2 network id"
        },
        "amount": {
         "type": "string",
         "description": "Price in the smallest unit of the asset"
        },
        "asset": {
         "type": "string",
         "description": "Token contract address"
        },
        "payTo": {
         "type": "string",
         "description": "Receiving address"
        },
        "maxTimeoutSeconds": {
         "type": "integer"
        },
        "extra": {
         "type": "object"
        }
       }
      }
     },
     "extensions": {
      "type": "object",
      "description": "x402 extensions, such as the Bazaar input and output description"
     }
    }
   },
   "Links": {
    "type": "object",
    "description": "Where to go from here. Addresses only.",
    "required": [
     "signup",
     "agent_identity",
     "docs",
     "ai_reads",
     "paid_snapshot"
    ],
    "properties": {
     "signup": {
      "type": "string",
      "format": "uri",
      "description": "The API key sign-up route (POST; a person completes it on https://nibiashara.com/agents)"
     },
     "agent_identity": {
      "type": "string",
      "format": "uri",
      "description": "The route an agent can call by itself to register: POST the JSON body {\"type\":\"anonymous\"}, with no captcha, no email and no form. Registering alone adds attribution, not volume; the limit rises once a person links the agent (see docs)."
     },
     "docs": {
      "type": "string",
      "format": "uri",
      "description": "The section of auth.md on getting a higher limit"
     },
     "ai_reads": {
      "type": "string",
      "format": "uri",
      "description": "AI-read counts for the first match or result (/reads?business=<id>); swap the id for any other listing. With no match, the directory-wide counts."
     },
     "paid_snapshot": {
      "type": "string",
      "format": "uri",
      "description": "The paid directory counts (x402). A link only: the price is in its 402 answer."
     }
    }
   },
   "EdgeBlock": {
    "type": "object",
    "description": "The edge's own problem document for a burst block (Cloudflare error 1015), sent when the caller asks for JSON. The members are Cloudflare's, not this API's, and may change; the RFC 9457 base members are listed here. There is no signup, docs or paid link in it.",
    "properties": {
     "type": {
      "type": "string",
      "description": "A Cloudflare documentation address, not an anchor in auth.md"
     },
     "title": {
      "type": "string"
     },
     "status": {
      "type": "integer"
     },
     "detail": {
      "type": "string"
     },
     "retry_after": {
      "type": "integer",
      "description": "Seconds, as the edge states them. It may be less than the block has left."
     }
    }
   },
   "CloudflareTraffic": {
    "type": "object",
    "properties": {
     "version": {
      "type": "string",
      "example": "v1"
     },
     "as_of": {
      "type": "string",
      "format": "date-time"
     },
     "zone": {
      "type": "string",
      "example": "nibiashara.com"
     },
     "window_hours": {
      "type": "integer",
      "example": 24
     },
     "requests_24h": {
      "type": "integer",
      "description": "All requests to the zone in the last 24 hours, adaptive sampling"
     },
     "requests_1h": {
      "type": "integer",
      "description": "The last 60 minutes of that"
     },
     "requests_7d": {
      "type": "integer",
      "description": "The last 7 complete UTC days, daily rollup"
     },
     "by_day": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "date": {
         "type": "string",
         "format": "date"
        },
        "requests": {
         "type": "integer"
        }
       }
      }
     },
     "mcp_calls_24h": {
      "type": "integer",
      "description": "Successful tool calls to /mcp in the last 24 hours: POST requests answered 200 or 202. Refused requests and liveness probes are not counted."
     },
     "api_calls_24h": {
      "type": "integer",
      "description": "Requests to /api/v1/* in the last 24 hours"
     },
     "agent_file_reads_24h": {
      "type": "integer",
      "description": "Reads of the agent discovery files (A2A card, llms.txt, server card) in the last 24 hours"
     },
     "agent_requests_24h": {
      "type": "integer",
      "description": "Successful MCP calls plus all requests to /api/v1/* and the agent discovery files in the last 24 hours, including the site's own feed reads"
     },
     "ai_agents_24h_total": {
      "type": "integer"
     },
     "ai_agents_24h": {
      "type": "object",
      "additionalProperties": {
       "type": "integer"
      },
      "description": "Requests by named AI crawler or assistant family, last 24 hours"
     },
     "source": {
      "type": "string"
     },
     "refresh": {
      "type": "string"
     }
    },
    "required": [
     "as_of",
     "requests_24h"
    ]
   }
  }
 }
}
