Always specify the fields parameter to retrieve only the data you need. This dramatically improves response time and reduces memory usage.
TypeScript
Python
// Slow: returns all 20+ fields per postconst results = await client.twitter.searchPosts('AI');// Fast: returns only what you needconst results = await client.twitter.searchPosts('AI', { fields: ['id', 'text', 'likeCount', 'authorUsername', 'createdAtDate'],});
# Slow: returns all 20+ fields per postresults = client.twitter.search_posts("AI")# Fast: returns only what you needresults = client.twitter.search_posts( "AI", fields=["id", "text", "like_count", "author_username", "created_at_date"],)
For engagement analysis, use ["id", "text", "likeCount", "retweetCount", "replyCount", "createdAtDate"]. For user discovery, use ["id", "username", "name", "followersCount", "description"].
// Too broad: returns millions of results"AI"// Better: narrow with boolean operators"AI" AND "healthcare" AND 2025// Best: exact phrases with filters"AI-powered diagnostics" AND (healthcare OR medical)
from xpoz import ( AuthenticationError, OperationTimeoutError, XpozError, ResponseType,)def search_with_retry(query: str, retries: int = 2): for attempt in range(retries + 1): try: return client.twitter.search_posts( query, response_type=ResponseType.FAST, limit=100, ) except AuthenticationError: raise # Don't retry auth errors except OperationTimeoutError: if attempt < retries: print(f"Attempt {attempt + 1} timed out, retrying...") continue raise
Authentication errors (401) should never be retried. Timeout errors are safe to retry. Failed operations may indicate a server-side issue — check the operationError field for details.
Xpoz caches operation results server-side with a TTL:
Running operations: 30-minute TTL (auto-expire if stalled)
Completed operations: 15-minute TTL (retrieve results within this window)
Paginated tables: Remain available for page navigation after creation
For paging mode, the first call creates a server-side table with all results. Subsequent nextPage() and getPage(n) calls read from this cached table, making page navigation fast.
Always close the client when done to release resources:
TypeScript
Python
// Option 1: async disposal (Node.js 18.2+)await using client = new XpozClient({ apiKey: 'key' });await client.connect();// client.close() called automatically// Option 2: try/finallyconst client = new XpozClient({ apiKey: 'key' });await client.connect();try { const user = await client.twitter.getUser('elonmusk');} finally { await client.close();}
# Option 1: context managerwith XpozClient("key") as client: user = client.twitter.get_user("elonmusk")# client.close() called automatically# Option 2: async context managerasync with AsyncXpozClient("key") as client: user = await client.twitter.get_user("elonmusk")