Skip to main content
@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

Works with AI SDK v5 and later.

2. Set your API key

Get a key on the dashboard and set it as an environment variable:

3. Use the tools

On AI SDK v5 and v6, use 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

Errors such as an invalid key or an unknown user are thrown as 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.