> For the complete documentation index, see [llms.txt](https://docs.griaule.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.griaule.com/apis/gbds-5/key-format.md).

# Key Format

## List key formats

> Returns all configured key formats used by API-side key validation. Each item describes a \`keyId\` and its constraints: \`formatType\` (\`CPF\`, \`TITULO\`, \`REGEX\`, \`ALPHANUMERIC\`, \`ALPHABETIC\`, \`NUMERIC\`), optional \`regex\` (when \`formatType=REGEX\`), and optional \`minLength\`/\`maxLength\`. Use this endpoint to inspect which formats are currently enforced by the API during enroll/update when key-format validation is enabled.

```json
{"openapi":"3.0.1","info":{"title":"GBDS API","version":"5.1.16"},"servers":[{"url":"http://<ip>:8085/gbds/v2"}],"paths":{"/keyFormat":{"get":{"tags":["key-format"],"operationId":"list_7","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ListKeyFormatResponse"}}}}},"description":"Returns all configured key formats used by API-side key validation. Each item describes a `keyId` and its constraints: `formatType` (`CPF`, `TITULO`, `REGEX`, `ALPHANUMERIC`, `ALPHABETIC`, `NUMERIC`), optional `regex` (when `formatType=REGEX`), and optional `minLength`/`maxLength`. Use this endpoint to inspect which formats are currently enforced by the API during enroll/update when key-format validation is enabled.","parameters":[],"summary":"List key formats"}}},"components":{"schemas":{"ListKeyFormatResponse":{"type":"object","properties":{"httpResponse":{"$ref":"#/components/schemas/HttpResponse"},"data":{"type":"array","items":{"$ref":"#/components/schemas/KeyFormat"}}}},"HttpResponse":{"type":"object","properties":{"httpCode":{"type":"integer","format":"int32"},"body":{"type":"string"}}},"KeyFormat":{"type":"object","properties":{"keyId":{"type":"string"},"formatType":{"type":"string","enum":["TITULO","CPF","ALPHANUMERIC","NUMERIC","ALPHABETIC","REGEX"]},"regex":{"type":"string"},"minLength":{"type":"integer","format":"int32"},"maxLength":{"type":"integer","format":"int32"}}}}}}
```

## Create or update key formats

> Creates or updates one or more key-format definitions. Required fields are \`keyId\` and \`formatType\`. When \`formatType=REGEX\`, the \`regex\` field is required. \`minLength\` and \`maxLength\` are optional. Newly created definitions return \*\*201 Created\*\*, while existing definitions return \*\*202 Accepted\*\*. These formats are used when key-format validation is enabled for enroll/update.

```json
{"openapi":"3.0.1","info":{"title":"GBDS API","version":"5.1.16"},"servers":[{"url":"http://<ip>:8085/gbds/v2"}],"paths":{"/keyFormat":{"post":{"tags":["key-format"],"operationId":"save_1","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/KeyFormat"}}},"required":true},"responses":{"201":{"description":"CREATED","content":{"application/json":{"schema":{"type":"object"}}}},"202":{"description":"ACCEPTED","content":{"application/json":{"schema":{"type":"object"}}}}},"description":"Creates or updates one or more key-format definitions. Required fields are `keyId` and `formatType`. When `formatType=REGEX`, the `regex` field is required. `minLength` and `maxLength` are optional. Newly created definitions return **201 Created**, while existing definitions return **202 Accepted**. These formats are used when key-format validation is enabled for enroll/update.","parameters":[],"summary":"Create or update key formats"}}},"components":{"schemas":{"KeyFormat":{"type":"object","properties":{"keyId":{"type":"string"},"formatType":{"type":"string","enum":["TITULO","CPF","ALPHANUMERIC","NUMERIC","ALPHABETIC","REGEX"]},"regex":{"type":"string"},"minLength":{"type":"integer","format":"int32"},"maxLength":{"type":"integer","format":"int32"}}}}}}
```

## Get key format

> Retrieves the configured key-format definition for a specific \`keyId\`. The response includes the \`formatType\` and any additional constraints (\`regex\`, \`minLength\`, \`maxLength\`). Use this to validate client payloads against server-side requirements and to understand how a specific key will be checked during enroll/update.

```json
{"openapi":"3.0.1","info":{"title":"GBDS API","version":"5.1.16"},"servers":[{"url":"http://<ip>:8085/gbds/v2"}],"paths":{"/keyFormat/{keyId}":{"get":{"tags":["key-format"],"operationId":"get_10","parameters":[{"name":"keyId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/KeyFormatResponse"}}}}},"description":"Retrieves the configured key-format definition for a specific `keyId`. The response includes the `formatType` and any additional constraints (`regex`, `minLength`, `maxLength`). Use this to validate client payloads against server-side requirements and to understand how a specific key will be checked during enroll/update.","summary":"Get key format"}}},"components":{"schemas":{"KeyFormatResponse":{"type":"object","properties":{"httpResponse":{"$ref":"#/components/schemas/HttpResponse"},"data":{"$ref":"#/components/schemas/KeyFormat"}}},"HttpResponse":{"type":"object","properties":{"httpCode":{"type":"integer","format":"int32"},"body":{"type":"string"}}},"KeyFormat":{"type":"object","properties":{"keyId":{"type":"string"},"formatType":{"type":"string","enum":["TITULO","CPF","ALPHANUMERIC","NUMERIC","ALPHABETIC","REGEX"]},"regex":{"type":"string"},"minLength":{"type":"integer","format":"int32"},"maxLength":{"type":"integer","format":"int32"}}}}}}
```

## Delete key format

> Deletes the key-format definition for the given \`keyId\`. If the format exists and is removed, server-side validation for that key will no longer be applied (unless the format is re-added). Returns \*\*204 No Content\*\* on success.

```json
{"openapi":"3.0.1","info":{"title":"GBDS API","version":"5.1.16"},"servers":[{"url":"http://<ip>:8085/gbds/v2"}],"paths":{"/keyFormat/{keyId}":{"delete":{"tags":["key-format"],"operationId":"delete_3","parameters":[{"name":"keyId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"204":{"description":"NO CONTENT (deleted)","content":{"application/json":{"schema":{"type":"object"}}}}},"description":"Deletes the key-format definition for the given `keyId`. If the format exists and is removed, server-side validation for that key will no longer be applied (unless the format is re-added). Returns **204 No Content** on success.","summary":"Delete key format"}}}}
```

## Validate keys (oneKeyOnly + format)

> Validates a list of keys according to the active key-validation settings. When the \`oneKeyOnly\` setting is enabled, payloads containing more than one key are rejected. When the \`keyFormat\` setting is enabled, each key must satisfy its configured \`key\_format\` rules (\`formatType\`, \`regex\`, \`minLength\`, \`maxLength\`). The endpoint returns \*\*200 OK\*\* if all validations pass, or \*\*400 Bad Request\*\* if any rule is violated. Use this to pre-check client requests before enroll/update.

```json
{"openapi":"3.0.1","info":{"title":"GBDS API","version":"5.1.16"},"servers":[{"url":"http://<ip>:8085/gbds/v2"}],"paths":{"/keyFormat/validate":{"post":{"tags":["key-format"],"operationId":"validate","requestBody":{"content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Key"}}}},"required":true},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"BAD REQUEST","content":{"application/json":{"schema":{"type":"object"}}}}},"description":"Validates a list of keys according to the active key-validation settings. When the `oneKeyOnly` setting is enabled, payloads containing more than one key are rejected. When the `keyFormat` setting is enabled, each key must satisfy its configured `key_format` rules (`formatType`, `regex`, `minLength`, `maxLength`). The endpoint returns **200 OK** if all validations pass, or **400 Bad Request** if any rule is violated. Use this to pre-check client requests before enroll/update.","parameters":[],"summary":"Validate keys (oneKeyOnly + format)"}}},"components":{"schemas":{"Key":{"type":"object","properties":{"id":{"description":"Name of entity identifier.","type":"string"},"value":{"description":"Value of entity identifier.","type":"string"}}}}}}
```

## Validate a single key value

> Validates a single key value against its configured format outside of the enroll/update flow. It returns \*\*200 OK\*\* if the value passes all checks (format type, regex pattern, and optional length constraints) or \*\*400 Bad Request\*\* with \`type=VALIDATION\_ERROR\` and \`code=INVALID\_KEY\` if validation fails. This endpoint only evaluates a single \`(keyId, keyValue)\` pair and does not modify state.

```json
{"openapi":"3.0.1","info":{"title":"GBDS API","version":"5.1.16"},"servers":[{"url":"http://<ip>:8085/gbds/v2"}],"paths":{"/keyFormat/validate/{keyId}/{keyValue}":{"get":{"tags":["key-format"],"operationId":"validate_1","parameters":[{"name":"keyId","in":"path","required":true,"schema":{"type":"string"}},{"name":"keyValue","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"BAD REQUEST","content":{"application/json":{"schema":{"type":"object","properties":{"errors":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["VALIDATION_ERROR"]},"code":{"type":"string","enum":["INVALID_KEY"]},"message":{"type":"string"}}}}}}}}}},"description":"Validates a single key value against its configured format outside of the enroll/update flow. It returns **200 OK** if the value passes all checks (format type, regex pattern, and optional length constraints) or **400 Bad Request** with `type=VALIDATION_ERROR` and `code=INVALID_KEY` if validation fails. This endpoint only evaluates a single `(keyId, keyValue)` pair and does not modify state.","summary":"Validate a single key value"}}}}
```

## Validate keys for potential inconsistencies

> Checks a list of keys for inconsistencies that would invalidate an update/enroll under the \`inconsistentKeys\` setting. Inconsistent cases include multiple keys matching different existing people or a payload key that matches an existing person while another key of the same \`id\` has a different value. The endpoint returns \*\*200 OK\*\* if the keys are consistent, or \*\*400 Bad Request\*\* when inconsistencies are detected.

```json
{"openapi":"3.0.1","info":{"title":"GBDS API","version":"5.1.16"},"servers":[{"url":"http://<ip>:8085/gbds/v2"}],"paths":{"/keyFormat/validate/inconsistentKeys":{"post":{"tags":["key-format"],"operationId":"validateInconsistentKeys","requestBody":{"content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Key"}}}},"required":true},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"BAD REQUEST","content":{"application/json":{"schema":{"type":"object"}}}}},"description":"Checks a list of keys for inconsistencies that would invalidate an update/enroll under the `inconsistentKeys` setting. Inconsistent cases include multiple keys matching different existing people or a payload key that matches an existing person while another key of the same `id` has a different value. The endpoint returns **200 OK** if the keys are consistent, or **400 Bad Request** when inconsistencies are detected.","parameters":[],"summary":"Validate keys for potential inconsistencies"}}},"components":{"schemas":{"Key":{"type":"object","properties":{"id":{"description":"Name of entity identifier.","type":"string"},"value":{"description":"Value of entity identifier.","type":"string"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.griaule.com/apis/gbds-5/key-format.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
