Fine-grained M2M token quotas are currently in Early Access. Reach out to your Auth0 contact to request access. To learn more about Auth0’s product release cycle, read Product release stages.
Fine-grained M2M token quotas are distinct from your tenant’s overall monthly M2M token allotment. You can use fine-grained token quotas as a safeguard against rapid token requests.
Use cases
- Control runaway applications: Apply application-level quotas to limit M2M applications from requesting tokens too frequently (due to bugs, no caching, etc.) without impacting your tenant’s overall M2M token quota.
- Ensure fair multi-tenant usage: Assign organization-level quotas to different customers (Auth0 Organizations) to prevent one from degrading quota for others.
- Set tenant-wide safeguards: Use tenant-level default quotas as a baseline limit against excessive M2M token requests from applications and organizations.
- Monitor before enforcement: Deploy quotas with
enforce: falseto observe token consumption via Consumption warning logs and Auth0 quota headers. Then, set informed limits before active blocking.
How it works
You can apply fine-grained M2M token quotas to the following entities:- Application: Limits tokens generated for a client to control individual application behavior.
- Organization: Limits tokens for requests made with an organization to help manage M2M activity for the SaaS customer or business unit across applications utilizing tokens associated with an
org_id.
- Hourly: The maximum number of tokens that can be obtained within a single hour. The quota resets at the beginning of each UTC hour.
- Daily: The maximum number of tokens that can be obtained within a 24-hour period. The quota resets at the beginning of each UTC day.
Auth0’s token counting mechanism is eventually consistent, allowing for potential minor, brief overruns before enforcement on subsequent requests.
Quota evaluation and enforcement rules
Auth0 determines and enforces fine-grained M2M token quotas for applications and organizations associated with your tenant:-
Client-Level Quota:
- If you have configured an Application-Specific Quota for the
client_id, Auth0 applies the quota to the client. - Otherwise, Auth0 applies the Tenant-Level Default Quota for Clients to the client. If you have not configured a tenant-level default for clients, Auth0 does not apply a fine-grained quota to the client.
- If you have configured an Application-Specific Quota for the
-
Organization-Level Quota:
- If you have configured an Organization-Specific Quota for the
org_idassociated with the token request, Auth0 applies the quota to the organization. - Otherwise, Auth0 applies the Tenant-Level Default Quota for Organizations to the
org_idassociated with the token request. If you have not configured a tenant-level default for Organizations, Auth0 does not apply a fine-grained quota for theorg_idassociated with the token request.
- If you have configured an Organization-Specific Quota for the
-
Depending on whether the token request has an associated organization, Auth0 checks for an applicable quota:
- If the token request has an associated organization defined explicitly or via default organization settings, Auth0 checks the client-level and organization-level quotas concurrently.
- If the token request does not have an associated organization, Auth0 only checks the client-level quota.
enforce flag set to true in the quota’s configuration:
- When a quota is enforced (
enforce: true): If an enforced quota is exceeded, the token request is rejected with an HTTP 429 Too Many Requests error. To learn more, read Error responses for exceeded quotas. - When a quota is not enforced (
enforce: false): Token requests are not rejected by this quota, even if its limit is exceeded. Auth0 still counts tokens and generates Consumption warning logs at thresholds, allowing for monitoring before enabling enforcement.
Observability
To provide visibility into quota consumption, Auth0 generates Consumption warning logs. These logs are triggered when a quota reaches 60%, 80%, and 100% of its limit. You can use these logs to proactively monitor token usage and identify potential issues. Applications can also programmatically determine their remaining quota using Auth0 quota headers. These HTTP headers are included in both successful and error responses to Client Credentials Flow requests, providing real-time information on quota usage.Configure M2M token quotas
You can configure Fine-Grained M2M Token Quotas using the Management API.Tenant-level default quotas
Tenant-level quotas serve as the default settings for all applications and organizations within your Auth0 tenant. You can use tenant-level quotas to establish baseline limits for M2M token usage. These quotas are overridden by application-specific and organization-specific quotas. You can specify default token quotas for applications and/or organizations associated with your tenant. To configure tenant-level quotas, use the Update a tenant endpoint:default_token_quota object contains the following application-level and organization-level token quota configurations:
clients.client_credentials: (Optional) Defines M2M token quotas for individual applications.organizations.client_credentials: (Optional) Defines M2M token quotas for organizations.per_hour: (Optional) Sets the hourly token quota.per_day: (Optional) Sets the daily token quota.enforce: (Optional) Determines whether token requests are rejected when the quota is exceeded. The default is true.
enforce: false). This allows you to monitor organization token usage before enforcing limits.
Application-specific quotas
You can configure quotas for specific applications, overriding the tenant-level defaults. This is useful for fine-grained control over individual application behavior. You can set application-specific quotas when creating or updating an application. To create an application with a token quota, use the Create a client endpoint:token_quota object contains the token quota configuration for the application:
client_credentials: Defines M2M token quotas.per_hour: Sets the hourly token quota.per_day: Sets the daily token quota.enforce: Determines whether token requests are rejected when the quota is exceeded. The default istrue.
{yourClientId} is limited to 10 M2M tokens per hour and 50 per day, overriding any tenant-level settings.
You can retrieve an application’s token quota configuration using the Get a client by ID endpoint.
Organization-specific quotas
You can also configure quotas for specific organizations, overriding tenant-level defaults. This allows you to manage M2M token usage for individual SaaS customers or partners. You can set organization-specific quotas when creating or updating an organization. To create an organization with a token quota, use the Create an organization endpoint:token_quota object contains the token quota configuration for the organization:
client_credentials: Defines M2M token quotas.per_hour: Sets the hourly token quota.per_day: Sets the daily token quota.enforce: Determines whether token requests are rejected when the quota is exceeded. The default istrue.
YOUR_ORG_ID is limited to 50 M2M tokens per hour and 250 per day.
You can retrieve an organization’s token quota configuration using the Get an organization endpoint.
Monitor token quota consumption
Auth0 quota headers
Auth0 includes HTTP headers in Client Credentials Flow responses (both successful and 429 error responses) to provide real-time information about quota consumption:Auth0-Client-Quota-Limit: Provides quota information for the application.Auth0-Organization-Quota-Limit: Provides quota information for the organization.
b(bucket_name): The name of the quota bucket (per_hourorper_day).q(quota): The configured quota limit for the bucket.- r (remaining): The number of remaining tokens in the bucket.
t(time): The number of seconds until the bucket resets.
Auth0-Client-Quota-Limit example:
- The application has an hourly quota (
b=per_hour) of 10 tokens (q=10). It has 7 tokens remaining (r=7), and the quota resets in 3540 seconds (t=3540). - The application also has a daily quota (
b=per_day) of 50 tokens (q=50). It has 47 tokens remaining (r=47), and the quota resets in 43200 seconds (t=43200).
Error responses for exceeded quotas
When an enforced quota is exceeded, the Auth0 Authentication API returns anHTTP 429 Too Many Requests error. In the response body, Auth0 returns the error code with a more detailed description. Auth0 also issues an event log of type feccft (for Failed exchange of Access Token for a Client Credentials Grant).
The following code sample is an example error response for an exceeded quota:
Auth0-Client-Quota-LimitorAuth0-Organization-Quota-Limit: The Auth0 quota header corresponding to the consumed quota for the application or the organization. To learn more about the header format, read Auth0 quota headers.X-RateLimit-Limit: The configured limit for the quota that has been consumed.X-RateLimit-Remaining: Set to zero, indicating that the quota has been fully consumed.X-RateLimit-Reset: A UNIX timestamp (in seconds) representing the time when the quota is expected to reset and further requests will be allowed.Retry-After: The number of seconds until the quota resets and further requests will succeed.
Retry-After header to determine the wait time for obtaining a new M2M token, allowing your application to decide whether to retry or throw an error. This is also important to avoid consuming the rate limit of your tenant.
The following code sample is a Node.js example that tries to get a new M2M token, receives a 429 error, and re-tries again if the wait time is less than 60 seconds. Otherwise, it throws an error:
Consumption warning logs
Auth0 generatestoken_quota_consumption_warning log events when the consumption for a quota reaches 60%, 80%, and 100%. You can analyze these logs to monitor token usage patterns, identify potential issues before limits are strictly enforced, and help you decide on appropriate quota values.
The following code sample is an example consumption warning log as a JSON log entry:
-
type:
token_quota_consumption_warning. Identifies the warning for M2M token quota consumption that’s reaching a threshold. -
description: (String) Human-readable summary in the format of
<percent>% <entity_type> <bucket>quota consumed. For example, “60% of client per day quota consumed.” -
details: (Object) Describes specifics about the quota and its consumption:
bucket: (String)per_dayorper_hour.entity_type: (String) client or organization.entity_id: (String) ID of the client or organization.quota: (Integer) Configured limit for this bucket.quota_consumption_percentage: (Integer) Percentage consumed (e.g., 60, 80, 100).quota_consumption: (Integer) Actual tokens counted.
date, client_name, ip, and log_id are standard Auth0 log fields.
Best practices
- Prioritize Token Caching: Emphasize proper access token caching in M2M applications. Quotas are safeguards, not replacements for efficient token management.
- Appropriate Quota Levels: Set quotas based on legitimate traffic patterns and reasonable burst capacity.
- Monitor Before Enforcing: Start with
enforce: falseto observe usage via logs and headers, then set informed limits before enablingenforce: true. - Client-Side Handling: Applications should handle 429 errors gracefully using
Retry-Afterfor backoff strategies. - Proactively check quota headers: Monitor token usage to identify potential issues.
- Review Logs Regularly: Monitor
token_quota_consumption_warninglogs to adjust quotas proactively.
Limitations
- Not API Call Limits: Fine-Grained M2M Token Quotas apply to the number of access tokens obtained via Client Credentials Flow, not calls made to your APIs using those tokens.
- Eventual Consistency: Token counting is eventually consistent; minor, brief overruns are possible before enforcement on subsequent requests.
- Requests that result in a
429response count for the Auth0 Authentication API rate limit for your tenant. To learn more, read Rate Limit Policy.
Troubleshoot
-
Legitimate Traffic Blocked:
- Consider setting
enforce: false. - Check Auth0 tenant logs for
token_quota_consumption_warningand failed exchange events (feccft). - Examine
Auth0-...-Quota-Limitheaders in responses. - Review application token request patterns and caching.
- Consider if the quota limit needs adjustment.
- Consider setting
-
Interpret 429 Errors: Use
X-RateLimit-*,Retry-After, and the specificAuth0-...-Quota-Limitheaders to identify the consumed limit and reset time.