REST response envelope
Successful calls return:2xx, treat the response as a failure even if the body includes a code field. Log the full body, the request path, and any cursor you already consumed.
HTTP status recovery
Credits and balance
Metered reads and writes spend account credits. When a job processes many pages, check balance before and after long runs:403 responses mention credits or access:
- Stop scheduled jobs that keep hammering the API.
- Confirm balance in the dashboard.
- Resume from the last saved cursor after credits are restored.
Pagination-safe retries
For search, followers, timelines, and DM history:- Store
next_cursor,has_next_page, and anytask_idoutside the agent conversation. - After
429or5xx, retry the same cursor, not the next page. - After
400,404, or422, inspect IDs and query parameters before retrying.
Write actions
Write endpoints (tweet, reply, like, follow, DM send) require:- A valid TwexAPI API key
- A saved Twitter cookie or
auth_tokenon the request
TwexAPI does not expose a separate write-action polling API. Prefer idempotent read checks (tweet lookup, DM status) before repeating side effects. Cookie setup and
403 recovery: Write Actions.
MCP errors
Authentication failed before the tool ran
When MCP authentication fails,explore and twexapi_request do not execute:
x-api-key or Authorization: Bearer on the MCP client, then rerun the tool call.
API error returned through twexapi_request
When the underlying REST call fails, preserve the tool result:
explore again if the route may have changed.
SDK and CLI errors
Generated SDKs map HTTP failures to language-native exceptions. Catch errors at the job boundary, log the status code and response body, and route429/5xx to retry policies.
Python example:
Retry backoff template
Use capped exponential backoff for429 and 5xx:
429.