Model APIs and gateways
The built-in OpenAI strict format distinguishes field issues (category: data and a field target) from semantic issues (no field target). The shared core still checks the real field owner, rule and references. It combines proof-backed redundant formal diagnoses while retaining semantic field problems and their clarification data. Custom executors, xAI, text mode and MCP host submissions use the shared candidate contract and the same core rules; they do not adopt OpenAI-only key or quote conventions.
Connect the model service you already use. First identify its protocol. JavaScript and TypeScript share the runtime API; the quick start gives a complete first call.
“OpenAI-compatible” does not necessarily include Responses. Check the service's actual endpoint. INTENT_MODEL and INTENT_API_KEY are variables the examples read; the library does not automatically read those names.
OpenAI / xAI Responses
Configure model and apiKey as nonempty strings, then pass executor to new Intent. For xAI, use provider='xai' with its model and credentials.
Connect your gateway
For a gateway exposing /v1/chat/completions, supply the API root without /chat/completions:
Replace the hostname, credentials, and model with your service's values. For a Responses-compatible gateway, set protocol='responses'. Pass executor to new Intent({executor}); parsing is unchanged. The openai provider selects a protocol preset; baseURL sends requests to your gateway.
JSON Schema structured output is the default. If the service only supports text output, set format='text' explicitly; it must still return candidate JSON matching the task for core validation. format does not switch protocols or automatically retry another format.
For provider='openai' and format='json_schema', both protocols send strict=true with an internal projection of the candidate Schema. Gateways must support OpenAI's strict subset; an unsupported gateway fails explicitly without automatic text fallback. xAI and explicit text mode keep their existing behavior.
The projection preserves required fields and rejects unsupported Schema shapes before any request with CONFIG_INVALID. Its private generation contract also constrains object identity, reference kinds and change states; the core still checks actual membership and semantic consistency. Registered SourceRef.quote fields are required on the wire. Current-input sources require the whole-input pointer and quote:null, restored to an omitted optional quote; this API path does not generate local input quotations. For other sources, null means omission, while an exact empty string or the string "null" remains a string. The reply is checked before this mapping; business nulls and JSON-encoded values are preserved. Duplicate JSON keys, missing fields, and unknown fields are rejected, without automatic repair. The unchanged core then checks sources, semantics, business rules, and the final result. Strict structure does not guarantee correct understanding. MCP host and custom executors retain their original source-quotation contract.
When a request has no declared or inherited business fields, the built-in OpenAI adapter can preserve a new, input-sourced constraint as text if its optional structured expression cannot be validated. Grounded expressions are retained. The constraint and its sources still undergo core validation.
Model parameters
Responses uses /responses; Chat Completions uses /chat/completions. Both set store=false and stream=false, send only current recognition material, omit business tools and implicit history, and do not retry or switch models. 401/403 are authentication failures; 429 is rate limiting. Refusal and incomplete generation have distinct errors; see Recovery.
Success and error bodies are bounded by bytes visible through Response.body after decompression, independently of Content-Length. Exactly the limit is allowed; exceeding it stops reading with RESOURCE_LIMIT/model. Redirects do not forward credentials. Check your actual provider's Schema support and quota; see Compatibility.
Custom ModelExecutor
A ModelExecutor is your adapter for calling the model. Reuse an SDK or HTTP call; you do not need to build another gateway service.
The flow is: user text → Intent prepares a task → your generate calls the model → candidate JSON text → Intent validates and assembles the final result.
Return {outcome:'complete', text:'model-generated candidate JSON'} on success, or refusal/incomplete when appropriate. text is not a final IntentResult. Do not assemble the final result yourself. See ModelExecutor.
The following complete example adapts real Chat Completions with an application header and maps choices[0].message.content into ModelReply. Prefer the built-in adapter for the standard protocol; for another protocol, change the request and text extraction.
This custom executor demonstrates protocol adaptation and uses non-strict generation. It does not include the built-in adapter's private Schema projection or codec. Its caller must obtain conforming candidate JSON; do not turn strict on with the unchanged outputSchema. For standard OpenAI structured output, use createApiExecutor.
Complete TypeScript: custom headers and reply mapping
Save as custom-executor-en.ts in an ESM project and set INTENT_GATEWAY_URL, INTENT_MODEL, INTENT_API_KEY. Use your TypeScript build, or:
INTENT_GATEWAY_URL is the complete endpoint, for example https://gateway.example.com/v1/chat/completions. This example calls fetch(url) and does not append a path. Set "type":"module" in package.json. It forwards signal to local fetch and bounds responses; remote cancellation follows your provider protocol. Preserve the candidate format and keep business execution outside recognition.
Clarification requests
Both OpenAI protocols use the current candidate schema. Strict wire schemas represent omitted optional candidate fields with null where required. An explicit business null stays encoded inside valueJson. Text recognition uses one request to the configured provider. Intent.parse settles structured-only replies locally with zero API requests.