Mask data in text
https://gptunnel.ru/v1/obfuscateSend the document in text. The endpoint replaces detected fragments and returns the masked text in obfuscated_text without calling a language model. For automatic restoration of masked values in model responses, use PII masking in Chat Completions.
Request parameters
Section titled “Request parameters”Send your API key in the Authorization header and use a JSON request body.
| Parameter | Type | Required? | Description |
|---|---|---|---|
text | string | Required | Nonempty text to process. The default limit is 500,000 characters. |
custom_patterns | array | Optional | Additional rules for your own identifiers. Each rule has a regular expression in pattern and may include a label. |
entity_types | array | Optional | Built-in classes: PER, ORG, LOC, MSC and IDS. Omit this field to detect all classes. To detect selected classes, pass a nonempty array containing the desired classes. |
Pass up to 20 rules in custom_patterns. Each regular expression can be up to 500 characters and each label up to 16 characters. See rule syntax and capture groups.
Example request
Section titled “Example request”Set the GPTUNNEL_API_KEY environment variable. The sample text contains the same test identifier twice. The rule assigns it the label DOCREF.
import jsonimport osfrom urllib.request import Request, urlopen
body = { 'text': 'DOCREF-27183 / DOCREF-27183', 'custom_patterns': [{'pattern': 'DOCREF-[0-9]{5}', 'label': 'DOCREF'}],}request = Request( 'https://gptunnel.ru/v1/obfuscate', method='POST', headers={ 'Authorization': os.environ['GPTUNNEL_API_KEY'], 'Content-Type': 'application/json', }, data=json.dumps(body).encode('utf-8'),)with urlopen(request, timeout=30) as response: print(json.load(response))curl --fail-with-body --silent --show-error \ --url 'https://gptunnel.ru/v1/obfuscate' \ --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \ --json '{ "text": "DOCREF-27183 / DOCREF-27183", "custom_patterns": [ { "pattern": "DOCREF-[0-9]{5}", "label": "DOCREF" } ]}'const response = await fetch('https://gptunnel.ru/v1/obfuscate', { method: 'POST', headers: { Authorization: process.env.GPTUNNEL_API_KEY, 'Content-Type': 'application/json', }, body: JSON.stringify({ "text": "DOCREF-27183 / DOCREF-27183", "custom_patterns": [ { "pattern": "DOCREF-[0-9]{5}", "label": "DOCREF" } ]}),})if (!response.ok) throw new Error(await response.text())console.log(await response.json())Response
Section titled “Response”The response below corresponds to the example request. Its id is illustrative.
{ "id": "6720f0c1a9e4b3d2c1f0e9a8", "obfuscated_text": "<<DOCREF_0001>> / <<DOCREF_0001>>", "mapping": [ { "id": "<<DOCREF_0001>>", "text": "DOCREF-27183" } ], "usage": { "input_tokens": 11, "cost_rub": 0.00308 }}Both copies of the identifier use the same placeholder in obfuscated_text. To restore the original value, use the corresponding id and text from mapping. If an external system needs masked text only, send obfuscated_text and keep mapping private because it contains the original values.
Pricing
Section titled “Pricing”You are charged for all text scanned, even when there are no matches.
usage.input_tokens is the number of tokens processed. usage.cost_rub is the price in rubles at the listed rate. In the sample response, 11 tokens cost ₽0.00308. Check your transaction history for the amount actually charged after discounts. Include the top-level id when contacting support about the request.
Errors
Section titled “Errors”Check the HTTP status and error.code. For example, an empty text returns HTTP 400 with invalid_value.
| HTTP | error.code |
What to Do |
|---|---|---|
| 400 | invalid_value |
Check the request body. Pass a nonempty string in text. To detect all classes, omit entity_types. |
| 400 | invalid_obfuscate_patterns |
Fix the rule in custom_patterns. See error.message for the reason. |
| 402 | insufficient_balance_error |
Check the balance of the account paying for the request. |
| 402 | api_key_limit_exceeded |
Check the API key’s usage and spending limit. |
| 403 | model_blocked |
Contact support about the API access restriction. |
| 413 | obfuscation_input_too_large |
Split the document into smaller parts. The text may exceed the size limit or take too long to scan. |
| 503 | obfuscation_unavailable |
Retry later. There is no processing charge while the service is unavailable. |