Twofold v2.7

Search pages, sections and endpoints.

    Open the console

    Rate limits

    The per-key and per-provider limits, and what a 429 tells you to do.

    Environment

    Every request is counted against two budgets: the one belonging to the credential that authenticates it, and, for calls made with a provider's access token, the one belonging to that provider's link. Batch patient upserts are the exception: they count against a budget of their own instead of the provider limit.

    CredentialSustainedBurst
    Partner API key100 requests/second200
    Provider access token100 requests/second200
    Provider access token, batch patient upserts1 request/second2
    • The partner limit is per key, so each key you mint has its own budget.
    • The provider limit is per link, not per token. Refreshing a token does not reset it.
    • A third limit sits in front of authentication, keyed by source IP rather than by credential. It is a flood guard, set far above what an integration sends, so ordinary traffic never meets it. Requests that fail authentication do count against it, which is what it is there for.

    Batch patient upserts

    POST /v2/users/{externalUserId}/patients/batch has its own limit of 1 request a second per link, with a burst of 2. A batch never uses up the provider limit, so syncing a provider's list in batches leaves their other calls untouched. With up to 1,000 patients per batch, even a long patient list goes over in a few seconds. The source IP limit still applies.

    A batch request body can be up to 20 MB. A larger one is rejected with 400 and the request_body_too_large code, before any patient in it is written. Long patientContext values are what usually push a batch past it, so send fewer patients per request when they are long. The batch itself is described on Patients.

    A new provider's first sync

    Batches are the way to send a new provider's patient list. If you send it one patient at a time instead, there is an allowance for that: for the first 30 minutes after a provider links, their first 1,000 single patient upserts (PUT /v2/users/{externalUserId}/patients/{patientExternalId}) don't count against the provider limit. Send the initial patient list as fast as you like. The upserts are not throttled, and they don't use up the provider's budget for other calls either.

    The allowance belongs to the link. Once the 30 minutes pass or the 1,000 upserts are used, the provider limit applies again, so a list longer than 1,000 patients still needs to slow down for the rest. A provider who unlinks and links again gets a new allowance. Every other endpoint counts as usual during those 30 minutes, and so does the source IP limit.

    Over the limit

    You get 429 with the rate_limited type, the rate_limit_exceeded code, and a Retry-After header in seconds:

    text
    HTTP/1.1 429 Too Many Requests
    Retry-After: 2
    Twofold-Request-Id: req_ab12Cd34Ef56
    text
    HTTP/1.1 429 Too Many Requests
    Retry-After: 2
    Twofold-Request-Id: req_ab12Cd34Ef56
    json
    {
      "error": {
        "type": "rate_limited",
        "code": "rate_limit_exceeded",
        "message": "Too many requests. Retry after 2 seconds.",
        "requestId": "req_ab12Cd34Ef56"
      }
    }
    json
    {
      "error": {
        "type": "rate_limited",
        "code": "rate_limit_exceeded",
        "message": "Too many requests. Retry after 2 seconds.",
        "requestId": "req_ab12Cd34Ef56"
      }
    }

    Honour Retry-After — retrying sooner just consumes more of the window. Back off exponentially with jitter and cap the number of attempts; a retry storm against a limit you are already over is the one way to make it worse. The rest of the retry rules are on Errors.

    Sizing your traffic

    These limits are generous for the work the API is for. Send a provider's initial patient list as batches of up to 1,000, and use single upserts for the patients that change after that, one at a time or a few at once. When you see a 429, wait out Retry-After. Limits are per provider, so syncing several providers in parallel is fine.