| name | google-adk-openapi-tool |
| description | Create ADK tools from OpenAPI specs. Use when connecting agents to REST APIs defined by OpenAPI/Swagger specs — auto-generates tools from endpoints with auth support. |
Google ADK — OpenAPI Tool Integration
Import
from google.adk.tools.openapi_tool.openapi_toolset import OpenAPIToolset
Basic Usage (from spec file)
from google.adk.agents import Agent
from google.adk.tools.openapi_tool.openapi_toolset import OpenAPIToolset
toolset = OpenAPIToolset(
spec_str=open("openapi.yaml").read(),
spec_str_type="yaml",
)
root_agent = Agent(
name="api_agent",
model="gemini-2.5-flash",
instruction="Use the API to help users manage their resources.",
tools=[toolset],
)
From JSON Spec
import json
with open("api_spec.json") as f:
spec = json.dumps(json.load(f))
toolset = OpenAPIToolset(
spec_str=spec,
spec_str_type="json",
)
With Authentication (API Key)
from google.adk.tools.openapi_tool.openapi_toolset import OpenAPIToolset
from google.adk.auth.auth_credential import AuthCredential, AuthCredentialTypes
api_key_credential = AuthCredential(
auth_type=AuthCredentialTypes.API_KEY,
api_key="your-api-key",
)
toolset = OpenAPIToolset(
spec_str=open("spec.yaml").read(),
spec_str_type="yaml",
auth_credential=api_key_credential,
)
With Bearer Token Auth
from google.adk.auth.auth_credential import AuthCredential, AuthCredentialTypes, HttpAuth, HttpCredentials
bearer_credential = AuthCredential(
auth_type=AuthCredentialTypes.HTTP,
http=HttpAuth(
scheme="bearer",
credentials=HttpCredentials(token="your-bearer-token"),
),
)
toolset = OpenAPIToolset(
spec_str=open("spec.yaml").read(),
spec_str_type="yaml",
auth_credential=bearer_credential,
)
Tool Filtering
toolset = OpenAPIToolset(
spec_str=open("spec.yaml").read(),
spec_str_type="yaml",
tool_filter=["getUsers", "createUser", "deleteUser"],
)
OpenAPIToolset Parameters
| Parameter | Type | Description |
|---|
spec_str | str | OpenAPI spec content as string |
spec_str_type | str | "yaml" or "json" |
auth_credential | AuthCredential | Authentication credentials |
tool_filter | list[str] | Operation IDs to include |
How It Works
- Parses the OpenAPI spec
- Creates one tool per operation (operationId becomes tool name)
- Parameters/request body become tool parameters
- Tool descriptions come from operation
summary and description
- Authentication is applied to all requests
OpenAPI Spec Requirements
- Must have
operationId for each endpoint (becomes the tool function name)
- Parameters need
description fields (becomes tool parameter descriptions)
- Request body schemas define the tool's input structure
Example Spec (Minimal)
openapi: "3.0.0"
info:
title: "Task API"
version: "1.0.0"
servers:
- url: "https://api.example.com/v1"
paths:
/tasks:
get:
operationId: listTasks
summary: "List all tasks"
responses:
"200":
description: "List of tasks"
post:
operationId: createTask
summary: "Create a new task"
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
title:
type: string
description: "Task title"
priority:
type: string
enum: [low, medium, high]
description: "Task priority level"
Key Rules
- Each operation in the spec becomes a separate tool
operationId is required and becomes the tool name the LLM sees
- Tool descriptions come from
summary + description fields
- Keep spec descriptions clear and actionable for the LLM
- Filter tools to only expose what the agent needs
- Authentication is applied globally to all tools from the same spec
Related Skills
google-adk-auth — Authentication credentials, schemes, and credential services
google-adk-function-tool — Custom function tools
google-adk-mcp-tool — MCP server integration