xquik-haystack for current tweets. This Haystack AI framework gives you typed tweet Document objects. Each includes text, authors, metrics, and URLs.
This Haystack AI API integration supports RAG pipelines and agent workflows. You can follow this guide when building AI applications with Haystack and current tweets. The integration never grants write access.
The integration provides two read-only components:
Search Public Tweets
XquikTweetSearch searches keywords, hashtags, accounts, conversations, and
exact phrases.Fetch User Timelines
XquikUserTweetsFetcher retrieves one public account’s tweets and optional
replies.XquikTweetSearch with ComponentTool when an agent needs a search tool called search_current_tweets.
Use the followers API for follower exports. Use the write API for approved publishing. Those actions stay outside this integration.
Install Haystack and Xquik
Use Python 3.10 or newer. Pin both packages for repeatable pipeline builds.0.1.3 is published on PyPI. Haystack 3.0.0 supports sync and async runs.
The pip install command pins both packages for repeatable builds.
Create an Xquik API key, then export it locally.
Secret object.
Search Twitter Tweets in Python
XquikTweetSearch calls the GET /x/tweets/search search endpoint. It accepts standard X search syntax and structured filters. Use it for each Twitter API keyword search or exact phrase query.
Latest for recent monitoring. Use Top for engagement-ranked discovery. Store tweet IDs because rankings can change.
Save every search query beside its tweet IDs. Set top_k to cap the number of tweets in each run.
Build Focused Tweet Searches
The API also supports structured search filters. Pass them through
extra_params during initialization.
extra_params.
Choose a Search Window
Bound every retrieval with timestamps.Document.meta["id"].
Fetch a Twitter User Timeline
UseXquikUserTweetsFetcher for GET /x/users/{id}/tweets. Pass a username or numeric X user ID.
include_replies=True for replies. Enable parent tweets only when reply context matters. Choose search for many accounts and timelines for one account.
Understand Haystack Document Fields
Each tweet becomes one HaystackDocument. Tweet text becomes Document.content. Stable fields become metadata.
Missing fields stay absent. Never treat missing metrics as zero. The
links output contains each available meta.url.
Build Reliable RAG Citations
Store tweet IDs and canonical URLs before embedding tweet text. This preserves evidence after ranking or joining.conversation_id for reply threads.
Treat Tweet Text as Untrusted Context
Tweets can contain prompt injection and unsafe URLs. Never treat tweet text as a system instruction. Keep tweets separate from instructions and tool permissions. Limit retrieval by topic and time. Preserve tweet IDs, authors, timestamps, and URLs. Require citations. Review sensitive conclusions. Likes and reposts rank results. They do not prove accuracy. Treat outputs from large language models (LLMs) as proposals, not evidence.Index Tweets or Retrieve Them Live
Choose the pipeline pattern that matches freshness requirements.Live Retrieval
Search during each question for recent tweets and active events.
Indexed Corpus
Store embeddings for repeated research across stable windows.
meta.id for deduplication.
Paginate Without Duplicate Tweets
Both components returnhas_more and next_cursor. Keep the request unchanged. Treat cursors as opaque strings.
Document.meta["id"].
Run Haystack Pipelines Asynchronously
Haystack 3 uses onePipeline class. Both Xquik components expose run_async().
Handle Every Documented Error
The integration raiseshttpx.HTTPStatusError. Branch on the canonical status before retrying.
Pipeline Handoff
Use this shape when Haystack hands results to a vector store, evaluation job, queue, CSV export, or dashboard.Document Rows
Store content, tweet IDs, URLs, timestamps, authors, and public metrics.
Citation Links
Join each canonical URL to
meta.id.Pagination Checkpoint
Store the request, options,
has_more, and next_cursor.Failure Branch
Store each HTTP status with its pipeline run ID.
Haystack Component or Direct REST API
Does your pipeline already returnDocument objects? Add these components directly. They normalize tweet text, metadata, URLs, and pagination.
Use direct Xquik REST routes for followers, following, replies, quotes, reposts, lists, communities, media, trends, monitors, approved writes, and extra query options.
Both approaches use the same Xquik contracts. Components only support tweet search and user timelines.
Migrate to Haystack 3
Haystack 3 replacesAsyncPipeline with Pipeline. Call await pipeline.run_async(...) for concurrent execution. Keep meta.id as the tweet identity.
Test with haystack-ai==3.0.0 before upgrading. Check the official migration guide for other changes.
Common Haystack Twitter API Questions
What Is Haystack AI?
Haystack links search, RAG, and AI agents inside Python pipelines.How Does the Twitter API Search Tweets?
It accepts queries, filters, ordering, and cursors. Xquik returns tweets and citation URLs.What Is a Twitter Search API Python Workflow?
Install both packages. RunXquikTweetSearch, then process documents, links, and cursors.
How Does an API Twitter Search Workflow Preserve Cursors?
Savenext_cursor after each page. Reuse every filter.
How Does the Twitter API Search Tweets by Keyword?
Pass keywords, phrases, hashtags, accounts, or filters. ChooseLatest or Top.
Haystack AI vs LangChain: Which Fits Twitter RAG?
Choose Haystack forDocument pipelines. Choose LangChain for its retrievers and tools.