# OpenAPI to Agent Tools Converter (`n4d.h1dr/openapi-to-agent-tools`) Actor

- **URL**: https://apify.com/n4d.h1dr/openapi-to-agent-tools.md
- **Developed by:** [Nadim Hider](https://apify.com/n4d.h1dr) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 spec converteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## OpenAPI and Swagger to Agent Tools Converter API

Instantly and deterministically transform any OpenAPI 2.0/3.0/3.1 or Swagger specification into production ready tool calling definitions for autonomous agents. Supports OpenAI Function Calling, Anthropic Tool Use, Google Gemini Function Declarations, and Model Context Protocol (MCP) server schemas in one pass.

### Key Capabilities

- **Multi Framework Native**: Simultaneously generates schemas tailored for OpenAI, Anthropic Claude, Google Gemini, and Model Context Protocol (MCP).
- **Strict Schema Support**: Enables `additionalProperties: false` and strict JSON schemas compatible with OpenAI Structured Outputs.
- **Deep Parameter Extraction**: Parses path variables, query parameters, headers, and complex nested request bodies into typed tool schemas.
- **Deterministic and Zero External Cost**: 100% algorithmic parsing via syntax tree reconstruction without LLM calls or token overhead.
- **Agent Ready Output**: Delivers clean tool definitions alongside Markdown endpoint summaries for prompt injection.

### Pricing

- Pay-Per-Event (PPE): **$0.005** per specification converted ($5.00 per 1,000 specifications).
- Compute fee waived for fast executions.

***

### Input Parameters

| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| `items` | Array | Yes | Sample Petstore API | List of OpenAPI/Swagger specs as JSON objects or YAML/JSON strings. |
| `target_formats` | Array | No | `["openai", "anthropic", "gemini", "mcp"]` | Formats to generate for autonomous agent systems. |
| `strict_mode` | Boolean | No | `true` | Adds strict formatting for structured outputs compliance. |

***

### Output Format

Outputs follow the standardized Dual Output Envelope:

```json
{
  "success": true,
  "meta": {
    "title": "Pet Store API",
    "version": "1.0.0",
    "endpoints_count": 2,
    "tools_generated_count": 2,
    "processing_time_ms": 1.45
  },
  "data": {
    "openai_tools": [
      {
        "type": "function",
        "function": {
          "name": "listPets",
          "description": "Returns a list of pets with optional limit filter.",
          "parameters": {
            "type": "object",
            "properties": {
              "limit": { "type": "integer", "format": "int32", "description": "How many items to return at one time (max 100)" }
            },
            "required": [],
            "additionalProperties": false
          },
          "strict": true
        }
      }
    ],
    "anthropic_tools": [...],
    "gemini_declarations": [...],
    "mcp_tools": [...]
  },
  "markdown_summary": "### API: Pet Store API (v1.0.0)\n- **listPets** (GET `/pets`): Returns a list of pets with optional limit filter."
}
```

***

### Code Examples (10+ Languages)

#### 1. Python

```python
from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")
run_input = {
    "items": [{"openapi": "3.0.0", "info": {"title": "Test", "version": "1.0"}, "paths": {}}],
    "target_formats": ["openai", "mcp"],
    "strict_mode": True
}
run = client.actor("n4d.h1dr/openapi-to-agent-tools").call(run_input=run_input)
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item["data"]["mcp_tools"])
```

#### 2. TypeScript / JavaScript

```typescript
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: 'YOUR_APIFY_TOKEN' });
const run = await client.actor('n4d.h1dr/openapi-to-agent-tools').call({
  items: [myOpenApiSpec],
  target_formats: ['anthropic', 'openai']
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items[0].data.anthropic_tools);
```

#### 3. cURL

```bash
curl -X POST "https://api.apify.com/v2/acts/n4d.h1dr~openapi-to-agent-tools/runs?token=YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"items": [{"openapi": "3.0.0", "info": {"title": "API", "version": "1.0"}, "paths": {}}]}'
```

#### 4. Go

```go
package main

import (
	"bytes"
	"encoding/json"
	"net/http"
)

func main() {
	payload := map[string]interface{}{
		"items": []interface{}{map[string]string{"openapi": "3.0.0"}},
	}
	body, _ := json.Marshal(payload)
	req, _ := http.NewRequest("POST", "https://api.apify.com/v2/acts/n4d.h1dr~openapi-to-agent-tools/runs?token=YOUR_APIFY_TOKEN", bytes.NewBuffer(body))
	req.Header.Set("Content-Type", "application/json")
	client := &http.Client{}
	client.Do(req)
}
```

#### 5. Ruby

```ruby
require 'net/http'
require 'json'
require 'uri'

uri = URI("https://api.apify.com/v2/acts/n4d.h1dr~openapi-to-agent-tools/runs?token=YOUR_APIFY_TOKEN")
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
req.body = { items: [{ openapi: "3.0.0" }] }.to_json
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
```

#### 6. PHP

```php
<?php
$ch = curl_init('https://api.apify.com/v2/acts/n4d.h1dr~openapi-to-agent-tools/runs?token=YOUR_APIFY_TOKEN');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['items' => [['openapi' => '3.0.0']]]));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
```

#### 7. Java

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class ToolConverter {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();
        String json = "{\"items\":[{\"openapi\":\"3.0.0\"}]}";
        HttpRequest req = HttpRequest.newBuilder()
            .uri(URI.create("https://api.apify.com/v2/acts/n4d.h1dr~openapi-to-agent-tools/runs?token=YOUR_APIFY_TOKEN"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();
        client.send(req, HttpResponse.BodyHandlers.ofString());
    }
}
```

#### 8. C# (.NET)

```csharp
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program {
    static async Task Main() {
        var client = new HttpClient();
        var content = new StringContent("{\"items\":[{\"openapi\":\"3.0.0\"}]}", Encoding.UTF8, "application/json");
        await client.PostAsync("https://api.apify.com/v2/acts/n4d.h1dr~openapi-to-agent-tools/runs?token=YOUR_APIFY_TOKEN", content);
    }
}
```

#### 9. Rust

```rust
use reqwest::Client;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let body = json!({ "items": [{ "openapi": "3.0.0" }] });
    client.post("https://api.apify.com/v2/acts/n4d.h1dr~openapi-to-agent-tools/runs?token=YOUR_APIFY_TOKEN")
        .json(&body)
        .send()
        .await?;
    Ok(())
}
```

#### 10. Swift

```swift
import Foundation

let url = URL(string: "https://api.apify.com/v2/acts/n4d.h1dr~openapi-to-agent-tools/runs?token=YOUR_APIFY_TOKEN")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: ["items": [["openapi": "3.0.0"]]])
URLSession.shared.dataTask(with: request).resume()
```

#### 11. n8n and Make.com

- In n8n, use the HTTP Request node with Method `POST` pointing to `https://api.apify.com/v2/acts/n4d.h1dr~openapi-to-agent-tools/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN`.
- In Make.com, add an Apify module "Run Actor and get dataset items" with the specified configuration.

# Actor input Schema

## `items` (type: `array`):

List of OpenAPI or Swagger 2.0/3.0/3.1 specifications in JSON or YAML string format or raw JSON objects.

## `target_formats` (type: `array`):

List of tool formats to generate: openai, anthropic, gemini, or mcp.

## `strict_mode` (type: `boolean`):

When enabled, adds additionalProperties false and ensures all properties are strictly typed for OpenAI Structured Outputs.

## Actor input object example

```json
{
  "items": [
    {
      "openapi": "3.0.0",
      "info": {
        "title": "Pet Store API",
        "version": "1.0.0",
        "description": "A sample API for testing tool generation."
      },
      "paths": {
        "/pets": {
          "get": {
            "operationId": "listPets",
            "summary": "List all pets",
            "description": "Returns a list of pets with optional limit filter.",
            "parameters": [
              {
                "name": "limit",
                "in": "query",
                "description": "How many items to return at one time (max 100)",
                "required": false,
                "schema": {
                  "type": "integer",
                  "format": "int32"
                }
              }
            ]
          },
          "post": {
            "operationId": "createPet",
            "summary": "Create a pet",
            "description": "Creates a new pet in the store.",
            "requestBody": {
              "required": true,
              "content": {
                "application/json": {
                  "schema": {
                    "type": "object",
                    "required": [
                      "name"
                    ],
                    "properties": {
                      "name": {
                        "type": "string",
                        "description": "The name of the pet"
                      },
                      "tag": {
                        "type": "string",
                        "description": "Optional category tag"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  ],
  "target_formats": [
    "openai",
    "anthropic",
    "gemini",
    "mcp"
  ],
  "strict_mode": true
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "items": [
        {
            "openapi": "3.0.0",
            "info": {
                "title": "Pet Store API",
                "version": "1.0.0",
                "description": "A sample API for testing tool generation."
            },
            "paths": {
                "/pets": {
                    "get": {
                        "operationId": "listPets",
                        "summary": "List all pets",
                        "description": "Returns a list of pets with optional limit filter.",
                        "parameters": [
                            {
                                "name": "limit",
                                "in": "query",
                                "description": "How many items to return at one time (max 100)",
                                "required": false,
                                "schema": {
                                    "type": "integer",
                                    "format": "int32"
                                }
                            }
                        ]
                    },
                    "post": {
                        "operationId": "createPet",
                        "summary": "Create a pet",
                        "description": "Creates a new pet in the store.",
                        "requestBody": {
                            "required": true,
                            "content": {
                                "application/json": {
                                    "schema": {
                                        "type": "object",
                                        "required": [
                                            "name"
                                        ],
                                        "properties": {
                                            "name": {
                                                "type": "string",
                                                "description": "The name of the pet"
                                            },
                                            "tag": {
                                                "type": "string",
                                                "description": "Optional category tag"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    ],
    "target_formats": [
        "openai",
        "anthropic",
        "gemini",
        "mcp"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("n4d.h1dr/openapi-to-agent-tools").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "items": [{
            "openapi": "3.0.0",
            "info": {
                "title": "Pet Store API",
                "version": "1.0.0",
                "description": "A sample API for testing tool generation.",
            },
            "paths": { "/pets": {
                    "get": {
                        "operationId": "listPets",
                        "summary": "List all pets",
                        "description": "Returns a list of pets with optional limit filter.",
                        "parameters": [{
                                "name": "limit",
                                "in": "query",
                                "description": "How many items to return at one time (max 100)",
                                "required": False,
                                "schema": {
                                    "type": "integer",
                                    "format": "int32",
                                },
                            }],
                    },
                    "post": {
                        "operationId": "createPet",
                        "summary": "Create a pet",
                        "description": "Creates a new pet in the store.",
                        "requestBody": {
                            "required": True,
                            "content": { "application/json": { "schema": {
                                        "type": "object",
                                        "required": ["name"],
                                        "properties": {
                                            "name": {
                                                "type": "string",
                                                "description": "The name of the pet",
                                            },
                                            "tag": {
                                                "type": "string",
                                                "description": "Optional category tag",
                                            },
                                        },
                                    } } },
                        },
                    },
                } },
        }],
    "target_formats": [
        "openai",
        "anthropic",
        "gemini",
        "mcp",
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("n4d.h1dr/openapi-to-agent-tools").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "items": [
    {
      "openapi": "3.0.0",
      "info": {
        "title": "Pet Store API",
        "version": "1.0.0",
        "description": "A sample API for testing tool generation."
      },
      "paths": {
        "/pets": {
          "get": {
            "operationId": "listPets",
            "summary": "List all pets",
            "description": "Returns a list of pets with optional limit filter.",
            "parameters": [
              {
                "name": "limit",
                "in": "query",
                "description": "How many items to return at one time (max 100)",
                "required": false,
                "schema": {
                  "type": "integer",
                  "format": "int32"
                }
              }
            ]
          },
          "post": {
            "operationId": "createPet",
            "summary": "Create a pet",
            "description": "Creates a new pet in the store.",
            "requestBody": {
              "required": true,
              "content": {
                "application/json": {
                  "schema": {
                    "type": "object",
                    "required": [
                      "name"
                    ],
                    "properties": {
                      "name": {
                        "type": "string",
                        "description": "The name of the pet"
                      },
                      "tag": {
                        "type": "string",
                        "description": "Optional category tag"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  ],
  "target_formats": [
    "openai",
    "anthropic",
    "gemini",
    "mcp"
  ]
}' |
apify call n4d.h1dr/openapi-to-agent-tools --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,n4d.h1dr/openapi-to-agent-tools"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/9F2kesp0himDFpetW/builds/wSeuB7GhMv1Fb4vDS/openapi.json
