@twitterapi_io/ai-sdk packages twitterapi.io endpoints as AI SDK tools. Pass them to generateText, streamText or an agent, and the model can search X and read profiles, timelines, mentions, conversation threads and trends on its own. All tools are read-only.
1. Install
2. Set your API key
Get a key on the dashboard and set it as an environment variable:3. Use the tools
stepCountIs(5) instead of isStepCount(5).
To give the model only some tools, import them one by one:
Tools
Paginated tools return
{ tweets, hasNextPage, nextCursor }, and the model passes nextCursor back as cursor for the next page. Tweets come back in a compact shape (id, url, text, createdAt, author, engagement counts, reply and thread ids) to keep token use low.
Each tool call costs the same credits as the endpoint it calls; see Pricing.
Options
TwitterApiIoError with an HTTP status, and the AI SDK reports them to the model as tool errors.
Security
- Tool results are posts written by X users. Each tool description tells the model to treat them as data, never as instructions; repeat that rule in your system prompt.
- Keep the API key in an environment variable, not in source code.
Links
- npm: @twitterapi_io/ai-sdk
- Source: github.com/kaitoInfra/twitterapi-io-ai-sdk
- Prefer MCP? Connect any MCP client to
https://mcp.twitterapi.io/mcp.