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

# npm SDK Authentication

> Configure authentication for the Artos npm SDK using Bearer tokens and the reusable API client.

# npm SDK Authentication

The Artos npm SDK uses Bearer token authentication. You'll need your **organization access token** to make API calls.

## Basic Authentication

Pass your access token directly to each SDK function call:

```javascript theme={null}
const accessToken = 'your-organization-access-token'
const baseUrl = 'https://api.artosai.com'
```

<Warning>Store your access token in environment variables, not in your source code.</Warning>

```javascript theme={null}
const accessToken = process.env.ARTOS_ACCESS_TOKEN
const baseUrl = process.env.ARTOS_API_URL || 'https://api.artosai.com'
```

## Reusable API Client

For applications making frequent API calls, create a reusable API client with `createApiClient`:

```javascript theme={null}
import { createApiClient, getTemplateUrl } from '@artosai/sdk'

// Create a reusable client
const artosClient = createApiClient({
    baseUrl: 'https://api.artosai.com'
})

// Use the shared client for multiple calls
async function getMultipleTemplates(documentIds, accessToken) {
    const results = await Promise.all(
        documentIds.map(id => getTemplateUrl({
            documentId: id,
            accessToken,
            apiClient: artosClient
        }))
    )
    return results
}
```

### `createApiClient(config)`

Creates a reusable API client instance.

**Parameters:**

| Parameter  | Type     | Required | Description                                             |
| ---------- | -------- | -------- | ------------------------------------------------------- |
| `baseUrl`  | `string` | Yes      | The Artos API base URL                                  |
| `authMode` | `string` | No       | Authentication mode: `'bearer'` (default) or `'cookie'` |

**Returns:** `ApiClient`

```typescript theme={null}
interface ApiClient {
    call: (options: ApiCallOptions) => Promise<any>
    baseUrl: string
    authMode: string
}
```

## Common Authentication Errors

| Status Code | Description  | Recommended Action                                |
| ----------- | ------------ | ------------------------------------------------- |
| 401         | Unauthorized | Verify your access token is valid and not expired |
| 403         | Forbidden    | Confirm you have access to the requested resource |

### "401 Unauthorized" Error

1. Verify your access token is correct
2. Check if the token has expired
3. Contact Artos support for a new token if needed

### "403 Forbidden" Error

1. Verify the document ID is correct
2. Confirm your organization has access to this document
3. Contact your Artos account manager
