View as Markdown

Identify · Guide

Write a traffic policy

Write a traffic policy to decide what each agent and bot may do: allow it, block it, rate-limit it, hand it to your own challenge, or require the person behind it to approve. Traffic policies use the same versioned policy format as every product, with simulate, shadow mode and lists.

Before you begin: export the sandbox account key.

export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5

A rule has conditions (when, all must hold) and an outcome (then). The first matching rule wins; with no match, default applies (allow unless you set it).

then.actionWhat happens
allowThe request passes.
block403 with a generic "blocked" body. What the client gets is yours to choose: see Decide what to return.
log_onlyThe request passes and the decision is recorded.
rate_limitAt most max requests per window_seconds, counted per ip, agent, human (pseudonym) or operator. Over it: 429 with Retry-After.
challengeYour onChallenge hook runs, so you can hand off to the challenge you already use.
require_intent401 with a ProvenanceIntent challenge until the request carries the person's approval. See Require a human.

1. Start from a template

curl -s $PROVENANCE_API/v1/identify/policy_templates \
  -H "Authorization: Bearer $PROVENANCE_KEY" | jq '.data[].id'
"welcome_shopping_agents"
"block_ai_training"
"rate_limit_unknown_bots"
"require_human_account_changes"
"accept_verified_protocols"
"slow_down_scrapers"
"agent_checkout_approval"

slow_down_scrapers allows published search crawlers and signed agents, challenges a client that reads more than 120 pages in five minutes, and holds one whose requests look like a crawl (scraping_suspected) to 30 pages a minute, on browse and search only. It never rejects. See Slow down scrapers.

2. Save a policy

Conditions read the verdict's facts. The agent facts have the names checkout and agent rules use. Each fact takes the engine's operators, plus contains for signals:

FactExample values
agent.classsigned_agent, declared_bot, suspected_bot, likely_human, unknown
agent_categorysearch_crawler, ai_training_crawler, ai_assistant_fetch, shopping_agent, monitoring, other_agent
actionyour route map's names: browse, checkout, login, account_change
agent_id, operator, agent_directory, pseudonymmatch exactly, or test with in_list against a list
agent.platform, agent.platform_sourceopenai, anthropic, google, microsoft, apple, perplexity, meta, common_crawl; signed or declared (which platform sent it)
human_backed, intent_valid, biometric_bound, agent.verifiedtrue or false
agent.bot_score, vendor_scorenumbers, compared with gt, gte, lt, lte
signalscontains a signal code
protocol, protocol_status, protocol_kindap2, acp, x402; verified, unverified, invalid; checkout_mandate, payment_mandate, checkout_session, payment (protocols)
protocol_amount, protocol_payeethe verified amount in minor units, and the payee (in_list against your payees)
curl -s -X PUT "$PROVENANCE_API/v1/identify/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": {
      "rules": [
        { "id": "block-training", "when": [{ "fact": "agent_category", "op": "eq", "value": "ai_training_crawler" }], "then": { "action": "block" } }
      ],
      "default": "allow"
    }
  }'
{ "object": "policy_version", "domain": "traffic", "version": 1, "active": true, "note": null }

The middleware picks up the new version on its next bundle refresh, within five minutes.

In the console, Rules › Traffic edits the same document one rule at a time: each rule reads the facts above in words ("Who it is is Signed agent"), and takes one outcome: Allow, Challenge, Challenge with the person's approval (require_intent), Reject, Rate limit or Log. The Otherwise row is the document's default. A rule you turn off keeps its place with enabled: false and never runs. Edit as JSON, with simulate and shadow mode, is under More.

3. Simulate before you rely on it

curl -s "$PROVENANCE_API/v1/identify/policies/simulate" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "facts": { "class": "signed_agent", "agent_category": "ai_training_crawler" } }'
{ "object": "policy_simulation", "domain": "traffic", "action": "reject", "then": { "action": "block" }, "policy": { "id": "pol_3F9A1C7E52B04D8E6A1F27C9B4", "version": 1, "rule": { "id": "rul_01JDMRSCXHRC0FAR7CRZ9067GS", "name": null, "phase": "assess", "action": "reject", "conditions": [{ "fact": "agent_category", "op": "eq", "value": "ai_training_crawler", "actual": "ai_training_crawler" }] } } }

4. Backtest it on your recorded traffic

POST /v1/identify/policies/backtest replays your last 30 days of recorded decisions through a draft and says what would have changed, including how many of the visits it would block or challenge went on to place an order. See Backtest traffic rules.

5. Roll out in shadow mode

Run a new version as the shadow with POST /v1/identify/policies/versions/{version}/shadow. The middleware evaluates it on live traffic and reports what it would have done in decision.shadow, without enforcing it. Compare with GET /v1/identify/policies/shadow_report, then activate the version when the divergence is what you expect.

Decide what to return

A rejected or rate-limited client gets a generic machine-readable "blocked" body by default, with no rule id and no reason, so a well-behaved agent can tell it was blocked and a scraper can't tell by which rule:

{ "type": "https://provenanceauth.com/problems/traffic-blocked", "title": "Blocked", "status": 403, "detail": "This site's traffic policy doesn't allow this request." }

The rule id and reason stay with you: in the verdict's policy block, the recorded decision, the console and webhooks. Set respond on a block or rate_limit rule to choose something else, or on the policy itself to change the default for every rule. Identify and Trace share these kinds, so a kind means the same in both.

respond.kindWhat the client gets
not_possibleThe generic body above (the default). include_rule: true and include_reason: true put the rule id and reason back.
messageThe same body with detail set to your text (at most 200 characters).
status_only403, 404 or 429 with an empty body.
pageA status and one of your stored pages (POST /v1/identify/response_templates with purpose: "block").
empty200 with {} or an empty HTML page. Read actions only (browse, search).

rate_limit keeps Retry-After on every kind except empty. empty is refused when a rule can match anything but a read action: add a condition { "fact": "action", "op": "in", "value": ["browse", "search"] }. If a request reaches it on another action anyway, the client gets not_possible. The verdict's decision.respond names the kind the client received, and fallback says why when the rule's own kind couldn't be served (a missing template, a request that isn't a read).

{
  "rules": [
    {
      "label": "Retired pages",
      "when": [{ "fact": "path", "op": "matches", "value": "/old/*" }],
      "then": { "action": "block", "respond": { "kind": "page", "status": 404, "template_id": "irt_01JDTESTTEMPLATE00000000000" } }
    },
    {
      "label": "Suspected bots searching",
      "when": [{ "fact": "agent.class", "op": "eq", "value": "suspected_bot" }, { "fact": "action", "op": "eq", "value": "search" }],
      "then": { "action": "block", "respond": { "kind": "empty", "content_type": "application/json" } }
    }
  ],
  "respond": { "kind": "message", "message": "This request isn't available." }
}

The middleware serves stored pages from its policy bundle, with no fetch per request. A template is refused at delete while a rule names it.

Errors you might see

SymptomCauseFix
400 policy_invalidA fact, operator or action isn't one of the documented valueserror.details names the rule and field.
400 policy_invalid with respond_not_allowed_for_actionempty on a rule that can match checkout, login or another writeAdd an action condition on browse and search only.
409 response_template_in_useA rule still names the template you're deletingChange the rule first.
402 trial_endedThe Free trial ended, and custom traffic policies are on Pro and upChoose a plan in Settings → Plan & usage; see plans and usage.
A rule never matches a signed agentThe agent isn't registered with Provenance, so it has no agent_categoryMatch on agent_directory or operator instead.

See also