public void assignPerRequestApiKey(ApiKeyData data) {
        String perRequestKey = generateKey();
        ResourceDescriptor resource = toResource(perRequestKey);
        data.setPerRequestKey(perRequestKey);
        String json = ProxyUtil.convertToString(data);
        try {
            resourceService.putResource(resource, json, EtagHeader.NEW_ONLY);
        } catch (HttpException exception) {
            throw exception.getStatus() == HttpStatus.PRECONDITION_FAILED
                    ? new IllegalStateException(String.format("API key %s already exists in the storage", perRequestKey))
                    : exception;
        }
    }
Assigns a new generated per request key to the {@link ApiKeyData}.
<p>
    Note. The method is blocking and shouldn't be run in the event loop thread.
</p>
server/src/main/java/com/epam/aidial/core/server/security/ApiKeyStore.java