Fail Your CI Build When Your API Breaks: a 5xx, Contract and Latency Gate (2026)

Updated 2026-11-23

Your end-to-end suite is green. Meanwhile, during that run, the API it talks to answered three requests with a 502, returned a user without the name field the OpenAPI spec says is required, and took 1.4 seconds at p95 on the endpoint your checkout page waits for. None of that failed a test, because no test asserted on it.

Writing those assertions into every test is a lot of code that rots. There is a cheaper place to check: the traffic itself. If the tests run through a proxy that records every request and response, one call after the run can answer "did anything in there break the rules?"

That is what Proxycept's CI verdict does. You point your tests at a Proxycept profile, run them, then fetch:

GET /api/sessions/{session_id}/verdict?fail_on=5xx,contract,latency_p95_ms=800

and get back pass, fail or inconclusive, as JSON or as a JUnit report your CI already knows how to display.

What the verdict checks

You pick the rules with fail_on, a comma-separated list. The default is 5xx,contract.

Rule Fails when
5xx any response in scope had a 5xx status
4xx any response in scope had a 4xx status (off unless you ask for it: many suites expect some 4xx)
contract a response does not match the OpenAPI spec uploaded to the workspace: malformed JSON, a status the spec does not list, a missing required field, a wrong type, an extra field where additionalProperties: false, an enum mismatch
latency_p95_ms=N an endpoint's p95 response time is over N milliseconds

Endpoints are grouped the same way as the session's latency table: method, host and path, with the query string dropped and id-like segments folded, so /users/81723 and /users/81724 are one endpoint, /users/{id}.

The contract rule checks response types and shapes against the spec. It does not validate requests and it is not a full OpenAPI conformance suite.

Three answers, not two

A gate that says "pass" when it did not actually look is worse than no gate. So the verdict has a third answer:

  • pass: every rule ran over every flow in scope and found nothing.
  • fail: at least one rule found a problem. The JSON lists each failing endpoint, which rule it broke, and up to five flow ids you can open in the console.
  • inconclusive: nothing failed, but the check could not cover everything, or had nothing to check. The reasons are spelled out in inconclusive_reasons:
    • no_flows_in_scope: no traffic was captured. Usually the tests did not go through the proxy.
    • contract_report_truncated: the run produced more flows than one contract check reads (5,000).
    • contract_budget_exhausted: the contract check hit its time or validation budget.
    • contract_responses_not_fully_checked: some responses were too large to parse, were cut off when captured (bodies are stored up to 64 KB), or were only partly validated.
    • no_flow_matched_the_spec: the traffic never reached an operation in the spec (wrong server base path, or the wrong spec).
    • flows_truncated / no_measured_latency: the latency rule could not read the whole run, or every response was mocked and has no measured time.
    • no_rule_ran: every rule you asked for was skipped (for example fail_on=contract in a workspace with no spec).

A failure found in part of the traffic is still a failure, so fail wins over inconclusive. The 5xx and 4xx counts are always exact: they are counted over the whole scope, never sampled.

If the workspace has no OpenAPI spec, the contract rule is reported as skipped and the other rules still run. A skipped rule does not make the verdict inconclusive on its own, but a verdict whose every rule was skipped is (no_rule_ran): it checked nothing.

Set it up

You need:

  1. A Proxycept profile that your CI uses. Start it once in the console and leave it running.
  2. Its proxy URL with credentials, from the profile's Connect tab, stored as a CI secret (PROXYCEPT_PROXY_URL). API tokens are never given proxy credentials, so this comes from the console. The password stays the same while the profile keeps running; it changes if the profile is stopped and started again, so do not stop it from CI.
  3. A personal API token (prx_live_…, Settings → API tokens) as PROXYCEPT_TOKEN. A read_write token can also start the profile; a read token is enough for everything else.
  4. Optional: the API's OpenAPI spec uploaded to the workspace, for the contract rule.

The script

Save this as proxycept-ci.sh and run your test command through it, for example ./proxycept-ci.sh npm test. It needs curl and jq.

#!/usr/bin/env bash
# Run a test command through Proxycept, then gate the build on the verdict.
# Exit codes: 0 pass · 1 fail · 2 inconclusive · 3 the verdict could not be fetched.
# A failing test command exits with its own code, as it would without this script.
set -euo pipefail

API="${PROXYCEPT_API:-https://proxycept.com/api}"
AUTH="Authorization: Bearer $PROXYCEPT_TOKEN"
PROFILE_ID="$PROXYCEPT_PROFILE_ID"
RULES="${PROXYCEPT_FAIL_ON:-5xx,contract,latency_p95_ms=800}"

# 1. Make sure the profile is running. Idempotent; it returns no session id.
#    (Skip this line if you use a read-only token and keep the profile running.)
curl -fsS -X POST -H "$AUTH" "$API/profiles/$PROFILE_ID/start" > /dev/null

# The profile's open capture session, if it has one. A session is opened by the first
# request the profile captures, so a freshly started profile may not have one yet.
open_session() {
  curl -fsS -H "$AUTH" "$API/sessions/active?profile_id=$PROFILE_ID" |
    jq -r 'if .session != null and .session.ended_at == null then .session.id else empty end'
}

# 2. Note where this run starts: the newest flow so far. With no open session yet, every
#    flow in the session the tests open is this run's, so there is nothing to note.
BEFORE=$(open_session)
AFTER=""
if [ -n "$BEFORE" ]; then
  AFTER=$(curl -fsS -H "$AUTH" "$API/sessions/$BEFORE/flows?limit=1" | jq -r '.[0].id // empty')
fi

# 3. Run the tests through the proxy. Only the test command gets the proxy settings,
#    so the API calls this script makes are not captured.
curl -fsS -H "$AUTH" "$API/ca/certificate" -o proxycept-ca.pem
set +e
P="$PROXYCEPT_PROXY_URL"
HTTPS_PROXY="$P" HTTP_PROXY="$P" https_proxy="$P" http_proxy="$P" \
  NODE_EXTRA_CA_CERTS="$PWD/proxycept-ca.pem" \
  "$@"
TESTS=$?
set -e

# 4. Give the last captured flows a few seconds to be stored, then find the session.
sleep 5
SESSION_ID=$(open_session)
if [ -z "$SESSION_ID" ]; then
  echo "Proxycept captured nothing: did the tests use the proxy?" >&2
  [ "$TESTS" -eq 0 ] || exit "$TESTS"
  exit 2
fi
[ "$SESSION_ID" = "$BEFORE" ] || AFTER=""  # a new session holds only this run's flows

# 5. Fetch the verdict for this run only. --retry also covers a 429 (busy) answer.
QUERY="fail_on=$RULES${AFTER:+&after_flow_id=$AFTER}"
if ! VERDICT=$(curl -fsS --retry 5 -H "$AUTH" "$API/sessions/$SESSION_ID/verdict?$QUERY"); then
  echo "Could not fetch the Proxycept verdict" >&2
  [ "$TESTS" -eq 0 ] || exit "$TESTS"
  exit 3
fi
echo "$VERDICT" | jq '{result, inconclusive_reasons, rules: [.rules[] | {rule, status, failed_flows}]}'

[ "$TESTS" -eq 0 ] || exit "$TESTS"
case "$(echo "$VERDICT" | jq -r .result)" in
  pass) exit 0 ;;
  fail) exit 1 ;;
  inconclusive) exit 2 ;;
  *) exit 3 ;;
esac

NODE_EXTRA_CA_CERTS is for Node. Node's built-in fetch also ignores HTTPS_PROXY unless you set NODE_USE_ENV_PROXY=1 (Node 24 and later) or give it a proxy agent; if a Node suite comes back no_flows_in_scope, that is the first thing to check. Trust proxycept-ca.pem the way your test runtime expects: REQUESTS_CA_BUNDLE for Python requests, the JVM trust store for Java, and so on (see HTTPS and the CA).

Whether inconclusive (exit 2) should fail your build is your call. Most teams start by treating it as a warning and look at the reason; no_flows_in_scope almost always means the proxy settings did not reach the test process.

A JUnit report in the same call

Add format=junit and the same verdict comes back as JUnit XML: one test case per endpoint, with a <failure> naming the rules it broke, plus one test case per rule: a <failure> when the rule failed, <skipped> when it was skipped and <error> when it was inconclusive, so the report's totals always agree with the result. The result is also in the X-Proxycept-Verdict response header, so you can gate on it without parsing the XML:

curl -fsS --retry 5 -H "$AUTH" -D verdict.headers -o proxycept-verdict.xml \
  "$API/sessions/$SESSION_ID/verdict?$QUERY&format=junit" || exit 3
RESULT=$(tr -d '\r' < verdict.headers | awk -F': ' 'tolower($1) == "x-proxycept-verdict" { print $2 }' | tail -n 1)
case "$RESULT" in pass) exit 0 ;; fail) exit 1 ;; inconclusive) exit 2 ;; *) exit 3 ;; esac

Point your CI's test-report step (GitLab artifacts:reports:junit, Jenkins junit, the GitHub Actions test-report actions) at proxycept-verdict.xml.

One profile, several pipelines

A profile has one open session at a time, so two CI runs on the same profile write into the same session. Three query parameters narrow the verdict to one run:

  • after_flow_id: only flows captured after that flow. The script above records the newest flow before the tests start (when the profile has no open session yet, the session the tests open holds only their traffic, so it needs no anchor).
  • since: only flows captured at or after an ISO-8601 time, for example since=2026-11-23T10:15:00Z. Simpler, but it depends on your CI runner's clock.
  • host: only flows to one host, for example host=api.staging.example.com.

These narrow by time and host, not by caller. If two pipelines overlap in time and call the same host through the same profile, each verdict sees both runs' traffic. Give each pipeline its own profile when that matters (how many profiles can run at once depends on the plan; see pricing).

Limits worth knowing

  • The contract rule reads up to 5,000 flows per verdict and has a time budget. Larger runs come back inconclusive, never pass.
  • The latency and per-endpoint view reads the newest 20,000 flows in scope and lists up to 500 endpoints, failing ones first.
  • At most two contract checks run at once. A verdict that finds both busy is answered 429 with Retry-After; curl --retry waits and tries again.
  • A request answered by a mock has no measured time, so it is left out of p95 rather than counted as 0 ms.
  • The verdict echoes method, host, the normalized path and flow ids. It never echoes bodies, query strings or header values, and contract messages name the kind of problem, not the captured value.

Try it

Create a free account, start a profile, run one test suite through it, and open the session: the latency table and the contract panel show the same numbers the verdict gates on. API tokens and the rest of the API are described under API & automation; GET /api/sessions/{id}/verdict is open to any workspace member, viewers included.

Try Proxycept free

One hosted proxy endpoint for every device, emulator, and CI runner. Shared captures, no per-machine install.

Start free