API Authentication

Every API request requires authentication using an API key in the HTTP headers.

Getting Your API Key

  1. Log in to your TwitterXApi Dashboard
  2. Find your API key displayed on the dashboard homepage

Using Your API Key

All API requests must include the x-api-key header for authentication. Header format:

Authorization: Bearer YOUR_API_KEY

Example requests:

cURL

curl --request GET \
  --url 'https://api.twitterxapi.com/twitter/users?usernames=elonmusk' \
  --header 'Authorization: Bearer YOUR_API_KEY'

Python

import requests

url = "https://api.twitterxapi.com/twitter/users"

querystring = {"usernames":"elonmusk"}

headers = {"Authorization": "Bearer YOUR_API_KEY"}

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

JavaScript

const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer YOUR_API_KEY'
  }
};

fetch('https://api.twitterxapi.com/twitter/users?usernames=elonmusk', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

Java

HttpResponse<String> response = Unirest.get("https://api.twitterxapi.com/twitter/users?usernames=elonmusk")
  .header("Authorization", "Bearer YOUR_API_KEY")
  .asString();