# checkr-tenant

Integrate the Checkr Tenant API into this project so it can order tenant screenings and receive results, tested end-to-end in test mode.

Assume I may not be an experienced developer. Do as much as you safely can yourself. The only thing I must do by hand is create a test API key (step 3), and until I have one, keep building with mocks. Record every default you apply and why, so I can change it later (step 13).

SCOPE: Backend only (API client, order creation, result delivery, storage, tests). Never place live orders. When everything works, offer to build a simple screen to view results.

0. HOW TO WORK WITH ME.

   - Use plain language and short messages. The first time you use a technical term, explain it in a few words (for example, "webhook: Checkr calls your app when results are ready").
   - Before each major step, say in one line what you're about to do and why. After it, say in one line what changed.
   - When I need to do something, give exact clicks or commands for my operating system and shell, one numbered step at a time, and tell me how to check it worked.
   - When there's a choice, give 2 or 3 options, recommend one, and say why in one sentence. Ask one question at a time.
   - Do safe setup yourself: create files, add `.gitignore` entries, and add the project's standard test runner. Ask first before installing system software, creating accounts or cloud resources, changing hosting or deployment settings, adding dependencies, creating database migrations, or doing anything that costs money.

1. GROUND RULES. These apply to every step.

   - Use only `ckr_sk_test_…` keys. Never send a request with a `ckr_sk_live_…` key; live orders are real, billed screenings of real people.
   - Keep keys secret. Read them from environment variables or the project's secrets setup. Never ask me to paste a key into chat, and never print, hardcode, or commit one.
   - Never put the key anywhere a browser can see it: frontend code, or environment variables exposed to the browser (names starting with `NEXT_PUBLIC_`, `VITE_`, `REACT_APP_`, `EXPO_PUBLIC_`, or similar). Anyone could copy it and place orders on my account. All Checkr calls happen on the server.
   - Applicant data is sensitive (SSN, DOB, criminal, credit, eviction, income). Never log request or report bodies; log ids (`ord_…`, `rp_…`, `evt_…`) instead. Test-mode data in this file is synthetic, so you may read test responses to learn their shape and save sanitized test fixtures.
   - Landlords decide, code doesn't. Show results to the landlord; `consider` means "review before deciding", not "reject". Don't build automatic approve/deny logic unless I ask. If I do, tell me screening decisions carry legal obligations, such as FCRA adverse action notices, to review with a lawyer.
   - Sources, in order: the OpenAPI spec (step 4) for endpoints, fields, and shapes; this file for access, keys, billing, and defaults. The docs site's Getting Started guide may still describe an older access process (emailing Checkr, a required payment method); ignore it on those points. If the spec and this file disagree on anything else, follow the spec and list the mismatch in your report. If something isn't in either, choose the safest option and list it as an open question. Don't invent endpoints, fields, or values.

2. IF YOU GET STUCK. Don't just stop. Tell me in plain language what happened and why it matters, give 2 or 3 options with a recommendation, say the exact next action, and offer to do it. Keep working on everything the blocker doesn't affect.

   - No test key yet, or identity vetting not finished: give me the step 3 instructions, then keep building with mocks. If vetting is in review, tell me to wait for the completion email. Come back to steps 5, 6, and live tests when I say the key is saved.
   - My organization has access, but my user is not verified: another verified teammate may create the key, or I can finish my own vetting. Never ask anyone to send a key through chat or email.
   - The project has no server code: recommend server functions on the platform I already use, with the key in that platform's secret settings. The other option is a small separate backend in the project's language. Ask before creating anything in a cloud account.
   - No database: use the project's existing storage. If there is none, recommend my host's default database, or SQLite for local testing only, and flag that production needs a real database. Ask before creating cloud resources.
   - No test runner: add the ecosystem standard and tell me the one command that runs the tests.
   - No job system for polling: expose a function that checks open orders, and recommend a way to run it on a schedule.
   - You can't reach `tenant.checkr.com`: finish everything that doesn't need the network, then give me exact commands to run the key check and live tests locally. Ask me to share only the pass/fail summary, never keys or response bodies.
   - The API behaves differently from this file or the spec: retry once if it looks temporary. Otherwise keep the rest working and write a support message with the endpoint, status code, error `code`, and order id. Never include keys or applicant data.

3. TEST KEY. Look for `CHECKR_TENANT_API_KEY` in the environment and the project's secrets setup. Check only its prefix; never print it.

   - Starts with `ckr_sk_test_`: continue. If it's only in a file, load it into the shell without echoing it.
   - Starts with `ckr_sk_live_`: tell me to replace it with a test key, and don't call the API until I do.
   - Missing: set up the place for it, then give me these steps:
     1. Setup you do: use the project's existing secrets mechanism. Otherwise create the usual local secrets file (normally `.env`), add `CHECKR_TENANT_API_KEY=`, confirm the file is ignored, and add an empty entry to `.env.example`.
     2. Steps I do:
        a. Create an account at https://tenant.checkr.com/signup.
        b. Complete identity vetting at https://tenant.checkr.com/verify. If it goes to review, wait for the completion email. Test access unlocks automatically once vetting is verified.
        c. Create a Test key at https://tenant.checkr.com/settings/developer. Copy it immediately; it is shown only once.
        d. Save it as `CHECKR_TENANT_API_KEY` in the secrets file or panel, not in chat.
     3. Meanwhile, do steps 4 and 7 to 10 and the mocked unit tests in step 11. Return to step 5 when the key is saved.

   Test mode needs no payment method and no request to Checkr.

4. SPEC. Download the OpenAPI description to a temporary location, unless this project already generates clients from an OpenAPI file:

   - https://checkr-tenant-api-docs.redocly.app/_bundle/v1.json?download
   - https://checkr-tenant-api-docs.redocly.app/_bundle/v1.yaml?download

   If neither is reachable, use the quick reference at the end and list anything you couldn't verify as an open question.

   Every request uses base URL `https://tenant.checkr.com/api`, `Authorization: Bearer <key>`, and `Checkr-Tenant-Version: 2026-04-29`.

5. VERIFY THE KEY. Call `GET /orders?per_page=1` and report only the status code, never the key or response body.

   - `200`: continue.
   - `401`: the key is wrong or revoked. Tell me to create a new Test key and replace the old one. Keep building with mocks.
   - `403`: test API access is not active for this key's mode. Confirm the key starts with `ckr_sk_test_`, identity vetting shows Verified, and Developer settings allows key management. If those look correct, message support from https://tenant.checkr.com/developers without including the key or applicant data.

6. SMOKE TEST. Place one test order with a plain HTTP request to confirm the API works and capture real response shapes.

   - `POST /orders` with `Authorization`, `Checkr-Tenant-Version`, `Content-Type: application/json`, a new UUIDv4 `Idempotency-Key`, and:

     ```json
     {
       "order": {
         "package": "complete",
         "property": {
           "street": "1 Market St",
           "city": "San Francisco",
           "state": "CA",
           "zipcode": "94105"
         },
         "applicant": {
           "first_name": "Herbert",
           "last_name": "Humphrey",
           "email": "herbert.humphrey@example.com",
           "dob": "1996-04-27",
           "ssn": "111-11-1111"
         }
       }
     }
     ```

   - Expect `201`, an `id` containing `_test_`, and `live_mode: false`.
   - Poll `GET /orders/{id}` with backoff for at most 2 minutes until `status` is `completed`, then call `GET /orders/{id}/report`. If a non-null product still has a null status, poll the report the same way.
   - Expect `criminal_history.status` to be `consider`; credit, eviction, sex offender and global watchlist statuses to be `clear`; and `identity_verification` to be null.
   - On `422`, fix fields using `source.pointer` and retry with a new idempotency key. If it still fails or remains pending after 2 minutes, report only the order id and status, then follow step 2.
   - Save sanitized order and report responses as test fixtures, replacing mocks. Never save authorization headers.

7. INSPECT AND DECIDE. Inspect the project and follow its conventions. Before adding dependencies, creating migrations, or provisioning cloud resources, show me a short plan naming files, environment variables and storage changes, and wait for approval.

   Apply these defaults unless the project clearly points elsewhere:

   a. Screening party. Default to my own organization and omit `original_requester`. If the app clearly serves multiple landlord customers, send `original_requester` on every order with customer `external_id`, `type`, and name from the app's data.
   b. Trigger. Build a service function. Wire it to an obvious existing event; otherwise leave it unwired and say where to call it.
   c. Packages. Let the caller select `starter`, `essential`, or `complete`. Support `identity_verification` as an optional add-on, off by default.
   d. Applicant DOB and SSN. Don't collect them in production; let Checkr collect them. Accept optional values only because synthetic tests require them.
   e. Payer. Omit `payer`, so my organization pays.
   f. Delivery. Polling works with no setup. Also build a webhook receiver that is active only when `CHECKR_TENANT_WEBHOOK_SECRET` is set.
   g. Storage. Save Checkr order id, status, live mode, application URL, idempotency key, report id and product statuses. Don't persist full reports by default.
   h. Dependencies. Reuse existing tools. If a dependency is unavoidable, recommend the ecosystem standard and wait for approval.
   i. Location. Server-side only. In a monorepo, use the backend package closest to applications or leases.

8. BUILD THE CLIENT. One module, following project conventions:

   - Base URL, key and API version come from config.
   - Parse `{ errors: [{ code, detail, source: { pointer } }] }` into a typed error. Branch on `code`, never `detail`.
   - Retry `500` and network failures with capped backoff. Never retry `401`, `402`, `403`, `404`, or `422`, except polling's not-ready `404`.
   - Requests are rate limited per organization per minute, with test and live traffic counted separately. On `429`, honor `Retry-After`, read the limit from `X-RateLimit-Limit`, cap concurrent requests and do not start more pollers until the delay passes.
   - Live-only `402` codes: `no_payment_method` and `authentication_required` require billing action; `card_declined` requires a new idempotency key on retry.
   - Follow `next_href` for pagination. Never build cursors.
   - Use a read timeout of at least 60 seconds for report PDFs.

9. BUILD THE ORDER FLOW. `POST /orders` with `package`, plus `property` or `property_id`, plus `applicant` or `applicant_id`, never both forms for one association.

   - Create a new applicant per order; don't cache applicant ids against people.
   - Save a UUIDv4 idempotency key before calling and reuse it for network or `5xx` retries of the same logical order.
   - Store the fields from step 7g. The report id arrives later.
   - Map `422` errors to local validation fields using `source.pointer`.

10. BUILD RESULT DELIVERY.

    - Polling: for each open order, call `GET /orders/{id}` with capped backoff. On `completed`, fetch `GET /orders/{id}/report` and store the report id and statuses. On `canceled`, mark it canceled. Honor `429` and run live tests sequentially.
    - Webhooks: endpoints are registered manually in Developer settings and bound to one mode. Rely on `report.completed`, whose `data` is `{ id, order_id }`. The receiver must:
      1. retain the raw body before parsing
      2. return 2xx for the empty, unsigned dashboard test probe
      3. verify every `v1` in `Tenant-Signature: t=<unix>,v1=<hex>` using constant-time HMAC-SHA256 comparison
      4. reject stale timestamps using a configurable tolerance, default 300 seconds
      5. deduplicate event ids and return 2xx for duplicates
      6. enqueue work and return 2xx quickly
      7. ignore unknown event types with 2xx and use `created_at`, not arrival order
    - Products not ordered are null. Product statuses are `clear`, `consider`, or null while assembling. Show `consider` details without making an approval decision.

11. TEST IN TEST MODE. All scenario tuples use DOB `1996-04-27`; all four identity fields must match.

    | First   | Last     | SSN         | Consider on                                                                                  |
    | ------- | -------- | ----------- | -------------------------------------------------------------------------------------------- |
    | Herbert | Humphrey | 111-11-1111 | criminal                                                                                     |
    | Madelyn | Webster  | 222-22-2222 | credit                                                                                       |
    | Norma   | Davies   | 333-33-3333 | eviction (and identity verification when ordered)                                            |
    | Tim     | Watkins  | 444-44-4444 | criminal, credit, eviction, sex offender, watchlist (and identity verification when ordered) |
    | Hudson  | Green    | 555-55-5555 | nothing; runs the applicant flow                                                             |

    - For each profile, only products named in the table are `consider`; every other non-null screening product is `clear`. Income verification has a non-null status. Identity verification is null unless ordered as an add-on.
    - Most profiles skip applicant communications and return no application URL. Hudson runs the applicant experience.
    - Applicant Pay returns `422` in test mode. Idempotency keys do not replay test orders, so unit-test key reuse.

    Definition of done:

    1. Mocked client and signature unit tests pass without a key.
    2. With a test key, the Herbert complete-order smoke test passes through the built client and polling flow.
    3. One starter order confirms credit, eviction, income and identity verification are null.

    Extended suite, recommended after the minimum passes:

    - Madelyn, Norma and Tim complete-order scenarios, run sequentially.
    - Norma with the identity-verification add-on.
    - If step 7a selected the platform path, an `original_requester` order returning `original_requester_id`; otherwise skip and note why.
    - Optional Hudson applicant preview using a controlled email address.

12. NEXT STEPS FOR ME.

    - Webhooks: explain why they're faster, then give steps for a public HTTPS endpoint, a Test webhook in Developer settings, `CHECKR_TENANT_WEBHOOK_SECRET`, and a test order.
    - Going live: request production access from https://tenant.checkr.com/developers. After approval, create a live key in Developer settings, add a payment method unless invoiced, store the live key only in production, create a separate live webhook, surface billing errors, protect applicant data, and watch the first live order.
    - Applicant Pay is live-only. Read https://tenant.checkr.com/resources/application-screening-fee before using it because many states cap applicant screening fees.

13. REPORT. Start with three plain-language lines: what works now, what I need to do next, and the one command that runs tests. Then include:

    - smoke test result or that it is waiting on a key
    - files changed and why
    - defaults applied and why
    - secrets by environment and storage location
    - latest test results
    - applicant preview link, if created
    - next-step checklist
    - open questions and spec mismatches

QUICK REFERENCE. Use only if the spec cannot be fetched.

- Base URL: `https://tenant.checkr.com/api`. Test ids contain `_test_`.
- Endpoints: `POST|GET /orders`, `GET /orders/{id}`, `GET /orders/{id}/report`, `GET /reports/{id}`, `GET /reports/{id}/pdf`, `POST|GET /applicants`, `GET /applicants/{id}`, `POST|GET /properties`, `GET /properties/{id}`.
- Order input: `{ "order": { package, property | property_id, applicant | applicant_id, add_on_products?, original_requester | original_requester_id?, payer? } }`.
- Order statuses: `waiting_for_applicant`, `pending`, `completed`, `canceled`.
- Report products: criminal, credit, eviction, identity verification, income verification, sex offender registry and global watchlist. Each is null or has `id` and `status`.
- `GET /orders/{id}/report` returns `404` until ready.
- Lists: `{ object, count, next_href, previous_href, data }`.
- Errors: `401 authorization_error`, live-only `402` billing codes, `403 forbidden`, `404 not_found_error`, `422 validation_error`, `429 too_many_requests`, `500 internal_error`.
- Webhook body: `{ id, object: "event", type, created_at, data }`.

More: https://checkr-tenant-api-docs.redocly.app/ (also `/testing`, `/webhooks`, `/errors`, `/mcp-server`).
