{
  "openapi": "3.1.0",
  "info": {
    "title": "webfetch",
    "version": "1.0.0",
    "summary": "The fetch tool for agents.",
    "description": "One URL in, clean content out. JavaScript rendered in a real browser, bot challenges handled, and when a page cannot be fetched the response says why and the request is charged 0 credits.",
    "contact": {
      "name": "webfetch",
      "url": "https://webfetch.run"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://api.webfetch.run",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/scrape": {
      "post": {
        "operationId": "scrapeUrl",
        "summary": "Fetch one URL and return it in the requested formats.",
        "description": "Requires an API key and location.country. A successful uncached fetch costs one fetch charge. A wall, refusal or error returns `success: false` and costs nothing.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ScrapeRequest"
              },
              "example": {
                "url": "https://example.com",
                "location": {
                  "country": "US"
                },
                "formats": [
                  "markdown",
                  "metadata"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The page, or an honest failure. `success` is the source of truth — a wall is a 200 with success:false.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScrapeResponse"
                }
              }
            }
          },
          "400": {
            "description": "invalid_request, target_not_allowed, egress_unavailable or location_unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "missing_api_key or invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "The balance cannot cover the fetch.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "account_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "fleet_unavailable — our fault, refunded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "504": {
            "description": "timeout — charged 0",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/scrape/demo": {
      "post": {
        "operationId": "scrapeUrlDemo",
        "summary": "The same work, authenticated by a session. This is the free sandbox, with a lifetime free allowance.",
        "description": "Requires a signed-in session and location.country. Eligible accounts use a lifetime sandbox allowance.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ScrapeRequest"
              }
            }
          }
        },
        "security": [],
        "responses": {
          "200": {
            "description": "Same shape as /v1/scrape"
          },
          "401": {
            "description": "unauthorized"
          }
        }
      }
    },
    "/v1/locations": {
      "get": {
        "operationId": "listLocations",
        "summary": "List configured egress routes for all ISO 3166-1 alpha-2 countries.",
        "description": "An empty egress array means no configured route. This endpoint reports routing configuration, not observed IP geolocation or real-time proxy health.",
        "security": [],
        "responses": {
          "200": {
            "description": "Country codes, English names and configured egress types.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "countries",
                    "automaticCountry"
                  ],
                  "properties": {
                    "automaticCountry": {
                      "type": "string",
                      "description": "Suggested country for the sandbox, inferred from the connection with a US fallback."
                    },
                    "countries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "country",
                          "name",
                          "egress"
                        ],
                        "properties": {
                          "country": {
                            "type": "string",
                            "minLength": 2,
                            "maxLength": 2
                          },
                          "name": {
                            "type": "string"
                          },
                          "egress": {
                            "type": "array",
                            "items": {
                              "type": "string",
                              "enum": [
                                "direct",
                                "datacenter",
                                "residential"
                              ]
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "locations_unavailable"
          }
        }
      }
    },
    "/v1/sessions": {
      "get": {
        "operationId": "listInteractiveSessions",
        "summary": "List open interactive browser sessions for the account.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Active count, account concurrency limit, sessions and pricing."
          },
          "401": {
            "description": "missing_api_key or invalid_api_key"
          }
        }
      },
      "post": {
        "operationId": "openInteractiveSession",
        "summary": "Open a persistent interactive browser session with a JavaScript REPL.",
        "description": "One open session per account. Maximum lifetime is 5 minutes; idle timeout is 60 seconds. Charges $0.0440 per browser minute with a $0.0440 minimum. Reserves at most $0.2200 and refunds unused time.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url",
                  "location"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "egress": {
                    "type": "string",
                    "enum": [
                      "direct",
                      "datacenter",
                      "residential"
                    ]
                  },
                  "location": {
                    "type": "object",
                    "required": [
                      "country"
                    ],
                    "properties": {
                      "country": {
                        "type": "string",
                        "minLength": 2,
                        "maxLength": 2
                      },
                      "languages": {
                        "type": "array",
                        "minItems": 1,
                        "maxItems": 10,
                        "items": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Session opened."
          },
          "402": {
            "description": "Insufficient balance for maximum reserve."
          },
          "429": {
            "description": "Account session limit reached."
          }
        }
      }
    },
    "/v1/sessions/{id}/execute": {
      "post": {
        "operationId": "executeInteractiveSession",
        "summary": "Execute JavaScript against page and context in an open browser session.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "code"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 16000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "REPL result and current session expiry."
          },
          "408": {
            "description": "Execution timed out; session closed."
          },
          "410": {
            "description": "Session expired or closed."
          }
        }
      }
    },
    "/v1/sessions/{id}": {
      "delete": {
        "operationId": "closeInteractiveSession",
        "summary": "Close a browser session and settle the accrued browser-time charge.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Session closed and unused reserve refunded."
          },
          "404": {
            "description": "Session not open on this account."
          }
        }
      }
    },
    "/v1/me": {
      "get": {
        "operationId": "getAccount",
        "summary": "Account, credit balance, plan and what the plan unlocks.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "responses": {
          "200": {
            "description": "The account",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "email": {
                      "type": "string"
                    },
                    "credits": {
                      "type": "integer"
                    },
                    "plan": {
                      "type": "string",
                      "enum": [
                        "free",
                        "starter",
                        "scale"
                      ]
                    },
                    "capabilities": {
                      "type": "object",
                      "properties": {
                        "playground": {
                          "type": "boolean"
                        },
                        "apiKeys": {
                          "type": "boolean"
                        }
                      }
                    },
                    "upgradeReason": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "unauthorized"
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "health",
        "summary": "Liveness. No auth.",
        "security": [],
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "sk_live_…",
        "description": "API key. Paid plans."
      },
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "__session",
        "description": "Clerk session cookie."
      }
    },
    "schemas": {
      "ScrapeRequest": {
        "type": "object",
        "required": [
          "url",
          "location"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Public http(s). Private ranges are refused."
          },
          "formats": {
            "type": "array",
            "description": "Any of: markdown, html, rawHtml, rawBase64, text, screenshot, links, images, metadata, branding, attributes, summary, json, ai_overview. Case-insensitive; an unknown name is a 400.",
            "items": {
              "type": "string",
              "enum": [
                "markdown",
                "html",
                "rawHtml",
                "rawBase64",
                "text",
                "screenshot",
                "links",
                "images",
                "metadata",
                "branding",
                "attributes",
                "summary",
                "json",
                "ai_overview"
              ]
            },
            "default": [
              "markdown"
            ]
          },
          "egress": {
            "type": "string",
            "enum": [
              "direct",
              "datacenter",
              "residential"
            ],
            "default": "residential",
            "description": "Defaults to residential egress targeted to location.country."
          },
          "location": {
            "type": "object",
            "required": [
              "country"
            ],
            "properties": {
              "country": {
                "type": "string",
                "minLength": 2,
                "maxLength": 2
              },
              "languages": {
                "type": "array",
                "minItems": 1,
                "maxItems": 10,
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "onlyMainContent": {
            "type": "boolean",
            "default": true
          },
          "waitForSelector": {
            "type": "string"
          },
          "persist": {
            "type": "boolean",
            "default": false
          },
          "rotations": {
            "type": "integer",
            "minimum": 0,
            "maximum": 5,
            "default": 3
          },
          "parallelProbes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5,
            "default": 3
          },
          "timeout": {
            "type": "integer",
            "minimum": 5000,
            "maximum": 300000,
            "default": 120000
          },
          "session": {
            "type": "object",
            "description": "Replay a cleared session. Turns repeat queries to one host from ~38s into ~6-8s.",
            "properties": {
              "cookies": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "egressPort": {
                "type": "integer"
              }
            }
          },
          "attributes": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "object",
              "required": [
                "selector",
                "attribute"
              ],
              "properties": {
                "selector": {
                  "type": "string"
                },
                "attribute": {
                  "type": "string"
                }
              }
            }
          },
          "summaryPrompt": {
            "type": "string"
          },
          "jsonOptions": {
            "type": "object",
            "properties": {
              "schema": {
                "type": "object"
              }
            }
          }
        }
      },
      "ScrapeResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "The source of truth. A blocked page is success:false with HTTP 200."
          },
          "data": {
            "type": "object",
            "description": "Only the formats requested, plus metadata.",
            "properties": {
              "markdown": {
                "description": "string. The page as markdown. Default when no format is requested."
              },
              "html": {
                "description": "string. Cleaned HTML. Narrowed by onlyMainContent (default true)."
              },
              "rawHtml": {
                "description": "string. The document exactly as received. Never narrowed."
              },
              "rawBase64": {
                "description": "string. The document bytes as base64. UTF-8 safe."
              },
              "text": {
                "description": "string. Visible text only, no markup. Inline data: images are stripped."
              },
              "screenshot": {
                "description": "string. Base64 PNG of the rendered page."
              },
              "links": {
                "description": "string[]. Absolute URLs found on the page."
              },
              "images": {
                "description": "array of {src, alt?, width?, height?}. Absolute image URLs with alt text."
              },
              "metadata": {
                "description": "object. Head tags: title, description, og:*, canonical, language."
              },
              "branding": {
                "description": "object. Colours, fonts and logo. Deterministic, no model."
              },
              "attributes": {
                "description": "object. Named attributes per selector sent in `attributes`."
              },
              "summary": {
                "description": "string. A short abstract. Needs a model key on the deployment."
              },
              "json": {
                "description": "object. Structured extraction against `jsonOptions.schema`."
              },
              "ai_overview": {
                "description": "{ present, markdown?, screenshot? }. The generated-answer card, expanded, as markdown plus a PNG of that card. present:false when the page has none."
              }
            }
          },
          "error": {
            "type": "string",
            "description": "Machine-readable code when success is false."
          },
          "message": {
            "type": "string",
            "description": "Human-readable explanation when success is false."
          },
          "credits": {
            "type": "object",
            "properties": {
              "charged": {
                "type": "integer",
                "description": "0 for any failure."
              },
              "remaining": {
                "type": "integer"
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "const": false
          },
          "error": {
            "type": "string",
            "enum": [
              "invalid_request",
              "target_not_allowed",
              "egress_unavailable",
              "location_unavailable",
              "locations_unavailable",
              "missing_api_key",
              "invalid_api_key",
              "unauthorized",
              "insufficient_balance",
              "account_suspended",
              "insufficient_balance",
              "fleet_unavailable",
              "timeout",
              "blocked"
            ]
          },
          "message": {
            "type": "string"
          }
        }
      }
    }
  },
  "x-pricing": {
    "perFetchMicros": 22000,
    "failedFetchMicros": 0,
    "currency": "usd"
  },
  "x-failure-costs-money": false
}
