Skip to content

feat: expose Retry-After in APIError - #230

Draft
gracehopper-vt wants to merge 2 commits into
masterfrom
feat/expose-retry-after
Draft

gracehopper-vt wants to merge 2 commits into
masterfrom
feat/expose-retry-after

Conversation

@gracehopper-vt

Copy link
Copy Markdown
Collaborator

Summary

The VirusTotal API is adding a Retry-After header to rate-limit / quota-exceeded responses (429 in API v3). This PR makes it available to vt-py users:

  • APIError gets a new optional retry_after attribute (seconds, int), None when the response has no Retry-After header.
  • Client.get_error_async parses the header, accepting both forms allowed by RFC 9110: delta-seconds (Retry-After: 120) and an HTTP date.
  • Fully backwards compatible: APIError(code, message) and APIError.from_dict(error) keep working, and args is unchanged.

Usage:

try:
  obj = client.get_object("/files/{}", sha256)
except vt.APIError as e:
  if e.code == "QuotaExceededError" and e.retry_after is not None:
    time.sleep(e.retry_after)

No automatic retries are added: when a daily or monthly quota is exhausted, retry_after can be hours or days, and silently sleeping that long would hang scripts. Automatic waiting could be added later as an opt-in.

Tests

New tests in tests/test_client.py for a 429 with Retry-After in seconds, a 429 with an HTTP-date Retry-After, and an error without the header. Full suite: 45 passed.

gracehopper-vt and others added 2 commits October 3, 2026 11:20
The VirusTotal API is starting to send a Retry-After header with
rate-limit and quota-exceeded responses. Parse it (either seconds or an
HTTP date) and expose it as APIError.retry_after so callers can wait the
right amount of time before retrying. It is None when the header is not
present.

Co-authored-by: Oscar Torreno <torreno@google.com>
Co-authored-by: Oscar Torreno <torreno@google.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant