Skip to main content
Glama

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
NameRequiredDescriptionDefault
urlNoBase URL of the L402-enabled API, or direct URL to the manifest JSON file. If omitted, searches the registry instead.
queryNoSearch the L402 API registry by keyword (e.g., 'weather', 'ai', 'geocoding').
categoryNoFilter registry results by category (e.g., 'ai', 'data', 'finance').
budget_awareNoIf 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))}"
            })

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/refined-element/lightning-enable-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server