Check multiple authorizations in a single request
The BatchCheck API functions nearly identically to Check, but instead of checking a single user-object relationship BatchCheck accepts a list of relationships to check and returns a map containing BatchCheckItem response for each check it received.
An associated correlation_id is required for each check in the batch. This ID is used to correlate a check to the appropriate response. It is a string consisting of only alphanumeric characters or hyphens with a maximum length of 36 characters. This correlation_id is used to map the result of each check to the item which was checked, so it must be unique for each item in the batch. We recommend using a UUID or ULID as the correlation_id, but you can use whatever unique identifier you need as long as it matches this regex pattern: ^[\w\d-]{1,36}$
Note: The maximum number of checks that can be passed in the
BatchCheckAPI is configurable using the environment variable:[OPENFGA_MAX_CHECKS_PER_BATCH_CHECK](https://openfga.dev/docs/getting-started/setup-openfga/configuration#OPENFGA_MAX_CHECKS_PER_BATCH_CHECK). IfBatchCheckis called using the SDK, the SDK can split the batch check requests for you.
For more details on how Check functions, review the docs for /check.
Examples
A BatchCheckRequest
{
"checks": [
{
"tuple_key": {
"object": "document:2021-budget"
"relation": "reader",
"user": "user:anne",
},
"contextual_tuples": {...}
"context": {}
"correlation_id": "01JA8PM3QM7VBPGB8KMPK8SBD5"
},
{
"tuple_key": {
"object": "document:2021-budget"
"relation": "reader",
"user": "user:bob",
},
"contextual_tuples": {...}
"context": {}
"correlation_id": "01JA8PMM6A90NV5ET0F28CYSZQ"
}
]
}
Below is a possible response to the above request. Note that the result map’s keys are the correlation_id values from the checked items in the request:
{
"result": {
"01JA8PMM6A90NV5ET0F28CYSZQ": {
"allowed": false,
"error": {"message": ""}
},
"01JA8PM3QM7VBPGB8KMPK8SBD5": {
"allowed": true,
"error": {"message": ""}
}
}
Path Parameters
Body
1"01G5JAVJ41T49E9TT3SKVS7X1J"
Controls the consistency preferences when calling the query APIs.
- UNSPECIFIED: Default if not set. Behavior will be the same as MINIMIZE_LATENCY.
- MINIMIZE_LATENCY: Minimize latency at the potential expense of lower consistency.
- HIGHER_CONSISTENCY: Prefer higher consistency, at the potential expense of increased latency.
UNSPECIFIED, MINIMIZE_LATENCY, HIGHER_CONSISTENCY "MINIMIZE_LATENCY"
Response
A successful response.
Map keys are the correlation_id values from the BatchCheckItems in the request.