> ## Documentation Index
> Fetch the complete documentation index at: https://docs.twexapi.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Bearer token authentication for Twexapi — use with Cursor, Claude Code, GitHub Copilot, ChatGPT, and AI coding agents. Get started in minutes.

## **API Authentication**

Twexapi uses Bearer token authentication to secure all API requests. Each request must include a valid API key in the Authorization header to access our endpoints.

## Getting Your API Key

Follow these simple steps to obtain your API key:

1. Sign in to your [Twexapi Dashboard](https://twexapi.io/dashboard)
2. Your unique API key will be displayed prominently on the dashboard homepage
3. Copy the key securely - you'll need it for all API requests

<Tip>
  Keep your API key secure and never expose it in client-side code or public repositories.
</Tip>

***

## Using Your API Key

Include your API key in the `Authorization` header of every request using the Bearer token format:

**Required Header:**

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

***

## **Authenticate with AI Coding Agents**

Install the TwexAPI skill so **Cursor**, **Claude Code**, **GitHub Copilot**, **ChatGPT**, **Cline**, **Windsurf**, **Codex**, **Gemini CLI**, **Continue**, **Roo Code**, and other AI assistants know how to attach Bearer tokens correctly. Setup guides and CLI options are on the [integrations hub](https://twexapi.io/integrations).

<Tip>
  Copy your API key from the [dashboard](https://twexapi.io/dashboard), store it in an environment variable, and ask your agent to wire up `Authorization: Bearer YOUR_API_KEY` — the skill covers the auth pattern across cURL, Python, JavaScript, and more.
</Tip>

```bash theme={null}
npx skills add yeahjjyy/twexapi-cli
```

In Cursor, GitHub Copilot, Claude Code, ChatGPT, Continue, Roo Code, or any supported agent, try prompts like *"configure Twexapi auth from my `.env` file"*, *"add Bearer authentication to this API client"*, or *"generate a test request with my API key"*.

***

## **Implementation Examples**

Here are practical examples showing how to authenticate your requests across different programming languages:

<Note>
  Replace `YOUR_API_KEY` with your actual API key from the dashboard. All examples fetch user information for demonstration purposes.
</Note>

### cURL

Perfect for testing and quick API exploration:

```bash theme={null}
curl --request GET \
  --url 'https://api.twexapi.io/twitter/users?usernames=elonmusk' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json'
```

### Python

Using the popular `requests` library:

```python theme={null}
import requests

# API endpoint and parameters
url = "https://api.twexapi.io/twitter/users"
params = {"usernames": "elonmusk"}

# Authentication header
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}

# Make the request
response = requests.get(url, headers=headers, params=params)

# Handle the response
if response.status_code == 200:
    data = response.json()
    print(data)
else:
    print(f"Error: {response.status_code} - {response.text}")
```

### JavaScript (Node.js/Browser)

Modern fetch API implementation:

```javascript theme={null}
const fetchUserData = async () => {
  const options = {
    method: 'GET',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    }
  };

  try {
    const response = await fetch(
      'https://api.twexapi.io/twitter/users?usernames=elonmusk', 
      options
    );
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Request failed:', error);
  }
};

fetchUserData();
```

### Java

Using Unirest for simplified HTTP requests:

```java theme={null}
import kong.unirest.HttpResponse;
import kong.unirest.Unirest;

public class TwitterApiExample {
    public static void main(String[] args) {
        try {
            HttpResponse<String> response = Unirest
                .get("https://api.twexapi.io/twitter/users?usernames=elonmusk")
                .header("Authorization", "Bearer YOUR_API_KEY")
                .header("Content-Type", "application/json")
                .asString();
            
            if (response.getStatus() == 200) {
                System.out.println(response.getBody());
            } else {
                System.err.println("Error: " + response.getStatus() + " - " + response.getBody());
            }
        } catch (Exception e) {
            System.err.println("Request failed: " + e.getMessage());
        }
    }
}
```

## **Best Practices**

* **Environment Variables**: Store your API key in environment variables, never hardcode it
* **Error Handling**: Always implement proper error handling for API responses
* **Rate Limiting**: Respect API rate limits to avoid service interruptions
* **HTTPS Only**: All requests must use HTTPS for security
