Skip to content
Blog

Enterprise REST API Integration: Auto-Generating Tools from OpenAPI Specs

Turn an OpenAPI 3.x document into callable ADK tools with OpenAPIToolset — how names and schemas are derived, how auth and headers are applied, and when to curate instead.

Published on • November 28, 2026

AI Assistant

An enterprise API spec is already a complete description of a tool surface: endpoints, parameters, types, enums, and prose descriptions written by the people who own the API. Hand-transcribing that into FunctionTools means a second, decaying copy of the same contract. ADK’s OpenAPI integration closes the loop — point OpenAPIToolset at your spec and every operation becomes a RestApiTool the model can call, with the HTTP plumbing generated rather than written.

This tutorial covers how the toolset parses a spec, exactly how tool names and descriptions are derived (and why operationId matters more than you think), how authentication and headers flow to every generated tool, and the curation decisions that keep the tool list usable.

The two classes you need

from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_toolset import OpenAPIToolset

toolset = OpenAPIToolset(spec_str=openapi_spec_json, spec_str_type="json")
  • OpenAPIToolset — parses the spec (resolving internal $refs), discovers every GET/POST/PUT/DELETE operation under paths, and generates one tool per operation.
  • RestApiTool — a single generated tool. It holds the HTTP method, path, server base URL, parameter locations (path, query, header, cookie) and request-body schema, builds the request from the model’s arguments, executes it asynchronously with httpx, and returns the response.

The spec can be supplied as a Python dict (spec_dict=), or as a string (spec_str= plus spec_str_type='json' | 'yaml'). Attaching it to an agent is the same as attaching functions:

from google.adk.agents import LlmAgent

agent = LlmAgent(
    name="billing_agent",
    model="gemini-flash-latest",
    instruction="Use the billing API tools to answer questions about invoices.",
    tools=[toolset],
)

How names and descriptions are derived

This is where generated tools succeed or fail, because these strings are the schema the model reads:

Spec elementBecomesConsequence if missing
operationIdTool name, converted to snake_case, capped at 60 charsName generated from method + path — often generic
summaryPrimary tool descriptionFalls back to description, then silence
descriptionTool description (when no summary)Model guesses intent from the name alone
Parameter descriptionsArgument descriptions in the schemaModel guesses formats and enums
servers[].urlBase URL for every requestCalls go to the wrong environment

Practical rules:

  • Write operationId for every operation in your spec. listInvoices, createRefund — snake-cased, they become list_invoices, create_refund. Without them you get names derived from the path, which the model matches on poorly.
  • summary is a tool description, so write it as one: “List invoices for a customer, newest first” beats “Invoices endpoint”.
  • Check for collisions across specs. Two APIs can both define list_items. Use tool_name_prefix (ADK v2.0.0+) to namespace: toolset = OpenAPIToolset(spec_dict=..., tool_name_prefix="billing") → billing_list_invoices.

Authentication, headers, and SSL

Configure auth once at the toolset level; every generated RestApiTool inherits it:

toolset = OpenAPIToolset(
    spec_dict=openapi_spec,
    auth_scheme="api_key",          # or an OAuth scheme
    auth_credential=os.environ["BILLING_API_KEY"],
)

For per-request values — correlation IDs, a user’s token from session state — pass a header_provider callable that receives a ReadonlyContext and returns headers (ADK v2.0.0+):

from google.adk.agents.readonly_context import ReadonlyContext

def request_headers(context: ReadonlyContext) -> dict[str, str]:
    return {
        "X-Request-ID": context.invocation_id,
        "X-User-ID": context.user_id,
    }

toolset = OpenAPIToolset(spec_dict=openapi_spec, header_provider=request_headers)

ssl_verify accepts a CA bundle path, True/False, or an ssl.SSLContext. Prefer a CA bundle for internal APIs with a private certificate authority — ssl_verify=False disables verification entirely and exposes the request to interception.

Note the difference from MCP: here credentials are configured against your API spec, whereas MCP toolsets receive tools whose auth the server dictates.

Generated tool vs hand-written tool vs MCP server

DimensionOpenAPIToolsetHand-written FunctionToolMCP server wrapping the API
Setup costZero per endpointOne function per endpointServer + client config
Schema freshnessFollows the spec fileFollows your codeFollows the server
Request shaping (validation, enrichment, batching)None — spec in, call outFull controlFull control
Auth modelauth_scheme + auth_credential per toolsetWhatever you codeServer-managed, incl. OAuth flows
Reuse across agents/languagesSame spec, any ADK agentPython onlyAny MCP client
Best forBroad, CRUD-shaped internal APIsLogic-heavy or multi-step operationsThird-party or cross-team tool surfaces

A useful default: generate everything, then wrap the few that matter. Operations that need validation, cross-field checks, or error shaping deserve a real function; the other forty endpoints are fine as generated tools. If the API is owned by another team and exposed as an MCP server already, prefer that — see generating MCP servers from OpenAPI.

What happens on a call

When the model invokes list_invoices(customer_id="C-9"), the RestApiTool builds the URL, places arguments into their declared locations, attaches auth and custom headers, and executes with httpx (default 600-second read/write timeout, overridable via httpx_client_factory). A non-2xx or transport failure becomes a result handed back to the model — so the quality of that error text decides whether the model retries correctly or apologizes twice.

Because the execution is I/O-bound and async, several generated tools can run in parallel within a turn; the docs call this out as the performance path worth designing for.

Instruction and rollout checklist

  • List the generated tool names in the agent instruction — especially the near-miss pairs (list_invoices vs get_invoice). The instruction tells the model when; the generated schema tells it how.
  • Pin the spec in version control and regenerate expectations in CI: assert tool count, required-parameter lists, and a couple of operationId→name conversions. A spec edit silently changes your model’s tool surface.
  • Keep the spec’s servers pointed at the right environment. Staging specs in production agents is a real and painful failure mode.
  • Sanitize upstream error bodies before they reach the model — this is the same exfiltration surface as any other tool error.

Takeaways

  • OpenAPIToolset parses an OpenAPI 3.x spec and emits one RestApiTool per operation; the agent accepts the toolset in tools exactly like a function.
  • operationId → snake_case name (60 chars max) and summary → description: write both deliberately, they are your schema.
  • Auth configured at the toolset is inherited by every tool; header_provider adds per-request context-derived headers (ADK v2.0.0+).
  • Generate the breadth of the API, hand-write the endpoints that need validation or curated error contracts.
  • Treat the spec as a prompt-surface artifact: version it, assert against it, and diff tool declarations in CI.

Further reading