Gemini API Rate Limits and Queue Design: Quota Dimensions and Admission Control
Distinguish direct Google project quota dimensions from generic HTTP 429 responses, treat catalog and balance checks as observations, and run an offline Python queue controller.

Gemini API rate limits and gateway 429 responses are capacity signals, not invitations for every worker to retry faster. In production systems where interactive chat, webhook automations, structured extraction, and bulk jobs share model access, avoiding retry storms requires application-side queue admission control before requests ever leave your process.
This guide consolidates Gemini API quota-dimension routing and production queue design into one engineering workflow. It separates direct Google Cloud project quota counters from generic gateway HTTP 429 responses, clarifies why GET /v1/models and GET /api/client/balance are point-in-time observations rather than capacity reservations, and provides a complete offline Python admission module.
Separate direct Google project quota dimensions from generic 429 responses
In Google's direct Gemini API rate limits documentation, quotas are enforced per Google Cloud project—not per individual API key—and vary by model and usage tier. Exceeding any single active counter returns 429 RESOURCE_EXHAUSTED even when other counters have room. When calling an OpenAI-compatible gateway or when an HTTP 429 response does not include verified provider quota metadata, the exhausted dimension is unknown and must not be guessed.
| Quota or signal dimension | Where it applies | What it measures | Application queue admission response |
|---|---|---|---|
RPM (Requests per minute) |
Direct Google project & local app budget | Request count within a 1-minute window | Pace dispatch rate, coalesce duplicate work, and defer low-priority bursts |
input_TPM (Input tokens per minute) |
Direct Google project & local app budget | Input token volume per minute for standard Gemini models | Estimate input tokens before admission; isolate long-context jobs from short interactive turns |
RPD (Requests per day) |
Direct Google project & local app budget | Daily request cap (direct Google RPD resets at midnight Pacific time) | Hold an interactive reserve; pause background and batch queues before daily exhaustion |
IPM / TPD |
Specific direct Google models | Images per minute (IPM) or tokens per day (TPD) where applicable by model |
Track modality-specific and daily token budgets separately from standard chat RPM |
batch_enqueued_tokens |
Direct Google Batch API | Separate enqueued token capacity for asynchronous batch jobs | Route asynchronous batch submissions through a dedicated batch queue, never live workers |
spend_window |
Confirmed paid-tier spend limits | Account spend cap over a billing window when applicable | Reduce high-cost dispatches or pause non-essential jobs until the window clears |
unknown (Generic HTTP 429) |
Any unattributed 429 response | Rate limit hit without confirmed counter attribution | Apply cooldown and bounded retry budget rules without inventing a specific Google counter cause |
Rotating multiple API keys inside the same direct Google Cloud project does not increase project-level RPM, input_TPM, or RPD limits. Likewise, do not assume a gateway exposes internal provider project buckets or bypasses upstream limits via key rotation. Review the Google provider page and API429 vs direct Gemini API to compare what your application owns in each setup.
Why catalog and balance checks are observations, not capacity reservations
Before admitting expensive or multi-step work, applications should check model membership via GET /v1/models (see credential-scoped model catalog selection) and verify account funding via GET /api/client/balance as documented in the API429 documentation and public OpenAPI spec. You can also review public unit rates on the pricing page and published models in the model catalog.
Treat both checks strictly as point-in-time observations:
- A listed model ID in
GET /v1/modelsconfirms credential-scoped visibility at observation time; it does not reserve RPM/TPM slots or guarantee the next call succeeds. - A positive balance in
GET /api/client/balanceconfirms account credit at observation time; concurrent workers can spend that balance before a queued job executes, and sufficient balance never prevents an HTTP 429 rate-limit response.
Pair admission checks with scoped workload health observations for deployment readiness and structured-output pipeline budgets so validation repairs cannot flood your queue.
Five explicit queue admission states
Instead of letting worker threads block on sleeps or retry loops, model your application queue around five explicit state transitions driven by workload priority, queue age, remaining deadline, estimated input tokens, and per-tenant fairness:
admitted: The job's model is present in a recent catalog observation, balance observation is healthy, tenant in-flight concurrency is below cap, no cooldown is active, and local RPM,input_TPM, and RPD reserves have room.deferred: The job is temporarily held in the queue because a rate-limit cooldown is active, a tenant fairness cap is reached, or local RPM /input_TPM/ batch enqueued capacity is saturated—and the required wait plusexecution_allowancestill fits inside the job'sdeadline.rejected: The job envelope is invalid, the requested model is absent from the recent credential-scoped catalog observation, or the balance observation is insufficient.expired: Remaining time beforedeadlineis shorter thanexecution_allowance(or shorter thancooldown + execution_allowance). Dropping expired jobs before dispatch saves tokens and quota for live callers.reconciled: A prior attempt for this job ended in a client timeout or transport drop (prior_attempt_uncertain=True). The queue holds the item for state reconciliation rather than dispatching a duplicate paid call.
Runnable offline Python queue admission controller
The standalone Python 3.10+ module below (download api429-queue-admission.py) implements this pure offline admission decision using only the Python standard library. All model IDs and counters in the fixture are synthetic and offline.
"""Pure, offline queue admission and quota-signal evaluator for AI workloads.
Direct Google Gemini API project quotas (RPM, input_TPM, RPD, model-specific
IPM/TPD, separate Batch enqueued capacity, and confirmed paid-tier spend windows)
apply per Google Cloud project rather than per API key. They are distinct from a
generic HTTP 429 on an OpenAI-compatible gateway, where the exhausted dimension
remains 'unknown' unless confirmed by explicit response evidence.
Catalog snapshots (/v1/models) and balance snapshots (/api/client/balance) are
point-in-time observations, never capacity reservations. All demo model IDs are
fictional and do not represent API429 availability or throughput promises.
"""
import math
from typing import Any, Dict, NamedTuple, Optional
class QueueDecision(NamedTuple):
state: str
reason: str
suspected_dimension: str
wait_seconds: float
diagnostic: Dict[str, Any]
WORKLOAD_PRIORITY = {
'interactive': 3,
'webhook': 2,
'background': 1,
'batch': 0,
}
KNOWN_DIMENSIONS = (
'RPM',
'input_TPM',
'RPD',
'IPM',
'TPD',
'batch_enqueued_tokens',
'spend_window',
'unknown',
)
def _text(value: Any) -> bool:
return isinstance(value, str) and bool(value.strip())
def _number(value: Any) -> bool:
try:
return type(value) in (int, float) and math.isfinite(value) and value >= 0
except OverflowError:
return False
def evaluate_queue_item(
job: Dict[str, Any],
snapshot: Dict[str, Any],
*,
now: float,
) -> QueueDecision:
"""Return one of ('admitted', 'deferred', 'rejected', 'expired', 'reconciled').
Evaluates remaining deadline, workload class priority, queue age, input
token estimate, tenant fairness, and local application budget counters.
Never infers a specific Google quota dimension from an unclassified 429.
"""
if not isinstance(job, dict) or not isinstance(snapshot, dict) or not _number(now):
return QueueDecision(
'rejected', 'invalid_admission_input', 'unknown', 0.0,
{'error_code': 'invalid_admission_input'},
)
workload = job.get('workload_class')
tenant = job.get('tenant_id')
model = job.get('model')
enqueued_at = job.get('enqueued_at')
deadline = job.get('deadline')
exec_allowance = job.get('execution_allowance')
input_tokens = job.get('estimated_input_tokens')
if (workload not in WORKLOAD_PRIORITY or not _text(tenant) or not _text(model)
or not all(_number(v) for v in (enqueued_at, deadline, exec_allowance))
or exec_allowance <= 0 or type(input_tokens) is not int or input_tokens <= 0
or now < enqueued_at):
return QueueDecision(
'rejected', 'invalid_job_envelope', 'unknown', 0.0,
{'error_code': 'invalid_job_envelope'},
)
age = now - enqueued_at
remaining = deadline - now
if job.get('prior_attempt_uncertain') is True:
return QueueDecision(
'reconciled', 'prior_attempt_outcome_uncertain', 'unknown', 0.0,
{'workload_class': workload, 'age_s': round(age, 3), 'tenant_id': tenant},
)
if remaining < exec_allowance:
return QueueDecision(
'expired', 'deadline_insufficient_for_execution', 'unknown', 0.0,
{'workload_class': workload, 'age_s': round(age, 3), 'remaining_s': round(remaining, 3)},
)
catalog_models = snapshot.get('observed_models')
balance_ok = snapshot.get('balance_sufficient_observation')
if not isinstance(catalog_models, (list, tuple)) or model not in catalog_models:
return QueueDecision(
'rejected', 'model_not_in_recent_observation', 'unknown', 0.0,
{'workload_class': workload, 'model': model},
)
if balance_ok is not True:
return QueueDecision(
'rejected', 'balance_observation_not_confirmed', 'unknown', 0.0,
{'workload_class': workload, 'tenant_id': tenant},
)
def defer_capacity(reason: str, dimension: str, wait: float,
diagnostic: Dict[str, Any]) -> QueueDecision:
# Every deferral must leave room for execution, as cooldown and tenant
# waits do. Finishing exactly at the deadline is permitted.
if wait + exec_allowance > remaining:
return QueueDecision(
'expired', reason + '_wait_exceeds_deadline', dimension, 0.0,
diagnostic,
)
return QueueDecision('deferred', reason, dimension, wait, diagnostic)
if workload == 'batch' and snapshot.get('separate_batch_queue_required', True):
batch_room = snapshot.get('batch_enqueued_token_room', 0)
if type(batch_room) is not int or input_tokens > batch_room:
return defer_capacity(
'batch_enqueued_capacity_full', 'batch_enqueued_tokens', 30.0,
{'workload_class': workload, 'estimated_input_tokens': input_tokens},
)
tenant_in_flight = snapshot.get('tenant_in_flight', 0)
tenant_cap = snapshot.get('tenant_max_in_flight', 1)
if type(tenant_in_flight) is not int or type(tenant_cap) is not int or tenant_cap <= 0:
return QueueDecision(
'rejected', 'invalid_tenant_fairness_state', 'unknown', 0.0,
{'error_code': 'invalid_tenant_fairness_state'},
)
if tenant_in_flight >= tenant_cap:
wait = min(5.0, max(0.5, remaining - exec_allowance))
if wait + exec_allowance > remaining:
return QueueDecision(
'expired', 'tenant_cap_wait_exceeds_deadline', 'unknown', 0.0,
{'workload_class': workload, 'tenant_id': tenant},
)
return QueueDecision(
'deferred', 'tenant_fairness_cap_reached', 'unknown', round(wait, 3),
{'workload_class': workload, 'tenant_id': tenant, 'age_s': round(age, 3)},
)
last_429_dim: Optional[str] = snapshot.get('recent_429_dimension')
cooldown_s = snapshot.get('cooldown_remaining_s', 0.0)
if not _number(cooldown_s):
return QueueDecision(
'rejected', 'invalid_cooldown_state', 'unknown', 0.0,
{'error_code': 'invalid_cooldown_state'},
)
if cooldown_s > 0:
dim = last_429_dim if last_429_dim in KNOWN_DIMENSIONS else 'unknown'
if cooldown_s + exec_allowance > remaining:
return QueueDecision(
'expired', 'cooldown_exceeds_remaining_deadline', dim, 0.0,
{'workload_class': workload, 'suspected_dimension': dim},
)
return QueueDecision(
'deferred', 'active_rate_limit_cooldown', dim, round(cooldown_s, 3),
{'workload_class': workload, 'suspected_dimension': dim, 'age_s': round(age, 3)},
)
rpm_room = snapshot.get('local_rpm_room', 0)
tpm_room = snapshot.get('local_input_tpm_room', 0)
rpd_room = snapshot.get('local_rpd_room', 0)
reserve_rpd = snapshot.get('interactive_rpd_reserve', 0)
if not all(type(v) is int and v >= 0 for v in (rpm_room, tpm_room, rpd_room, reserve_rpd)):
return QueueDecision(
'rejected', 'invalid_local_budget_counters', 'unknown', 0.0,
{'error_code': 'invalid_local_budget_counters'},
)
if rpd_room == 0 or (WORKLOAD_PRIORITY[workload] < WORKLOAD_PRIORITY['interactive'] and rpd_room <= reserve_rpd):
return defer_capacity(
'local_rpd_reserve_protected', 'RPD', 60.0,
{'workload_class': workload, 'rpd_room': rpd_room},
)
if rpm_room < 1:
return defer_capacity(
'local_rpm_budget_saturated', 'RPM', 2.0,
{'workload_class': workload, 'age_s': round(age, 3)},
)
if input_tokens > tpm_room:
return defer_capacity(
'local_input_tpm_budget_saturated', 'input_TPM', 5.0,
{'workload_class': workload, 'estimated_input_tokens': input_tokens, 'tpm_room': tpm_room},
)
priority_score = WORKLOAD_PRIORITY[workload] * 1000 + min(int(age), 300)
return QueueDecision(
'admitted', 'within_local_admission_budgets', 'unknown', 0.0,
{
'workload_class': workload,
'priority_score': priority_score,
'estimated_input_tokens': input_tokens,
'age_s': round(age, 3),
},
)
def main() -> None:
base_snapshot = {
'observed_models': ('demo-gemini-flash', 'demo-gemini-pro'),
'balance_sufficient_observation': True,
'tenant_in_flight': 1,
'tenant_max_in_flight': 4,
'cooldown_remaining_s': 0.0,
'local_rpm_room': 12,
'local_input_tpm_room': 40000,
'local_rpd_room': 200,
'interactive_rpd_reserve': 50,
}
interactive_job = {
'workload_class': 'interactive',
'tenant_id': 'tenant-alpha',
'model': 'demo-gemini-flash',
'enqueued_at': 100.0,
'deadline': 115.0,
'execution_allowance': 4.0,
'estimated_input_tokens': 1800,
}
generic_429_snapshot = dict(base_snapshot, cooldown_remaining_s=3.5, recent_429_dimension='unknown')
uncertain_job = dict(interactive_job, prior_attempt_uncertain=True)
d1 = evaluate_queue_item(interactive_job, base_snapshot, now=102.0)
d2 = evaluate_queue_item(interactive_job, generic_429_snapshot, now=102.0)
d3 = evaluate_queue_item(uncertain_job, base_snapshot, now=102.0)
print('Fictional admitted:', d1.state, '|', d1.reason, '|', d1.diagnostic)
print('Fictional generic 429 deferral:', d2.state, '|', d2.suspected_dimension, '|', d2.wait_seconds)
print('Fictional uncertain reconciliation:', d3.state, '|', d3.reason)
if __name__ == '__main__':
main()
Operational guardrails for multi-tenant and tool workloads
When integrating interactive coding assistants such as Claude Code or Cursor alongside automated n8n workflows, isolate interactive traffic from background queues:
- Protect interactive RPD and TPM reserves. Configure background and bulk enrichment queues to defer automatically when local daily or minute budgets approach the interactive reserve threshold.
- Cap per-tenant in-flight requests. Prevent one noisy customer or runaway workflow from occupying every worker slot while other tenants wait.
- Keep Retry-After and backoff centralized. Once a job is admitted and receives an HTTP 429 or 503, hand off timing calculation to your retry budget policy rather than inventing ad-hoc worker sleeps. Check the FAQ for client account and billing details.
FAQ
Why do I receive HTTP 429 when my request count per minute is low?
In direct Gemini API usage, requests are checked against multiple independent project counters simultaneously. A handful of large prompts can exhaust input_TPM, overnight jobs can exhaust RPD, image tasks can hit IPM, or paid accounts can hit a spend window even when RPM is low. On a gateway, if the 429 response does not specify a counter, treat the dimension as unknown and pace admission conservatively.
Does rotating API keys inside one Google Cloud project multiply Gemini quota?
No. Google documents that Gemini API rate limits apply per project, not per API key. Creating multiple keys inside the same project does not increase project quota and fragments your application's telemetry.
Does checking GET /api/client/balance or GET /v1/models reserve capacity for my queue?
No. Both endpoints return point-in-time observations. They help your queue reject unconfigured models or unfunded workloads early, but your application still needs local concurrency caps, deadline checks, and rate-limit cooldowns.
What should the queue do when a worker times out waiting for a model response?
Transition the job to reconciled (prior_attempt_uncertain), not admitted. A timeout does not prove the upstream request was canceled; reconciling downstream state or idempotency records first prevents duplicate charges and duplicate side effects.
Sources & further reading
Put the next step into practice.
Check model IDs, current pricing and request formats before integrating. Availability can depend on the model and provider route.

