Skip to content

Quickstart

This walks through a sign-up form, end to end, in the sandbox. You need a sandbox account and access to the console.

In the console, open API keys and create two sandbox keys:

  • A publishable site key (oc_pk_test_…) for the browser tag. It is public by design and can only send signals. Add your site’s hostname to its allowed domains (a sandbox key with no domains accepts any origin, for quick setup).
  • A secret key (oc_test_…) with the decide and outcomes scopes, for your server. It is shown once; store it in your secret manager.

Load the tag on the page with your form, and mark the form with data-collect:

<script src="https://c.opencontext.com/t.js" data-key="oc_pk_test_…" async></script>
<form method="post" action="/signup" data-collect="signup">
<input name="email" type="email" autocomplete="email" required>
<input name="password" type="password" autocomplete="new-password" required>
<button>Create account</button>
</form>

When the form is submitted, the tag collects signals, adds a hidden request_id field, and submits the form. If anything goes wrong it submits anyway, so the tag never blocks a customer. For production, serve the tag from a path on your own site; see Browser tag.

On your server, read request_id from the form and call the decision API with your secret key:

Terminal window
curl https://api.opencontext.com/v1/decision \
-H "Authorization: Bearer $SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"request_id": "req_01M8YGM5XB0RJ7S2N1Q4ZK6W3D",
"event_type": "signup",
"account_id": "cust_1842",
"email": "pat@example.com",
"ip": "198.51.100.7",
"user_agent": "Mozilla/5.0 ..."
}'

The same call in Node:

const res = await fetch("https://api.opencontext.com/v1/decision", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.SECRET_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
request_id: req.body.request_id,
event_type: "signup",
account_id: user.id,
email: req.body.email,
ip: req.ip,
user_agent: req.get("user-agent"),
}),
signal: AbortSignal.timeout(1500),
});
const decision = await res.json();
switch (decision.recommendation) {
case "allow": return createAccount();
case "step_up": return askForVerification(); // email code, passkey, or agent proof
case "review": return createAccount({ hold: true }); // your team or the fraud manager reviews it
case "deny": return refuse();
}

Keep decision.decision_id with the account or order. You will report outcomes against it.

When you learn more (a chargeback, a good repayment, an analyst’s call), tell us:

Terminal window
curl https://api.opencontext.com/v1/outcomes \
-H "Authorization: Bearer $SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{ "request_id": "dec_01M8YGM5XC012R9ZCQKTSX9RR7", "outcome": "confirmed_good", "outcome_type": "paid_in_full" }'

If an agent is doing this integration, these are the facts it needs:

  • Keys come from environment variables. The secret key (oc_test_…) stays on the server; only the publishable key (oc_pk_test_…) goes in the page. Sandbox keys see sandbox data only, so testing is safe.
  • The tag never blocks a form and the decision call should never block your product: use a timeout of about 1.5 seconds and pick a fallback per event type (most teams allow logins and sign-ups for review, and hold payouts).
  • To verify the integration, submit the form once and look for the decision in the console’s Transactions page. A no_request_id warning on the decision means the tag did not run.
  • Every error has a stable code and says how to fix it. See Errors.
  • A person turns on production. An agent can integrate and test in the sandbox; live keys are created by a person on the account.
  • Task-sized guides: sign-up in Next.js, AI agents at login, and credential stuffing. Machine-readable docs: https://docs.opencontext.com/llms.txt and the OpenAPI contract.
  • How it works: the flow from page to decision.
  • Decisions: every field in the response, and how to use it.
  • Rules: change what the recommendation is for each event type.