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

# Authentication

> Authenticate the ReyGrid TypeScript SDK with an API key.

Provide your API key when creating the client. The SDK sends it as `Authorization: Bearer <key>` on every request.

```typescript theme={"system"}
import { ReyGrid } from "reygrid";

const client = new ReyGrid({ apiKey: process.env.REYGRID_API_KEY });
```

## Change the key at runtime

```typescript theme={"system"}
client.setApiKey("new-key");   // returns the client, so calls can be chained
client.setApiKey(undefined);   // clear
client.getApiKey();            // string | undefined
```

## Validate the key

```typescript theme={"system"}
const v = await client.validate();
console.log(v.valid, v.usage.total, v.usage.quotaLimit);

const usage = await client.getUsage(); // shortcut for (await validate()).usage
```

A missing or invalid key throws [`ReyGridAuthError`](/integrations/typescript/error-handling).

<Warning>
  Don't put API keys in browser bundles. Call ReyGrid from your server. See [REST API authentication](/rest-api/authentication) for security guidance.
</Warning>


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