---
title: "JavaScript SDK Authentication"
description: "Authenticate with the TraceRTM JavaScript SDK"
keywords: [javascript, sdk, authentication, api keys, tokens]
---

# JavaScript SDK Authentication

The TraceRTM JavaScript SDK supports multiple authentication methods.

## API Key Authentication

### Basic Usage

```javascript
import { TraceRTM } from '@tracertm/sdk';

const client = new TraceRTM({
  apiKey: 'rtm_live_abc123...'
});
```

### From Environment Variable

```javascript
const client = new TraceRTM({
  apiKey: process.env.TRACERTM_API_KEY
});
```

## Token Authentication

### Using Access Token

```javascript
const client = new TraceRTM({
  accessToken: 'eyJhbGciOiJSUzI1NiIs...'
});
```

### Token Refresh

```javascript
const client = new TraceRTM({
  accessToken: 'current_token',
  refreshToken: 'refresh_token_abc123...',
  onTokenRefresh: (newToken) => {
    // Save new token
    saveToken(newToken);
  }
});
```

## Error Handling

```javascript
import { TraceRTM, AuthenticationError } from '@tracertm/sdk';

try {
  const client = new TraceRTM({ apiKey: 'invalid_key' });
  await client.projects.list();
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Authentication failed:', error.message);
  }
}
```

## Next Steps

- [Artifacts](./04-artifacts) - Working with items
- [Examples](./06-examples) - Code examples
