OpenAPI to AI Function Calling

Convert OpenAPI/Swagger specs into AI function calling definitions for any provider

~/openapi-to-functions

Paste an OpenAPI/Swagger spec to generate AI function calling definitions.

Supports OpenAPI 3.0+ JSON. Each endpoint becomes a function definition.

What is an OpenAPI to AI Function Calling Converter?

An OpenAPI to AI function calling converter transforms your existing REST API specifications into the structured tool definitions that large language models need for function calling. If you have an OpenAPI (Swagger) spec describing your API endpoints, this tool extracts the relevant information — operation names, descriptions, parameters, and request body schemas — and reformats it into the JSON structure that AI providers like OpenAI, Anthropic, and Google require.

Function calling (also known as tool use) is one of the most powerful features of modern AI models. It allows models to invoke external functions with structured arguments, enabling AI agents to interact with APIs, databases, and external services. However, writing tool definitions by hand is tedious and error-prone — especially when you already have a complete API specification that describes the same information in OpenAPI format.

Our free converter eliminates this duplicate work. Paste your OpenAPI spec, select which endpoints to convert, and get properly formatted function definitions for any AI provider. All processing runs in your browser — your API specification never leaves your machine.

How to Use This Converter

Converting your OpenAPI spec to function definitions is straightforward:

  1. Paste your OpenAPI specification — Copy your OpenAPI 3.x or Swagger 2.0 spec in JSON or YAML format. The tool accepts complete specs or partial specs containing just the paths and components you need.
  2. Select endpoints to convert — The tool lists all discovered endpoints with their HTTP methods, paths, and descriptions. Select the ones you want to expose as AI-callable functions. Not every endpoint is suitable for function calling — focus on endpoints with clear purposes and well-defined parameters.
  3. Choose your target format — Select OpenAI, Anthropic, Google Gemini, or all three. Each provider has slightly different format requirements that the converter handles automatically.
  4. Review and customize — The generated definitions include function names derived from operationId or path, descriptions from the spec summary, and parameter schemas from the request body and query parameters. Review and adjust descriptions for optimal model understanding.
  5. Copy and integrate — Copy the generated JSON and add it to your AI integration code. The output is ready to use with each provider's SDK or API directly.

Understanding OpenAPI to Function Calling Mapping

The conversion from OpenAPI to function definitions involves several important mapping decisions:

Function Naming

The function name is derived from the `operationId` field in your OpenAPI spec. If no operationId is present, the tool generates a name from the HTTP method and path (e.g., `GET /users/{id}` becomes `get_user_by_id`). Good operationIds in your spec lead to better function names that models can understand.

Parameter Extraction

Parameters are collected from three sources: path parameters (e.g., `/users/{id}`), query parameters, and the request body schema. All are merged into a single flat parameter object for the function definition, since AI function calling does not distinguish between parameter locations. Required path parameters are automatically marked as required in the generated schema.

Schema Resolution

OpenAPI specs frequently use `$ref` to reference shared schema definitions in the components section. AI function calling formats do not support references — all schemas must be self-contained. The converter resolves all references by inlining the referenced schema, handling nested references recursively. Circular references are detected and broken with a depth limit to prevent infinite expansion.

Description Enhancement

Good function descriptions are critical for AI models to understand when and how to call each function. The converter uses the OpenAPI `summary` and `description` fields, combining them into a clear, concise description. Parameter descriptions from the spec are preserved to help the model generate correct argument values.

Common Patterns and Best Practices

When converting OpenAPI specs to function calling definitions, these patterns produce the best results:

  • Select endpoints strategically — Not every API endpoint should be a function. Focus on endpoints that represent distinct, useful actions. Avoid exposing low-level CRUD operations when higher-level business operations are available.
  • Use meaningful operationIds — operationIds like `searchProducts` produce better function names than auto-generated ones like `get_api_v1_products`.
  • Write clear descriptions — The model relies heavily on function and parameter descriptions to decide which function to call and what arguments to pass. Vague descriptions lead to incorrect function calls.
  • Simplify complex schemas — If your request body has 20+ fields with deep nesting, consider exposing a simplified version with only the most commonly used fields. Complex schemas confuse models and lead to errors.
  • Test with real prompts — After generating function definitions, test them with actual user prompts to verify the model selects the right function and generates valid arguments.

Frequently Asked Questions

What is OpenAPI and how does it relate to AI function calling?

OpenAPI (formerly Swagger) is a standard specification for describing REST APIs. It defines endpoints, parameters, request/response schemas, and authentication methods in a machine-readable JSON or YAML format. AI function calling requires similar structured definitions — name, description, and parameter schemas. This tool bridges the gap by extracting endpoint information from your OpenAPI spec and converting it into the tool/function definition format that AI models expect.

Which OpenAPI specification versions are supported?

This tool supports OpenAPI 3.0.x and 3.1.x specifications, as well as Swagger 2.0 (which is auto-converted to OpenAPI 3.0 format internally). Both JSON and YAML input formats are accepted. If your spec uses features specific to 3.1 (like JSON Schema 2020-12 compatibility), those are handled correctly. For best results, ensure your spec is valid — use the official Swagger Editor to validate first if you encounter issues.

How does the tool handle nested schemas and $ref references?

The converter fully resolves $ref references by inlining referenced schemas into the function definition. This is necessary because AI function calling formats (especially Google Gemini) do not support $ref. Nested objects are preserved up to a reasonable depth, and circular references are detected and broken to prevent infinite loops. Complex composition keywords (allOf, oneOf, anyOf) are simplified into flat schemas where possible.

What output formats are available for the generated functions?

The tool generates function definitions in three formats: OpenAI function calling (with the { type: "function", function: {...} } wrapper), Anthropic tool use (with input_schema), and Google Gemini function declarations (with parameters). You can generate all three simultaneously or select a specific target format. Each output is valid JSON ready to paste into your API requests.

Related Tools

Explore more tools for building AI function calling integrations:

Related Tools