Skip to main content
The X (Twitter) integration lets you index posts from any public X/Twitter account and make them searchable through Nia’s unified search. Pull in tweets, filter by replies and retweets, and query the content alongside all your other indexed sources.
This integration uses the X API v2. You need a valid bearer token from the X Developer Portal to get started.

Prerequisites

Before setting up the X integration, you need:
  1. A Nia API key — Get one at app.trynia.ai
  2. An X API bearer token — Create a project and app in the X Developer Portal to obtain a bearer token with read access
Your X API bearer token grants read access to public tweets. Store it securely in an environment variable or secret manager. Nia encrypts tokens at rest.

Getting Started

1

Get Your X API Bearer Token

Sign up at the X Developer Portal, create a project and app, and copy the bearer token from the “Keys and Tokens” section.
2

Create an Installation

Register the X account you want to index by providing the username and your bearer token via the Nia API.
3

Configure Options

Choose how many posts to fetch and whether to include replies and retweets.
4

Trigger Indexing

Start the indexing job. Nia fetches posts from the account, chunks and embeds them, and stores everything in the vector index.
5

Search

Query indexed posts through the unified search endpoint, alongside repositories, docs, Slack, and other sources.

Creating an Installation

Register an X account for indexing:
curl -X POST https://apigcp.trynia.ai/v2/x/installations \
  -H "Authorization: Bearer $NIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "username": "elaborateai",
    "bearer_token": "AAAAAAAAAAAAAAAAAAA...",
    "display_name": "Elaborate AI Posts",
    "max_results": 200,
    "include_replies": false,
    "include_retweets": false
  }'
{
  "id": "x-inst-7a3b9c01-...",
  "username": "elaborateai",
  "display_name": "Elaborate AI Posts",
  "max_results": 200,
  "include_replies": false,
  "include_retweets": false,
  "status": "created",
  "created_at": "2026-03-29T10:00:00Z"
}

Request Parameters

ParameterTypeRequiredDescription
usernamestringYesThe X/Twitter username (without the @)
bearer_tokenstringYesX API v2 bearer token
display_namestringNoA friendly label for this installation
max_resultsintegerNoNumber of posts to fetch per indexing run (1—500, default 100)
include_repliesbooleanNoInclude reply tweets (default false)
include_retweetsbooleanNoInclude retweets (default false)
The max_results parameter controls how many of the most recent posts are fetched each time indexing runs. Set it higher to capture more history, or lower to focus on recent content.

Managing Installations

List All X Installations

curl https://apigcp.trynia.ai/v2/x/installations \
  -H "Authorization: Bearer $NIA_API_KEY"
{
  "installations": [
    {
      "id": "x-inst-7a3b9c01-...",
      "username": "elaborateai",
      "display_name": "Elaborate AI Posts",
      "max_results": 200,
      "include_replies": false,
      "include_retweets": false,
      "status": "indexed",
      "indexed_post_count": 200,
      "last_indexed_at": "2026-03-29T10:15:00Z"
    }
  ]
}

Get a Single Installation

curl https://apigcp.trynia.ai/v2/x/installations/x-inst-7a3b9c01-... \
  -H "Authorization: Bearer $NIA_API_KEY"

Delete an Installation

Remove an installation and all its indexed data:
curl -X DELETE https://apigcp.trynia.ai/v2/x/installations/x-inst-7a3b9c01-... \
  -H "Authorization: Bearer $NIA_API_KEY"
{
  "message": "Installation deleted and indexed data removed."
}
Deleting an installation permanently removes all indexed post data from Nia. This cannot be undone.

Indexing

Trigger Indexing

Start an indexing job to fetch and index posts from the configured X account:
curl -X POST https://apigcp.trynia.ai/v2/x/installations/x-inst-7a3b9c01-.../index \
  -H "Authorization: Bearer $NIA_API_KEY"
{
  "installation_id": "x-inst-7a3b9c01-...",
  "status": "processing",
  "workflow_run_id": "wf-89ab12cd-..."
}

Check Indexing Status

curl https://apigcp.trynia.ai/v2/x/installations/x-inst-7a3b9c01-.../status \
  -H "Authorization: Bearer $NIA_API_KEY"
{
  "installation_id": "x-inst-7a3b9c01-...",
  "username": "elaborateai",
  "status": "processing",
  "progress": 65,
  "message": "Fetching and embedding posts (130/200)",
  "indexed_post_count": 130,
  "chunk_count": 145
}
StatusMeaning
createdInstallation created, not yet indexed
processingIndexing is in progress
indexedIndexing completed successfully
failedIndexing encountered an error

Configuration Options

Control what gets indexed by adjusting the installation parameters at creation time.

max_results

Fetch between 1 and 500 of the most recent posts per indexing run. Higher values capture more history but take longer.

include_replies

When enabled, reply tweets from the account are included in the index. Useful for capturing conversational context.

include_retweets

When enabled, retweets are included. Disable to focus only on original content from the account.

Searching Indexed Posts

Once indexed, posts from X accounts are searchable through Nia’s unified search endpoint:
curl -X POST https://apigcp.trynia.ai/v2/search/query \
  -H "Authorization: Bearer $NIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "What has this account said about AI agents?"}],
    "include_sources": true,
    "stream": true
  }'
You can combine X posts with other sources for cross-source queries:
curl -X POST https://apigcp.trynia.ai/v2/search/query \
  -H "Authorization: Bearer $NIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "Compare the public announcements with the actual implementation"}],
    "repositories": [{"repository": "acme/product"}],
    "include_sources": true,
    "stream": true
  }'
Streamed response:
data: {"content": "Based on the indexed posts from @elaborateai and the repository code..."}
data: {"sources": [{"content": "@elaborateai (2026-03-15): We just shipped...", "metadata": {...}}]}
data: [DONE]

API Reference

MethodEndpointDescription
GET/v2/x/installationsList all X installations
POST/v2/x/installationsCreate a new installation
GET/v2/x/installations/{id}Get installation details
DELETE/v2/x/installations/{id}Delete an installation
POST/v2/x/installations/{id}/indexTrigger indexing
GET/v2/x/installations/{id}/statusGet indexing status

Re-index whenever you want to capture new posts. Since the integration fetches the most recent posts (up to max_results), running indexing periodically keeps the content fresh. You can trigger it manually or build automation around the API.
The X API v2 bearer token only provides access to public tweets. Protected accounts cannot be indexed unless you use an OAuth token with appropriate access, which is not currently supported by this integration.
A Basic or Pro plan on the X Developer Portal is sufficient. The Free tier has limited tweet read access and may not support the max_results range needed. Check the X API documentation for current tier details.

Need Help? Join our Discord community or reach out through app.trynia.ai for support.