FR - Dynamic 'Operation' selection for OpenAPI Resources

I was looking to add an API as a tool for an Agent. Originally, I was just going to give the OpenAPI Schema to a model along with my user input and have the model sort out which API endpoint to use..... an API Triage Agent of sorts i guess and my options were to either add each endpoint as a separate tool, or 1 tool with an input used as the 'Operation' parameter in the resource query:

Could you go in more depth in your use case? Parameters for each operation can be very different, so it's a little unclear how dynamic operations would work?

I just mean how the Operation dropdown is auto-populated, if I could use a string to either select the proper Operation or error on no match then I can 1 block that's able to send to any endpoint.... kinda like using the 'default value' parameter:

I actually solved this by giving an Agent the web search tool, the url for the API docs and a generalized 'task' description of what I want to do. I can then tell it to find the appropriate endpoint, build the request url(w body data if needed), then I just have to fill in my API key so I can manually send the request w python.... the only other option I could think of was to have a big if/else block to route the workflow to each separate block/endpoint (without using code blocks)

hopefully I didn't make that confusing =/

COINGECKO_API_PROMPT = ("You search the Coingecko API documentation for information about the API endpoints, parameters, and usage to find the best endpoint to use for the user's request. Return only the relevant information about the API endpoint.")


COINGECKO_API_PLANNER_PROMPT = (
    "You are a Coingecko API planning specialist. Given a user query and the Coingecko API documentation, "
    "create an ordered sequence of API calls to accomplish the user's request.\n\n"
    "Return your response in the following structured format:\n\n"
    "EXPLANATION: [Overall explanation of the API call sequence]\n\n"
    "ENDPOINTS:\n"
    "1. METHOD: [GET/POST/etc] URL: [complete URL] DESCRIPTION: [what this accomplishes] HEADERS: [any required headers] BODY: [request body if needed]\n"
    "2. METHOD: [GET/POST/etc] URL: [complete URL] DESCRIPTION: [what this accomplishes] HEADERS: [any required headers] BODY: [request body if needed]\n"
    "...\n\n"
    "Base URL: https://api.coingecko.com/api/v3\n\n"
    "Examples:\n"
    "- 'Get Bitcoin price' → Single call to /simple/price\n"
    "- 'Get Bitcoin historical data for last 30 days' → Call to /coins/bitcoin/market_chart\n"
    "- 'Find trending coins and their prices' → First call /trending, then /simple/price with trending coin IDs\n\n"
    "Always order calls logically - if one call depends on data from another, put the dependency first."
)


class ApiEndpoint(BaseModel):
    url: str
    """The complete URL endpoint to call"""
    
    method: str
    """HTTP method (GET, POST, PUT, DELETE)"""
    
    headers: Dict[str, str] = {}
    """Headers to include in the request"""
    
    body: Dict[str, Any] = {}
    """Body data for POST/PUT requests"""
    
    description: str
    """Description of what this endpoint call accomplishes"""
    
    order: int
    """The order in which this endpoint should be called (1, 2, 3, etc.)"""


class ApiPlan(BaseModel):
    endpoints: List[ApiEndpoint]
    """Ordered list of API endpoints to call"""
    
    explanation: str
    """Overall explanation of the API call sequence"""


coingecko_api_agent = Agent(
    name="CoingeckoAPI",
    instructions=COINGECKO_API_PROMPT,
    tools=[get_coingecko_api_docs],
    model=config.DEFAULT_MODEL
)


coingecko_api_planner_agent = Agent(
    name="CoingeckoAPIPlanner",
    instructions=COINGECKO_API_PLANNER_PROMPT,
    tools=[get_coingecko_api_docs],
    model=config.DEFAULT_MODEL
)


class CryptocurrencyManager:
    def __init__(self):
        self.console = Console()
        self.printer = Printer(self.console)

    async def run(self, query: str) -> str:
        """Run the cryptocurrency data retrieval process for a given query"""
        try:
            trace_id = gen_trace_id()
            with trace("Cryptocurrency trace", trace_id=trace_id):
                self.printer.update_item(
                    "trace_id",
                    f"View trace: https://platform.openai.com/traces/trace?trace_id={trace_id}",
                    is_done=True,
                    hide_checkmark=True,
                )

                self.printer.update_item(
                    "starting",
                    f"Starting cryptocurrency data retrieval for: '{query}'",
                    is_done=True,
                    hide_checkmark=True,
                )

                # Use agent to retrieve coingecko API docs and find the best endpoint for the query                self.printer.update_item("retrieving", "Retrieving cryptocurrency API data...")
                coingecko_api_docs_url = "https://docs.coingecko.com/v3.0.1/reference/endpoint-overview"
                api_request = await Runner.run(coingecko_api_agent, "API Docs URL: " + coingecko_api_docs_url + "\n\n" + "Query: " + query)
                self.printer.update_item("api_docs", "Retrieved API docs successfully", is_done=True)
                self.printer.update_item("retrieving", "Performing retrieval: " + api_request.final_output + "\n...")
                api_result = await fetch_data(api_request.final_output.endpoint, headers={'x-cg-demo-api-key': config.COINGECKO_API_KEY})
                
                # Perform cryptocurrency data retrieval with API results
                context_input = f"API Data: {api_result}\n\nUser Query: {query}"
                result = await Runner.run(cryptocurrency_agent, context_input)
                final_output = result.final_output
                
                self.printer.update_item("report", final_output, is_done=True)
                    
                self.printer.end()
                
            print("\n\n=====CRYPTOCURRENCY REPORT=====\n\n")
            print(f"Report: {final_output}")
            
            return final_output
            
        except Exception as e:
            self.printer.end()
            print(f"❌ Error during cryptocurrency data retrieval: {e}")
            raise

^^ works like a charm =). feel free to use it and change for ur api needs