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

# Client and authentication

> Configure the Node.js SDK client and log in to Infisical.

Every call to Infisical goes through an `InfisicalSDK` client. You create the client once, log it in as a [machine identity](https://infisical.com/docs/documentation/platform/identities/machine-identities.md), and then use it for every request.

## Create a client

Create the client with the URL of your Infisical instance in `siteUrl`. If you use the US region of Infisical Cloud, you can leave `siteUrl` out.

```typescript US Cloud theme={"dark"}
import { InfisicalSDK } from "@infisical/sdk";

const client = new InfisicalSDK();
```

```typescript EU Cloud theme={"dark"}
import { InfisicalSDK } from "@infisical/sdk";

const client = new InfisicalSDK({ siteUrl: "https://eu.infisical.com" });
```

```typescript Self-hosted theme={"dark"}
import { InfisicalSDK } from "@infisical/sdk";

const client = new InfisicalSDK({ siteUrl: "<your-instance-url>" });
```

**Parameters:**

**options** `object`

**properties**

**siteUrl** `string` (default: [https://app.infisical.com](https://app.infisical.com))

The URL of your Infisical instance.

## Log in

The client logs in with one of the machine identity's [authentication methods](https://infisical.com/docs/documentation/platform/identities/machine-identities.md#authentication-methods). After the client logs in, it sends the access token it got with every request.

### Universal Auth

```typescript theme={"dark"}
await client.auth().universalAuth.login({
  clientId: process.env.INFISICAL_UNIVERSAL_AUTH_CLIENT_ID!,
  clientSecret: process.env.INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET!,
});
```

**Parameters:**

**options** `UniversalAuthLoginRequest` *required*

**properties**

**clientId** `string` *required*

The client ID of the machine identity's [Universal Auth](https://infisical.com/docs/documentation/platform/identities/universal-auth.md) configuration.

**clientSecret** `string` *required*

A client secret of the machine identity's Universal Auth configuration.

### AWS auth

If your application runs on AWS, it can log in through [AWS Auth](https://infisical.com/docs/documentation/platform/identities/aws-auth.md) with the AWS credentials it already has:

```typescript theme={"dark"}
await client.auth().awsIamAuth.login({
  identityId: "<machine-identity-id>",
});
```

The SDK gets the details it needs from the AWS environment:

* **AWS credentials:** the same way the AWS SDK for JavaScript does, such as from environment variables or the IAM role of an EC2 instance or Lambda function
* **AWS region:** from the `AWS_REGION` environment variable, or from the EC2 instance metadata if `AWS_REGION` isn't set

**Parameters:**

**options** `object`

**properties**

**identityId** `string`

The ID of the machine identity. Defaults to the value of the `INFISICAL_MACHINE_IDENTITY_ID` environment variable.

### Access token

If your application gets an access token some other way, such as from the [Infisical Agent](https://infisical.com/docs/integrations/platforms/infisical-agent.md), give the token to the client:

```typescript theme={"dark"}
client.auth().accessToken("<access-token>");
```

**Parameters:**

**token** `string` *required*

The access token, without the `Bearer` prefix.

To read the token that the client uses, call `client.auth().getAccessToken()`. It returns `null` if the client hasn't logged in.

## Renew the access token

The SDK doesn't renew the access token on its own. The token expires after the **Access Token TTL** set in the machine identity's auth method. Each renewal extends the token by its TTL, up to the **Access Token Max TTL**. After the max TTL, log in again. If your application runs longer than the TTL, renew the token before it expires:

```typescript Universal Auth theme={"dark"}
await client.auth().universalAuth.renew();
```

```typescript AWS Auth theme={"dark"}
await client.auth().awsIamAuth.renew();
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.