discover_api
Search and retrieve L402-enabled APIs with detailed endpoint information and pricing. Filter by category or keyword, and view affordable call counts based on your budget.
Instructions
Discover L402-enabled APIs. Use 'query' to search the registry for available APIs by keyword, or use 'url' to fetch a specific API's manifest with full endpoint details and pricing. Use 'category' to browse by category. With budget_aware=true, shows how many calls you can afford.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | No | Base URL of the L402-enabled API, or direct URL to the manifest JSON file. If omitted, searches the registry instead. | |
| query | No | Search the L402 API registry by keyword (e.g., 'weather', 'ai', 'geocoding'). | |
| category | No | Filter registry results by category (e.g., 'ai', 'data', 'finance'). | |
| budget_aware | No | If true, annotate endpoints with affordable call counts based on remaining budget. Default: true. |
Implementation Reference
- The `discover_api` function is the main handler for the discover_api tool. It routes requests either to search the registry or to fetch a specific API manifest.
async def discover_api( url: str | None = None, query: str | None = None, category: str | None = None, budget_aware: bool = True, budget_service: "BudgetService | None" = None, ) -> str: """ Discover L402-enabled APIs. Use 'query' to search the registry for available APIs by keyword, or use 'url' to fetch a specific API's manifest with full endpoint details and pricing. Use 'category' to browse by category. With budget_aware=True, shows how many calls you can afford. Args: url: Base URL of the L402-enabled API, or direct URL to the manifest JSON file query: Search the L402 API registry by keyword (e.g., 'weather', 'ai', 'geocoding') category: Filter registry results by category (e.g., 'ai', 'data', 'finance') budget_aware: If True, annotate endpoints with affordable call counts. Default: True budget_service: BudgetService for budget annotations Returns: JSON with discovered APIs or manifest details """ if httpx is None: return json.dumps({ "success": False, "error": "httpx is required for discover_api. Install with: pip install httpx" }) try: # Route: URL provided -> fetch manifest if url and url.strip(): return await _fetch_and_format_manifest( url.strip(), budget_aware, budget_service ) # Route: query/category provided -> search registry if (query and query.strip()) or (category and category.strip()): return await _search_registry( query, category, budget_aware, budget_service ) # No params -> usage error return json.dumps({ "success": False, "error": "Please provide either a 'url' to fetch an API manifest, or a 'query'/'category' to search the registry.", "examples": [ {"description": "Search for weather APIs", "call": 'discover_api(query="weather")'}, {"description": "Browse AI category", "call": 'discover_api(category="ai")'}, {"description": "Get full details for a specific API", "call": 'discover_api(url="https://api.example.com")'}, ] }, indent=2) except Exception as e: return json.dumps({ "success": False, "error": f"Error discovering API: {sanitize_error(str(e))}" })