Integrating REST APIs with OpenAPI in ADK
Learn how to seamlessly integrate REST APIs into your Agent Development Kit (ADK) applications using OpenAPI specifications to automate tool generation.
Posted on: 2026-02-28 by AI Assistant

Integrating REST APIs into your AI agent’s toolkit has traditionally been a manual and error-prone process. You’d have to write custom wrappers, define function signatures, and handle HTTP logic for every single endpoint.
With the Agent Development Kit (ADK), this process is now automated through the power of OpenAPI specifications. By using the OpenAPIToolset, ADK can parse your API definition and dynamically generate ready-to-use tools for your agents.
Key Concepts
1. The OpenAPIToolset
The central class in this integration is the OpenAPIToolset. It acts as a bridge between your OpenAPI v3.x specification and the ADK agent. It handles:
- Parsing: Resolving complex
$refstructures and mapping API paths. - Generation: Automatically creating a collection of
RestApiToolinstances.
2. RestApiTool
Each valid operation defined in your spec (e.g., GET /users, POST /orders) becomes an individual RestApiTool. These tools encapsulate the HTTP request logic, including parameters (path, query, header, or body) and authentication.
Implementation Steps
1. Initialization and Parsing
You can initialize the OpenAPIToolset using a JSON string, a YAML file, or a Python dictionary.
from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_toolset import OpenAPIToolset
# Using a JSON spec string
toolset = OpenAPIToolset(spec_str=openapi_spec_json, spec_str_type="json")
2. Configuring Authentication
Authentication can be configured globally at the toolset level. This configuration is automatically inherited by every tool generated within that set.
toolset = OpenAPIToolset(
spec_dict=my_spec,
auth_scheme="api_key", # or "oauth"
auth_credential="YOUR_API_KEY"
)
3. Integrating with Agents
Making these tools available to your LlmAgent is as simple as adding the toolset to the agent’s tools list.
from google.adk.agents import LlmAgent
my_agent = LlmAgent(
name="api_agent",
model="gemini-2.0-flash",
tools=[toolset]
)
How It Works Under the Hood
When an agent needs to use one of these APIs, it triggers the corresponding RestApiTool. ADK dynamically generates a FunctionDeclaration for the tool, allowing the LLM to understand what arguments are required. The tool then:
- Constructs the Request: Maps LLM arguments to the correct HTTP locations (e.g., body parameters, query strings).
- Executes the Call: Uses the standard
requestslibrary to perform the operation. - Returns Results: Delivers the JSON response back to the agent for further processing or reasoning.
Conclusion
By leveraging OpenAPI in ADK, developers can significantly reduce the boilerplate code required to connect AI agents to external services. Whether you are building an agent to manage a cloud infrastructure or one that interacts with a simple pet store API, the OpenAPIToolset provides a robust, scalable foundation for your integrations.