Skip to content

fix: do not retry a 429 when API credits are exhausted - #15

Merged
arjunjain merged 1 commit into
mainfrom
fix/quota-exhausted-no-retry
Sep 3, 2026
Merged

fix: do not retry a 429 when API credits are exhausted#15
arjunjain merged 1 commit into
mainfrom
fix/quota-exhausted-no-retry

Conversation

@arjunjain

@arjunjain arjunjain commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Syncs this client with python-client 0.3.1 (PR #28), which fixed the 429 retry logic when an API key's credits are exhausted.

The problem

A 429 covers three different conditions. The OpenAPI spec's shared 429 response says so outright:

Too many requests in a short period, rate limit exceeded, or API credits exhausted.

This client retried all three. Waiting out the backoff cannot conjure more credits, so an exhausted quota burned the full retry budget — about 62s across the default five attempts — before surfacing an error that was never going to clear.

The fix

The 429 branch now reads results.code and fails immediately when it means exhausted credits. Transient 429s retry exactly as before.

Code Meaning Behaviour
ApiLimitExceeded credits exhausted fail immediately
ApiKeyLimitExceeded credits exhausted (key-scoped) fail immediately
RateLimitExceeded transient retry
TooManyRequests transient burst limit retry
(no code) unknown retry, as before

On ApiKeyLimitExceeded

It is not in the spec's ErrorCode enum — only ApiLimitExceeded is. It is kept anyway because python-client sends it, and this spec has proven incomplete before (it omits news_type on websocket/register entirely, and lagged on the symbolmarket_id rename). Dropping it would silently miss key-scoped quota exhaustion.

Tests

Two per client: a quota code makes exactly one request, and a non-quota 429 still retries — so this cannot regress into a blanket no-retry.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/NewsdataApiBase.php 92.30% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sync with python-client 0.3.1 (PR #28). A 429 covers three cases — a
burst limit, a rate limit, and exhausted API credits — and the client
retried all three. Waiting out the backoff cannot conjure more credits,
so an exhausted quota burned the full retry budget (~62s on the default
five attempts) before surfacing an error that was never going to clear.

The 429 branch now reads `results.code` and fails immediately when it
means exhausted credits. Transient 429s retry exactly as before.

ApiLimitExceeded is the documented code (see the ErrorCode enum in
https://newsdata.io/openapi.json, whose 429 response is described as
"Too many requests in a short period, rate limit exceeded, or API
credits exhausted"). ApiKeyLimitExceeded is accepted too: it is absent
from the spec, but python-client sends it and the spec has proven
incomplete before, so dropping it would silently miss key-scoped quotas.
@arjunjain
arjunjain force-pushed the fix/quota-exhausted-no-retry branch from 368c09a to 8e9afda Compare September 3, 2026 01:26
@arjunjain
arjunjain merged commit ffeeea5 into main Sep 3, 2026
9 checks passed
@arjunjain
arjunjain deleted the fix/quota-exhausted-no-retry branch September 3, 2026 03:47
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.

2 participants