Share quota for multiple API KEYS

Hi,

I’ve been looking for a way to create an API then multiple API KEYS for that API where the API KEYS share a policy quota.

Right now what I’m doing is creating the API then adding it to the policy (creating a new entry on policies/policies.json) that looks like this:

  "{POLICY_NAME}": {
    "rate": 10,
    "per": 1,
    "quota_max": 500000,
    "quota_remaining": 500000,
    "quota_renewal_rate": 2592000,
    "access_rights": {
      "{API_ID}": {
        "api_id": "{API_ID}",
        "api_name": "name",
        "versions": [
          "v1"
        ],
        "allowed_urls": []
      }
    }

Then when I create an API KEY for that API, I do this:

POSt {host}/tyk/keys
{
    "access_rights": {
      "{API_ID}": {
        "api_id": "{API_ID}",
        "api_name": "customer001",
        "versions": ["v1"]
      }
    },
    "meta_data": {},
    "apply_policies": ["{POLICY_NAME}"]
}

I can check that the key is correctly created and the quota is updated. This is the API KEY after 2 requests been made:

{
    "last_check": 0,
    "allowance": 0,
    "rate": 10,
    "per": 1,
    "throttle_interval": 0,
    "throttle_retry_limit": 0,
    "max_query_depth": 0,
    "date_created": "2022-02-12T17:08:35.748599651Z",
    "expires": 0,
    "quota_max": 500000,
    "quota_renews": 1647277837,
    "quota_remaining": 499998,
    "quota_renewal_rate": 2592000,
    "access_rights": {
        "{API_ID}": {
            "api_name": "name",
            "api_id": "{API_ID}",
            "versions": [
                "v1"
            ],
            "allowed_urls": [],
            "restricted_types": null,
            "limit": {
                "rate": 10,
                "per": 1,
                "throttle_interval": 0,
                "throttle_retry_limit": 0,
                "max_query_depth": 0,
                "quota_max": 500000,
                "quota_renews": 1647277837,
                "quota_remaining": 499998,
                "quota_renewal_rate": 2592000
            },
            "field_access_rights": null,
            "allowance_scope": ""
        }
    },
    "org_id": "",
    "oauth_client_id": "",
    "oauth_keys": null,
    "certificate": "",
    "basic_auth_data": {
        "password": "",
        "hash_type": ""
    },
    "jwt_data": {
        "secret": ""
    },
    "hmac_enabled": false,
    "enable_http_signature_validation": false,
    "hmac_string": "",
    "rsa_certificate_id": "",
    "is_inactive": false,
    "apply_policy_id": "",
    "apply_policies": [
        "{API_ID}"
    ],
    "data_expires": 0,
    "monitor": {
        "trigger_limits": null
    },
    "enable_detail_recording": false,
    "enable_detailed_recording": false,
    "meta_data": {},
    "tags": [],
    "alias": "",
    "last_updated": "1644685715",
    "id_extractor_deadline": 0,
    "session_lifetime": 0,
    "key_id": "2092384029380423094203"
}

The thing is: If another API KEY is created the policy quota is “Fully Copied” and both API KEYS acts individually about the quota.

I’d like to know if it’s possible to share the same policy quota (eg: 500k req/month) among all the API KEYS, so any request decrement the quota remaining for each API KEY?

Thanks

1 Like

Hi @Leobel_Izquierdo

kindly follow the latest update on this link