Skip to content

fix: send country to states() and do not retry billed requests (0.6.2) - #16

Merged
rbatista191 merged 1 commit into
mainfrom
fix/states-country-and-sync-retries
Nov 29, 2026
Merged

rbatista191 merged 1 commit into
mainfrom
fix/states-country-and-sync-retries

Conversation

@rbatista191

Copy link
Copy Markdown
Contributor

Summary

A customer reported two problems. Both are in the Python and the Node SDK.

  1. states() sent GET /v1/states with no country. The API requires country (apps/api/src/controllers/v1/fetch-states.ts in backend), so every call returned 400. states() now sends country, "US" by default. The docstring said "Google requests". It now names the engines that accept state: ChatGPT, Gemini and Bing AI Mode.
  2. The client retried every request after a timeout, a connection error or a 429/5xx, POST /v1/monitor/* included. The API charges a sync request when it sends a 200 (credits-middleware.ts). It checks for a client cancel only before each scrape attempt (monitor-handler.ts). Thus a retry after a client timeout can charge twice.

Retry rules after this change

Request Retried on
GET Timeout, connection error, 429, 500, 502, 503, 504 (no change)
Async create with an idempotency key (batch: each task has one) Same as GET
monitor.*, async create without a key Connection did not open, 429, 500, 503

A 502 or 504 comes from a gateway, and the API can still complete the request and charge for it. A 429, 500 or 503 from the API did not charge.

The default timeout is now 320 s, up from 300 s. The server stops a sync request after 5 minutes, and the client now gets that response before its own timeout.

Version 0.6.2. A merge publishes it to PyPI.

Tests

  • Unit tests for states() and each retry rule. The 7 new behaviour tests fail on the old code.
  • Python: pytest on 3.8, 3.11 and 3.13, and ruff. Node: vitest on 18, 20, 22, 24 and 26, tsc --noEmit and the build.
  • Real sockets against a local server, Python and Node 18 and 24: a read timeout, a closed connection and a 502 on a monitor request each make 1 request. A 503 makes 3. A DNS failure makes 3 attempts. A GET timeout makes 3. An async create with a key makes 3 after a timeout.
  • Not tested against the live API.

states() sent GET /v1/states with no country. The API requires country,
so every call returned 400. states() now sends country, "US" by default.
The docstring now names the engines that accept state: ChatGPT, Gemini
and Bing AI Mode.

The client retried a sync monitor request after a read timeout, a
dropped connection, a 502 or a 504. In these cases the server can
complete the first request and charge for it, so the retry can charge
again. A request that is not idempotent is now retried only when the
connection did not open, or on a 429, 500 or 503. An async task create
is idempotent when it has an idempotency key (for a batch, when each
task has one). GET requests keep all retries.

The default timeout is now 320 seconds, up from 300. The server stops a
sync request after 5 minutes, and the client now gets that response.
@rbatista191
rbatista191 merged commit a781520 into main Nov 29, 2026
7 checks passed
@rbatista191
rbatista191 deleted the fix/states-country-and-sync-retries branch November 29, 2026 10:54
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