# HAR to OpenAPI 3 Spec Generator (`earthen_garland/har-to-openapi`) Actor

Turn a HAR recording of an API you own or are authorized to use into an OpenAPI 3 spec: templated paths, typed parameters, auth scheme, pagination and response schemas. Secrets redacted by default. YAML + JSON output.

- **URL**: https://apify.com/earthen_garland/har-to-openapi.md
- **Developed by:** [Kobi Mozgori](https://apify.com/earthen_garland) (community)
- **Categories:** Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 71.4% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $20.00 / 1,000 openapi spec generateds

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

## HAR to OpenAPI 3 Spec Generator

Turn a **HAR recording of an API you own or are authorized to use** into a ready-to-edit **OpenAPI 3.0.3 spec**: templated paths, typed parameters, the auth scheme, pagination hints and response schemas. Secrets are **redacted by default**.

Typical uses:

- Document an internal or legacy API that never had a spec, from traffic your own app or test suite already produces.
- Bootstrap a spec for your own service before writing it by hand, then import it into Swagger UI, Postman, Insomnia, Stoplight or a code generator.
- Diff what your client *actually* calls against the official spec of an API you have access to.

> **Acceptable use.** Use this Actor only on traffic you are allowed to record and analyze: your own APIs, APIs of your employer or client with their permission, or third-party APIs whose terms allow it. It is a documentation tool, not a tool for reverse-engineering or bypassing access controls of sites you are not authorized to use. Do not upload HARs that contain other people's personal data. You are responsible for complying with the terms of every API that appears in your HAR.

### What you get

| Output | Where |
| --- | --- |
| OpenAPI spec (JSON, or YAML when format is `yaml`) | Key-value store record `OUTPUT` |
| `openapi.yaml` / `openapi.json` | Key-value store records (per `outputFormat`) |
| One row per endpoint (method, path, params with types, status codes, auth, pagination) | Default dataset, view **Endpoints** |
| Run summary (requests used/dropped, redaction counts, timing; never secret values) | Key-value store record `RUN_SUMMARY` |

The spec contains:

- **Templated paths**: `/users/101`, `/users/202` → `/users/{userId}` (integers, UUIDs, hex ids, dates, slugs, composite segments), using URLs found in response bodies as extra evidence.
- **Typed parameters**: path and query params with `integer`, `number`, `boolean`, `array`, `date`, `date-time`, `uuid`; required vs optional from how often they appear.
- **Request bodies**: JSON and form-urlencoded schemas.
- **Responses**: one entry per observed status code with an inferred JSON schema.
- **Auth**: `securitySchemes` for bearer, basic, API key in header or query, applied per operation.
- **Pagination**: `x-pagination` with offset/page/cursor params, `Link: rel="next"` headers and next/total fields.

### Secret redaction (on by default)

Before inference, and again on the final output, the Actor replaces with `REDACTED`:

- values of `Authorization` / `Proxy-Authorization` (keeping the scheme word, so `Bearer REDACTED` still yields a bearer scheme), `Cookie`, `Set-Cookie` and HAR cookie lists;
- API-key and token headers (`X-API-Key`, `X-Auth-Token`, CSRF tokens, …) and any header, query, form or JSON field whose name looks like a secret (`token`, `secret`, `password`, `api_key`, `session`, `signature`, …);
- bearer/basic credentials, JWT-looking strings and common key formats (for example `sk_live_…`, `ghp_…`, `AKIA…`, `AIza…`) anywhere in URLs, headers or bodies;
- `user:password@` in URLs.

A final pass re-checks the serialized spec, the dataset rows and the summary for every secret value collected from the HAR. The test suite proves that no secret from a sample HAR full of fake credentials appears in any output. Redaction is best-effort pattern matching: review the spec before sharing it, and prefer HARs recorded with test accounts.

### Input

| Field | Description |
| --- | --- |
| `harFile` | Upload a `.har` file (stored in a key-value store). |
| `harUrl` | Or give a direct http(s) link to a HAR. Prefilled with a small synthetic demo HAR (fake credentials). With no HAR at all, the Actor runs its built-in demo HAR. |
| `outputFormat` | `both` (default), `yaml` or `json`. |
| `baseUrl` | Keep only one API: URL prefix (`https://api.example.com/v1`) or host (`api.example.com`, `*.example.com`). Default: the most frequent origin in the HAR. |
| `redactSecrets` | Default `true`. |
| `skipStaticAssets` | Default `true`: ignore images, fonts, CSS, JS. |
| `title` | Optional `info.title`. |
| `maxHarMb` | Download limit, default 100 MB. |

Example:

```json
{
  "harUrl": "https://example.com/my-own-app.har",
  "baseUrl": "api.my-company.example",
  "outputFormat": "both",
  "redactSecrets": true
}
```

How to record a HAR: Chrome/Edge/Firefox DevTools → **Network** → reproduce the flows you want documented → **Export HAR**. Exercising more variety (several ids, pages, error cases) gives better templating and response schemas.

### Accuracy

We benchmarked the inference engine against official OpenAPI specs. On a holdout set of 3 public APIs (25 operations) that were generated only after the engine was frozen, it scored a combined endpoint+parameter F1 of **0.990**, versus **0.559** for mitmproxy2swagger. Inference runs in **under 0.12s per HAR** on the benchmark machine (a full Actor run also includes container start-up). Results are deterministic: the same HAR always gives the same spec.

Known limits: the spec only covers what the HAR contains; parameter names for templated segments are inferred (`{userId}`, `{order}`) and may need renaming; an identifier with a raw `/` inside it can be split into several segments; `info.version` is `0.0.0-inferred`.

### Pricing

Pay per event: **$0.02 per generated spec** (one HAR = one spec), plus Apify's standard synthetic Actor-start event. Dataset rows are free. See the **Pricing** tab for the current numbers.

### Integrations

Use the Apify API, CLI, Make, Zapier or n8n to run the Actor and fetch `openapi.yaml` from the run's key-value store, for example in CI after your end-to-end tests record a HAR.

### Support

Open an issue on the Actor's **Issues** tab with a description of the problem. Please never attach a HAR that contains real credentials or personal data.

# Changelog

This Actor's version history is a separate document: https://apify.com/earthen_garland/har-to-openapi/changelog.md

# Actor input Schema

## `harFile` (type: `string`):

Upload a .har file exported from your browser DevTools (Network tab > Save all as HAR), a proxy, or your test suite. Record only traffic of APIs you own or are authorized to access. Either this or HAR URL is required.

## `harUrl` (type: `string`):

Direct http(s) link to a HAR file, for example a key-value store record URL or a file in your own storage bucket. Used when no file is uploaded. The prefilled link is a small synthetic demo HAR with fake credentials. If both HAR fields are empty, the Actor runs that built-in demo HAR.

## `outputFormat` (type: `string`):

Which spec files to save in the key-value store. With 'both', OUTPUT is the JSON spec and openapi.yaml + openapi.json are both saved.

## `baseUrl` (type: `string`):

Keep only requests to this API. Either a URL prefix (https://api.example.com/v1) or a host (api.example.com, \*.example.com). Empty = the most frequent origin in the HAR.

## `redactSecrets` (type: `boolean`):

Strip values of Authorization headers, cookies, Set-Cookie, API keys, tokens, passwords and bearer/JWT-looking strings before inference and again on the output. The auth scheme type (bearer, basic, apiKey) is kept. Strongly recommended to leave on.

## `skipStaticAssets` (type: `boolean`):

Ignore images, fonts, CSS and JavaScript files that browsers record alongside API calls.

## `title` (type: `string`):

Optional info.title for the generated spec. Default: 'Inferred API for <origin>'.

## `maxHarMb` (type: `integer`):

Safety limit for the downloaded HAR. Very large HARs may need more run memory.

## Actor input object example

```json
{
  "harUrl": "https://api.apify.com/v2/key-value-stores/BJOCMDs5aTxeeFyF3/records/demo.har",
  "outputFormat": "both",
  "redactSecrets": true,
  "skipStaticAssets": true,
  "maxHarMb": 100
}
```

# Actor output Schema

## `spec` (type: `string`):

OUTPUT record: the spec as JSON (or YAML when outputFormat is yaml).

## `specYaml` (type: `string`):

The spec as YAML (outputFormat yaml or both).

## `specJson` (type: `string`):

The spec as JSON (outputFormat json or both).

## `endpoints` (type: `string`):

Default dataset: one row per method + path with parameters, status codes, auth and pagination.

## `runSummary` (type: `string`):

RUN_SUMMARY record: request counts, filters, redaction counts (no secret values) and timing.

# 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 = {
    "harUrl": "https://api.apify.com/v2/key-value-stores/BJOCMDs5aTxeeFyF3/records/demo.har"
};

// Run the Actor and wait for it to finish
const run = await client.actor("earthen_garland/har-to-openapi").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 = { "harUrl": "https://api.apify.com/v2/key-value-stores/BJOCMDs5aTxeeFyF3/records/demo.har" }

# Run the Actor and wait for it to finish
run = client.actor("earthen_garland/har-to-openapi").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 '{
  "harUrl": "https://api.apify.com/v2/key-value-stores/BJOCMDs5aTxeeFyF3/records/demo.har"
}' |
apify call earthen_garland/har-to-openapi --silent --output-dataset

```

## MCP server setup

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

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/av6681QDP1oFm6Xdn/builds/F2Ms633u27JKZvC9O/openapi.json
