{
  "openapi": "3.1.0",
  "info": {
    "title": "Optiview Parse and Retrieve",
    "version": "1.1.1",
    "description": "Server-to-server Parse and Retrieve API. Direct endpoints return durable jobs, with queued fallback. Processing failure can be HTTP 200: inspect status. Parse costs 1 credit and Retrieve 5 on success. $20 buys 20,000 prepaid credits. Documentation: https://optiview.ai/developers/"
  },
  "servers": [
    {
      "url": "https://api.optiview.ai"
    }
  ],
  "security": [
    {
      "serviceKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "serviceKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "ov_service_… key created in the developer console."
      }
    },
    "schemas": {
      "ParseInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "html",
          "url"
        ],
        "properties": {
          "html": {
            "type": "string",
            "description": "Complete supplied HTML. Maximum 2,000,000 UTF-8 bytes, within 2,100,000 encoded JSON bytes."
          },
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048,
            "description": "Absolute HTTPS source identity for resolving relative links. No credentials, custom port or fragment. Validated but never fetched; does not verify supplied HTML provenance."
          }
        }
      },
      "RetrieveInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048,
            "description": "HTTPS source URL without credentials, custom port or fragment. Retrieve accepts eligible public hosts, ordinary query parameters and www/non-www; credential-bearing or signed URLs are rejected."
          }
        }
      },
      "AsyncInput": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "product",
              "html",
              "url"
            ],
            "properties": {
              "product": {
                "const": "parse"
              },
              "html": {
                "type": "string",
                "description": "Maximum 2,000,000 UTF-8 bytes."
              },
              "url": {
                "type": "string",
                "format": "uri",
                "maxLength": 2048,
                "description": "Absolute HTTPS source identity for resolving relative links. No credentials, custom port or fragment. Validated but never fetched; does not verify supplied HTML provenance."
              }
            }
          },
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "product",
              "url"
            ],
            "properties": {
              "product": {
                "const": "retrieve"
              },
              "url": {
                "type": "string",
                "format": "uri",
                "maxLength": 2048,
                "description": "HTTPS source URL without credentials, custom port or fragment. Retrieve accepts eligible public hosts, ordinary query parameters and www/non-www; credential-bearing or signed URLs are rejected."
              }
            }
          }
        ]
      },
      "Source": {
        "type": "object",
        "required": [
          "basis",
          "observed_at",
          "decoded_html_sha256",
          "source_bytes",
          "origin_freshness_verified"
        ],
        "properties": {
          "basis": {
            "enum": [
              "supplied_html",
              "anonymous_http_response"
            ]
          },
          "observed_at": {
            "type": "string",
            "format": "date-time"
          },
          "decoded_html_sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "source_bytes": {
            "type": "integer",
            "minimum": 0
          },
          "origin_freshness_verified": {
            "const": false
          },
          "status": {
            "type": "integer",
            "description": "Retrieve only: observed HTTP status."
          },
          "content_type": {
            "type": "string"
          },
          "redirects": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "from",
                "to",
                "status"
              ],
              "properties": {
                "from": {
                  "type": "string"
                },
                "to": {
                  "type": "string"
                },
                "status": {
                  "type": "integer"
                }
              }
            }
          },
          "scheme_retries": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "cache_control": {
            "type": [
              "string",
              "null"
            ]
          },
          "age": {
            "type": [
              "string",
              "null"
            ]
          },
          "etag": {
            "type": [
              "string",
              "null"
            ]
          },
          "last_modified": {
            "type": [
              "string",
              "null"
            ]
          },
          "cookies_forwarded": {
            "const": false
          },
          "cookies_retained": {
            "const": false
          }
        },
        "additionalProperties": true
      },
      "Extraction": {
        "type": "object",
        "required": [
          "parser_version",
          "composition_version",
          "source_review",
          "warnings"
        ],
        "properties": {
          "parser_version": {
            "type": "string"
          },
          "composition_version": {
            "type": "string"
          },
          "presentation_version": {
            "type": "string"
          },
          "source_review": {
            "type": "object",
            "properties": {
              "status": {
                "type": "string"
              }
            },
            "additionalProperties": true
          },
          "warnings": {
            "type": "array",
            "items": {}
          },
          "dynamic_rendering": {
            "const": "not_executed"
          }
        },
        "additionalProperties": true
      },
      "Result": {
        "type": "object",
        "required": [
          "success",
          "url",
          "title",
          "content_type",
          "markdown",
          "payload_sha256",
          "source",
          "extraction",
          "narrative_graph",
          "limitations"
        ],
        "properties": {
          "success": {
            "const": true
          },
          "url": {
            "type": "string"
          },
          "requested_url": {
            "type": "string",
            "description": "Retrieve only."
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "content_type": {
            "const": "text/markdown"
          },
          "markdown": {
            "type": "string",
            "description": "Up to 512,000 UTF-8 bytes."
          },
          "payload_sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "source": {
            "$ref": "#/components/schemas/Source"
          },
          "extraction": {
            "$ref": "#/components/schemas/Extraction"
          },
          "narrative_graph": {
            "type": "object",
            "required": [
              "status"
            ],
            "properties": {
              "status": {
                "const": "not_requested"
              }
            }
          },
          "limitations": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "additionalProperties": true
      },
      "Job": {
        "type": "object",
        "required": [
          "id",
          "product",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "product": {
            "enum": [
              "parse",
              "retrieve"
            ]
          },
          "status": {
            "enum": [
              "queued",
              "running",
              "succeeded",
              "failed",
              "expired",
              "canceled"
            ]
          },
          "credits_reserved": {
            "type": "integer",
            "description": "Initial queued acceptance only."
          },
          "result_url": {
            "type": "string",
            "description": "Relative job read URL on initial queued acceptance."
          },
          "credits_charged": {
            "type": "integer",
            "enum": [
              0,
              1,
              5
            ],
            "description": "A successful retained-expired job keeps its earlier charge."
          },
          "created_at": {
            "type": "integer",
            "description": "Unix milliseconds. Retention begins at creation."
          },
          "completed_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Unix time in milliseconds."
          },
          "error_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "result": {
            "$ref": "#/components/schemas/Result"
          }
        },
        "additionalProperties": true,
        "description": "Acceptance may omit timestamps and credits_charged. Only an available succeeded job includes result. HTTP 200 does not imply processing success.",
        "allOf": [
          {
            "if": {
              "properties": {
                "status": {
                  "const": "succeeded"
                }
              }
            },
            "then": {
              "required": [
                "result"
              ]
            },
            "else": {
              "not": {
                "required": [
                  "result"
                ]
              }
            }
          }
        ]
      },
      "Error": {
        "type": "object",
        "required": [
          "error",
          "request_id"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "Usage": {
        "type": "object",
        "required": [
          "account",
          "jobs"
        ],
        "properties": {
          "account": {
            "type": "object",
            "required": [
              "credits",
              "held"
            ],
            "properties": {
              "credits": {
                "type": "integer",
                "description": "Wallet balance before subtracting held reservations."
              },
              "held": {
                "type": "integer",
                "minimum": 0
              }
            }
          },
          "jobs": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "product",
                "status",
                "jobs",
                "credits"
              ],
              "properties": {
                "product": {
                  "enum": [
                    "parse",
                    "retrieve"
                  ]
                },
                "status": {
                  "type": "string"
                },
                "jobs": {
                  "type": "integer"
                },
                "credits": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "in": "header",
        "name": "Idempotency-Key",
        "required": true,
        "description": "Persist for the logical work item. Replay with the same originating application, endpoint and exact serialized input. Not reset when output expires.",
        "schema": {
          "type": "string",
          "minLength": 8,
          "maxLength": 128,
          "pattern": "^[a-zA-Z0-9_.:-]+$"
        }
      }
    }
  },
  "paths": {
    "/v1/jobs": {
      "post": {
        "operationId": "createJob",
        "description": "Reserve credits and queue one page. Reuse the same idempotency key and identical input after uncertain submission.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AsyncInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing or terminal job. Inspect status; failed processing can return HTTP 200.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "202": {
            "description": "Durable queued or running job. Poll its ID with the originating application; this is not a finished result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, request field or idempotency key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked service key, or closed account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient available credits.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser-origin request or missing product scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency key belongs to different input or another application.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Supplied HTML exceeds the byte limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request or submission rate limit; implement bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service disabled, temporary failure or missing committed result. Retry using the same job/idempotency ID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Jobs"
        ]
      }
    },
    "/v1/jobs/{id}": {
      "get": {
        "operationId": "getJob",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Existing or terminal job. Inspect status; failed processing can return HTTP 200.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked service key, or closed account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser-origin request or missing product scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown route or job unavailable to this application.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request or submission rate limit; implement bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service disabled, temporary failure or missing committed result. Retry using the same job/idempotency ID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Jobs"
        ]
      }
    },
    "/v1/usage": {
      "get": {
        "operationId": "getUsage",
        "responses": {
          "200": {
            "description": "Workspace balance and grouped usage.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked service key, or closed account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser-origin request or missing product scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request or submission rate limit; implement bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service disabled, temporary failure or missing committed result. Retry using the same job/idempotency ID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Usage"
        ]
      }
    },
    "/v1/parse": {
      "post": {
        "operationId": "parse",
        "description": "Execute parse immediately when capacity permits, using the same durable job, idempotency, source controls and successful-job charging. Returns a job envelope; inspect status. Queued/running responses require polling /v1/jobs/{id}. Retry the same endpoint, identical input and Idempotency-Key after uncertain delivery. Existing /v1/jobs remains asynchronous.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ParseInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing or terminal job. Inspect status; failed processing can return HTTP 200.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "202": {
            "description": "Durable queued or running job. Poll its ID with the originating application; this is not a finished result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, request field or idempotency key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked service key, or closed account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient available credits.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser-origin request or missing product scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency key belongs to different input or another application.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Supplied HTML exceeds the byte limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request or submission rate limit; implement bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service disabled, temporary failure or missing committed result. Retry using the same job/idempotency ID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Content"
        ]
      }
    },
    "/v1/retrieve": {
      "post": {
        "operationId": "retrieve",
        "description": "Execute retrieve immediately when capacity permits, using the same durable job, idempotency, source controls and successful-job charging. Returns a job envelope; inspect status. Queued/running responses require polling /v1/jobs/{id}. Retry the same endpoint, identical input and Idempotency-Key after uncertain delivery. Existing /v1/jobs remains asynchronous.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RetrieveInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing or terminal job. Inspect status; failed processing can return HTTP 200.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "202": {
            "description": "Durable queued or running job. Poll its ID with the originating application; this is not a finished result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, request field or idempotency key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked service key, or closed account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient available credits.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser-origin request or missing product scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency key belongs to different input or another application.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request or submission rate limit; implement bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service disabled, temporary failure or missing committed result. Retry using the same job/idempotency ID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Content"
        ]
      }
    }
  },
  "externalDocs": {
    "description": "Developer documentation",
    "url": "https://optiview.ai/developers/"
  },
  "tags": [
    {
      "name": "Content",
      "description": "Direct content preparation."
    },
    {
      "name": "Jobs",
      "description": "Asynchronous submission and job reads."
    },
    {
      "name": "Usage",
      "description": "Workspace balance and usage."
    }
  ]
}
