How to Detect API Drift Before Your Customers Do
API drift — when your documentation diverges from your actual API — is silent until a developer hits a 404 or a parameter mismatch. This post explains the architecture behind DocsCI's drift detection engine and how to catch it in CI.
What is API drift?
API drift happens when the behavior your API actually exhibits diverges from what your documentation says it does. This manifests in several ways:
- A parameter is renamed in code but not in docs (
user_id→userId) - A field becomes required but docs show it as optional
- A response shape changes (new field added, old field removed)
- An endpoint is deprecated but docs show it as current
- Auth requirements change (e.g., new scope required)
The dangerous thing about drift is that it's asymmetric: it's easy to create and hard to notice. A single engineer makes a one-line change to the API contract. No alarm fires. The documentation stays wrong for weeks or months until a developer stumbles into the mismatch.
The three layers of API drift detection
DocsCI's drift detection works at three layers, which together cover the vast majority of real-world drift patterns:
Schema diffing (OpenAPI spec vs docs)
We parse your OpenAPI spec and extract the contract for each endpoint: path, method, required parameters, response schema. Then we parse your documentation and extract what it claims about those endpoints. Any mismatch is flagged.
# OpenAPI spec says: POST /users required: [email, plan] ← plan is required # Docs say: POST /users required: [email] ← drift: plan not documented as required
Live probe execution
We extract curl and HTTP examples from your docs and execute them against your staging environment. If the request fails, the response shape doesn't match, or the status code is wrong, it's flagged as drift.
# Docs example:
curl -X POST https://api.example.com/users \
-d '{"email":"user@example.com"}'
# Expected: 201
# Actual: 422 (missing required field 'plan')
# → DRIFT: plan is now requiredSDK execution diff
For companies with typed SDKs, we run SDK snippets from docs and compare method signatures against the installed SDK version. A TypeScript error means the docs show an API that the SDK no longer supports.
// Docs show:
const user = await client.users.create({
email: "user@example.com"
});
// SDK error: Property 'plan' is missing in type
// → DRIFT: plan is now required by the SDK typeSetting up drift detection in CI
The minimal setup requires two things: your docs archive and your OpenAPI spec URL. The workflow runs on every release tag (or every PR if you want tighter feedback loops):
# .github/workflows/drift-detect.yml
name: API Drift Detection
on:
push:
tags: ['v*'] # on every release
pull_request: # or on every PR
jobs:
drift:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Detect API drift
run: |
tar czf docs.tar.gz docs/ *.md
RESULT=$(curl -sf -X POST https://snippetci.com/api/runs/queue \
-H "Authorization: Bearer ${{ secrets.DOCSCI_TOKEN }}" \
-F "docs_archive=@docs.tar.gz" \
-F "openapi_url=https://api.example.com/openapi.json")
DRIFT=$(echo "$RESULT" | jq -r '.finding_breakdown.by_kind.drift_detected // 0')
echo "Drift findings: $DRIFT"
echo "$RESULT" | jq -e '.status == "passed"'Interpreting drift findings
DocsCI returns drift findings with three severity levels:
| Severity | Meaning | CI behavior |
|---|---|---|
| critical | Breaking change — docs show API behavior that will cause errors | Fails CI |
| warning | Mismatch detected but old behavior may still work | Warns, doesn't fail |
| info | New fields in API not yet documented | Informational |
The compound effect: drift + broken examples
The most damaging scenario combines drift with broken code examples: your API changes, which causes the curl example in your docs to return an error, which causes the SDK example to fail, which causes the test in your CI to break, which you fix by updating only the test — not the docs. DocsCI breaks this cycle by making the docs the first thing to fail when an API contract changes.
Try drift detection free
Connect your OpenAPI spec and get a full drift report in under 5 minutes.