Source: docs/public/integration/prompt-integrations.md
Browser prompt integrations
Use a prompt integration when an operator has supplied an approved bundle.
This browser-only API processes non-sensitive form data and returns a validated
JSON object. It is not a chat API. Do not add an API key, prompt, model name,
user identity or secret to browser requests. Exclude personal names, emails,
phone numbers and other personal data even if the form collects them locally.
For agent-assisted setup, use the two-step agent guide.
For a complete contract, see the FODA example.
Integration bundle
| Field | Description |
|---|---|
endpoint | HTTPS URL to send requests to |
origin | Configured HTTPS origin (must match exactly) |
turnstile_sitekey | Public Turnstile sitekey |
turnstile_action | Required action for rendering the widget |
input_schema | Exact accepted input fields and bounds |
output_schema | Exact shape and bounds of successful data; use it to build the UI |
Schemas and the sitekey are public integration metadata, not credentials.
Older bundles may lack the response schema: request it from the operator rather
than guessing. Do not copy sample schemas over an already approved contract.
Rendering Turnstile
Render only after the script has loaded. Both sitekey and action are required.
The following assumes integration contains your approved bundle:
<div id="turnstile-container"></div>
<script>
let widgetId;
let turnstileToken = null;
window.onTurnstileLoad = () => {
widgetId = turnstile.render("#turnstile-container", {
sitekey: integration.turnstile_sitekey,
action: integration.turnstile_action,
callback: (token) => { turnstileToken = token; },
"expired-callback": () => { turnstileToken = null; },
"error-callback": () => { turnstileToken = null; },
});
};
</script>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onTurnstileLoad&render=explicit" async defer></script>
Enable submission only with a token, valid input and no pending request.
Call directly from the approved browser origin, not a backend proxy. Localhost,
a tunnel or a different preview hostname is not automatically authorized.
Request and response
Send only the declared input and a fresh token. This example uses the field
from the FODA example; use your own bundle's input_schema:
const traceId = crypto.randomUUID();
try {
const response = await fetch(integration.endpoint, {
method: "POST",
headers: { "Content-Type": "application/json", "X-Trace-Id": traceId },
signal: AbortSignal.timeout(30000),
body: JSON.stringify({
input: { business_context: form.businessContext.value },
turnstile_token: turnstileToken,
}),
});
const body = await response.json();
if (!response.ok) throw new Error(body.error?.code ?? "PROMPT_INTEGRATION_FAILED");
renderResult(body.data); // textContent/DOM nodes, never untrusted innerHTML
} finally {
turnstileToken = null;
turnstile.reset(widgetId);
}
Handle errors and clear the loading state in the caller. On success, the
response is { "data": <object matching output_schema> }. Errors have
{ "error": { "code": "...", "message": "..." } } and contain no partial
model output. Treat all form values and returned content as untrusted.
The full request body is limited to 20 KiB and serialized input to 16 KiB.
Usage is attributed to the account that owns the integration; do not send
user_id for billing purposes.
Retry and failure handling
Tokens are single-use. Reset the widget after every submission, including
failures or client timeouts. Do not retry automatically. A timed-out browser
request may still have consumed quota and model usage.
| Code | Status | Action |
|---|---|---|
INVALID_JSON | 400 | Serialize the request envelope as JSON; this is not model-output JSON |
VALIDATION_ERROR | 422 | Read message: it identifies the first schema rule/field or the input byte limit |
ORIGIN_DENIED | 403 | Use the exact approved origin |
TURNSTILE_REQUIRED | 400 | Supply a fresh token |
TURNSTILE_INVALID | 403 | Check action and hostname; obtain a fresh token |
INTEGRATION_DISABLED | 404 | Contact the operator |
RATE_LIMITED / DAILY_QUOTA_EXCEEDED | 429 | Respect Retry-After; do not loop |
REQUEST_TOO_LARGE | 413 | Reduce input size within the approved contract |
MODEL_OUTPUT_TRUNCATED | 502 | Forgium's generation hit its output-token budget; contact the operator |
MODEL_OUTPUT_INVALID | 502 | Read message: missing model content, malformed model JSON, or the first output-schema failure |
INFERENCE_UNAVAILABLE | 503 | Model inference failed or timed out; report to the operator |
INTEGRATION_UNAVAILABLE | 503 | Stored integration schema could not be loaded; the operator must repair it |
TURNSTILE_UNAVAILABLE / RATE_LIMIT_UNAVAILABLE / QUOTA_UNAVAILABLE | 503 | Verification/protection/configuration is unavailable; contact the operator if it persists |
code remains the stable programmatic category. message explains the concrete
failure and the next action; it is human-readable text, not a string to match in
routing logic. The closed error envelope remains only code and message,
with messages bounded to 100 characters. No request values, generated content,
unknown field names, tokens or provider exception text are returned.
For example, a string beyond the approved input limit produces:
{
"error": {
"code": "VALIDATION_ERROR",
"message": "/business_context: maxLength is 4000. Input must match input_schema. Fix the reported field."
}
}
A model returning a string where the output contract requires an array produces:
{
"error": {
"code": "MODEL_OUTPUT_INVALID",
"message": "/strengths: must be array. Model output must match output_schema. Contact the operator."
}
}
Schema messages include the first failure and may abbreviate long paths/rules
within the message bound. Undeclared fields are reported without echoing their
names or values. Fix the reported input error and validate against the complete
bundle schema before another submission. For TURNSTILE_INVALID, messages
separately identify token rejection, an action mismatch or a hostname mismatch.
For either model-output error, share the error code, message, UTC time and the
X-Trace-Id you sent. Do not share form content or Turnstile tokens.
Do not loosen validation, alter the output contract or change the frontend
to repair server-side generation errors. An incognito window does not fix them.
New and updated integrations use a maximum of 2048 output tokens, including
JSON syntax. Keep schemas and requested answers concise; a schema being accepted
does not guarantee every possible answer fits. The operator must verify a real
representative inference before accepting the integration. Older integrations
need an operator update to adopt the new budget.
The burst limit is 3 requests per minute per integration/client IP. The daily
budget is configured by the platform per environment, not by browser input;
Turnstile-verified inference attempts can consume quota even when generation fails.
Contract
The public OpenAPI document is the source of truth for
execution. It describes the common envelope; the approved bundle supplies
the integration-specific input and response schemas. No server-to-server mode
or public management endpoint is provided.