Developers/Python integration

Integrations

Python integration

Use Python’s standard library to call the REST API. This is a working integration example, not a separate Python SDK.

Prepare the environment

Use Python 3.10+ and set OPTIVIEW_API_KEY privately. No third-party package is required. The example sends an authenticated request, identifies the client with a descriptive User-Agent, handles HTTP errors and bounds job polling.

Its successful Retrieve call consumes 5 credits. It does not automatically retry uncertain submissions; preserve the work item’s idempotency key before running it.

Retrieve and wait for completion

PythonCopy

import json
import os
import time
import urllib.error
import urllib.request

BASE_URL = "https://api.optiview.ai/v1"
API_KEY = os.environ["OPTIVIEW_API_KEY"]

class OptiviewAPIError(RuntimeError):
    def __init__(self, status, code, message, request_id=None):
        self.status = status
        self.code = code
        self.request_id = request_id
        super().__init__(
            f"HTTP {status} [{code}]: {message} request_id={request_id}"
        )

def request(path, body=None, idempotency_key=None):
    headers = {
        "Authorization": "Bearer " + API_KEY,
        "User-Agent": "OptiviewIntegration/1.0"
    }
    if body is not None:
        headers["Content-Type"] = "application/json"
    if idempotency_key:
        headers["Idempotency-Key"] = idempotency_key
    data = json.dumps(body).encode("utf-8") if body is not None else None
    req = urllib.request.Request(BASE_URL + path, data=data, headers=headers)
    try:
        with urllib.request.urlopen(req, timeout=35) as response:
            return json.load(response)
    except urllib.error.HTTPError as error:
        try:
            detail = json.loads(error.read())
        except ValueError:
            detail = {}
        api_error = detail.get("error", {})
        raise OptiviewAPIError(
            error.code,
            api_error.get("code", "edge_error"),
            api_error.get("message", "Non-JSON or upstream HTTP error"),
            detail.get("request_id")
        ) from error

# Save this key with your work item; reuse it after an uncertain timeout.
job = request("/retrieve", {
    "url": "https://optiview.ai/products/parse/"
}, idempotency_key="retrieve-order-1042")

# Bound the wait. A timeout does not cancel the server job.
deadline = time.monotonic() + 90
while job["status"] in ("queued", "running"):
    if time.monotonic() >= deadline:
        raise TimeoutError("Resume polling job " + job["id"])
    time.sleep(2)
    job = request("/jobs/" + job["id"])

if job["status"] != "succeeded" or "result" not in job:
    raise RuntimeError(job.get("error_code") or job["status"])
print(job["result"]["markdown"])

Use Parse with existing HTML

Reuse the request function above and replace the initial Retrieve call with:

PythonCopy

with open("page.html", encoding="utf-8") as source:
    html = source.read()

job = request("/parse", {
    "html": html,
    "url": "https://example.com/support"
}, idempotency_key="parse-order-1042")

The same status checks and polling loop apply. Parse requires the parse scope and consumes 1 credit on success.

Production handling

Persist the job ID and original input/key before recovery. If an HTTP or network error occurs after submission, use the idempotency retry rules; do not generate a replacement key automatically. A local timeout does not cancel the job. An edge-generated non-JSON error may not include an API error code or request ID; retain its HTTP status for support.

Keep logs limited to job IDs, request IDs, status and error codes. Store returned Markdown if you need it beyond seven days. For higher volume, use a bounded worker pool and workspace limits.

Additional source context

Your website was built for people. Optiview makes it ready for AI, too.

Get started

Overview · Quickstart · Authentication

API reference

Parse HTML · Retrieve a webpage · Jobs and results · Usage and credits · Errors and retries · Limits and retention

Integrations

JavaScript · MCP for agents · OpenAPI specification · Changelog

Try Optiview

See my site with Optiview · Run your free AI Audit

Explore

Publish · Parse · Retrieve · Pricing

Learn

Guides · Developer docs · Research & thinking · Experiments & methods · AI Audit · AI agent directory · FAQ

Company

About Optiview · Agencies · Contact · Privacy · Billing terms

Additional page links


Published brand narrative

Site-wide brand information

Who we are

Optiview — Parse, Retrieve and Publish for AI

Optiview helps businesses and developers make website information easier for AI to use. Parse converts supplied HTML into clean Markdown and source metadata. Retrieve fetches an eligible public HTTPS webpage and prepares its content. Publish helps a verified business prepare its own website content and make approved Narrative Graph context available through a supported connection.

Parse and Retrieve use application keys and a prepaid developer wallet. Publish has separate website setup, ownership checks and a subscription. Optiview does not control whether an outside AI service discovers, uses or cites the resulting content.

Applies to: Optiview

Why we matter

A clearer source, from website content to business context

Webpages mix useful information with navigation, layout and application code. Businesses may also have important qualifications, answers and context that are not clearly published.

Optiview gives developers a way to prepare source content for their applications, and gives businesses a way to publish the context their teams approve. Your application chooses how to use Parse and Retrieve results. Your business controls what it publishes through Publish.

Clearer publishing makes information available; it does not determine an AI system’s answer. Each outside service chooses its own retrieval, recommendations and citations.

What we offer

Three products, with separate jobs and clear pricing

Developer credits do not purchase Publish subscriptions. Parse and Retrieve do not add a customer’s private Narrative Graph to arbitrary third-party pages. See https://optiview.ai/pricing/ and https://optiview.ai/developers/ for the current offer and limits.

Why trust us

Inspect the output and understand what the evidence establishes

Developers can inspect the prepared Markdown, job status, source metadata, processing warnings and credit ledger. Retrieve records the public source response it observed; Parse identifies supplied HTML rather than claiming to verify the current origin.

Publish administrators can review parser output, the combined published-output preview, source checks and publication history. A preview is separate from a recorded live delivery. Saved edits remain separate from the active publication until explicitly published.

Our experiment pages contain selected first-party AI conversations and source comparisons. Delivery records establish what was served, not downstream ingestion, recommendations, citations or revenue. Observed language matches do not establish causation or a consistent visibility improvement. Explore the evidence and limitations at https://optiview.ai/proof/.

Helpful knowledge

Common questions about the three products

Which product should I use? Use Parse when you already have HTML. Use Retrieve when you need Optiview to fetch one eligible public page first. Use Publish when your business wants to prepare its verified website and publish approved context.

Do Parse and Retrieve require website ownership or DNS changes? No website connection is needed for these developer products. You remain responsible for source rights and permitted downstream use. Public availability does not grant a reuse license.

How do developer accounts and keys work? Create a developer workspace and save the personal sign-in key and offline recovery code. Create scoped service keys for server-side applications. Email is an unverified contact identifier, not account-ownership proof or an email-only recovery method. Keep all credentials private.

Can my agent use Optiview? The authenticated developer API returns prepared content for your application or model. A downloadable JavaScript client and local MCP adapter are available. Your host must authorize sources and any credit expenditure. Compatibility does not establish adoption or a partnership with an AI provider.

Does the API include my private Narrative Graph? Parse and Retrieve are source-only. Verified website publishing and approved publisher context belong to the separate Publish workflow.

Does Publish replace our website or CMS? No. Your website stays in its existing system. Your web team establishes and tests a supported connection. Your team reviews and explicitly publishes any Narrative Graph additions. Ordinary visitors retain the normal website experience.

Does every AI tool get the prepared version? No. Delivery depends on the website connection, source eligibility and the request. Some tools explicitly request Markdown; supported AI requests may also receive prepared Markdown or HTML through eligible delivery paths. Traditional search crawlers retain the original website response. A claimed tool name does not prove the requester’s identity.

Does the demo publish or save to our workspace? No. The public demo is a separate preview. Its AI-generated examples require review and do not transfer automatically into an approved publication.

Will Optiview guarantee citations or recommendations? No. Optiview prepares and publishes sources. Outside AI services choose what to retrieve, use and cite.

What to do next

Choose your starting point

Already using Publish? Review your Narrative Graph, publish approved changes explicitly, inspect the combined source in Markdown and check recorded delivery in Activity. Keep your existing visibility tools to study downstream AI answers.