canonry

OpenAI Provider Design

Role

packages/provider-openai sends tracked queries to the OpenAI Responses API with web search. Canonry uses the answer text for mentions and URL citation annotations for cited domains.

Provider Contract

validateConfig(config: OpenAIConfig): OpenAIHealthcheckResult

Validates that the config has a non-empty API key. Returns the model name that will be used.

healthcheck(config: OpenAIConfig, signal?: AbortSignal): Promise<OpenAIHealthcheckResult>

Makes a lightweight OpenAI API call to verify the key works. Returns ok/error with a message.

executeTrackedQuery(input: OpenAITrackedQueryInput): Promise<OpenAIRawResult>

Sends the unchanged query to the OpenAI Responses API without instructions. The adapter requires the web_search tool and sends a requested location in user_location. See Retrieval contract. The result includes these fields.

normalizeResult(raw: OpenAIRawResult): OpenAINormalizedResult

Extracts analyst-relevant fields from the raw response:

Retrieval contract

OpenAI records search-required-v1 in query_snapshots.retrieval_contract. The request sends tool_choice: "required" with web_search as its only tool. Adding another tool changes that contract, since required lets the model select from the tools in the request. These observations measure the Responses API. The cdp:chatgpt browser adapter measures the ChatGPT web UI separately.

Retrieval detection

retrievalStatus is read from the response, not assumed from the contract:

Response retrievalStatus
any web_search_call output item (any action: search, open_page, find_in_page; with or without a query) used
Nonempty output, status: "completed" or omitted, and no web_search_call item not-used
no search call and status is incomplete, failed, or any other unfinished state unknown
output missing, not an array, or empty unknown

unknown never collapses into not-used: only an intact response can prove that no search happened. Under forced search nearly every row reads used; that is the contract holding, and a not-used row is the visible breach.

Stored rows labelled native-auto-v1

Releases 4.139.0 (the first to record a contract) through 5.19.0 labelled OpenAI rows native-auto-v1 and retrievalStatus: unknown, although every one of those releases sent the identical forced-search request above. The label was wrong, not merely old, and left alone it would show a contract change at the upgrade where the method never changed. canonry backfill answer-visibility corrects those rows: native-auto-v1 becomes search-required-v1, and the status is re-derived from the stored apiResponse (left unknown when no payload was stored). It reports the count as retrievalRelabeled, touches no other provider, and never moves a row already on search-required-v1. Rows with a NULL contract predate the field and stay NULL: early releases wrapped the query in a search prompt, so those rows were not all built one way.

Model

Default: gpt-5.4. Configurable via OpenAIConfig.model.

Custom Endpoint

Optional. Set OpenAIConfig.baseUrl — via the OPENAI_BASE_URL env var or providers.openai.baseUrl in ~/.canonry/config.yaml — to route requests through a proxy or gateway in front of the OpenAI API. It maps to the SDK’s baseURL. When unset, the SDK uses its default endpoint (https://api.openai.com/v1).

Web Search & Citation Detection

The provider uses OpenAI’s web search tool (web_search, the current GA tool — released 2025-08-26 in the SDK as web_search_2025_08_26). When enabled, the Responses API:

  1. Executes web searches relevant to the query (exposed as web_search_call output items)
  2. Generates a response with inline URL citations
  3. URL citations appear as annotations on output_text content blocks

Citation detection works by extracting domains from final output_text.annotations entries where type === 'url_citation'. The provider intentionally does not treat web_search_call.action.sources as citations, because those are retrieval/search telemetry rather than final answer citations. The job runner then matches the cited domains against the project’s canonical domain and competitor domains to determine citation state.

We deliberately do not set the new web_search tool’s filters.allowed_domains — Canonry tracks who actually gets cited across the open web, so allow-listing would defeat the point. web_search (GA) is used over the legacy web_search_preview for the same reason: measure the open web as users see it.

Upstream references

Domain extraction

Quota Defaults

Quota policy is passed via OpenAIConfig.quotaPolicy but enforcement is handled by the job runner (not the provider itself).

Data Stored per Snapshot

The job runner stores the following in query_snapshots.raw_response as JSON:

{
  "model": "gpt-4o",
  "groundingSources": [
    { "uri": "https://example.com/page", "title": "Page Title" }
  ],
  "searchQueries": ["keyword related search"],
  "apiResponse": { "output": [...] }
}

retrieval_status and retrieval_contract are separate query_snapshots columns, not part of this envelope.

Implementation Status

Live OpenAI API calls implemented with Responses API web search. The openai SDK is used for API communication.