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

# TypeScript SDK

> Full documentation for the Anti AI TypeScript SDK.

## Installation

```bash theme={null}
npm install @oculus/sdk
```

## Quick reference

```typescript theme={null}
import { OculusClient } from '@oculus/sdk';
import { OculusAuthError, OculusAPIError, TokenRevokedException } from '@oculus/sdk';

const client = new OculusClient({
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
  baseUrl: 'https://api.antiailabs.com',
  onTokenRevoked: (jti) => console.warn(`Token ${jti} revoked`),
});

const token = await client.getToken('db:read');
const token2 = await client.getToken('db:read stripe:customer:read');
const token3 = await client.getToken('db:read', 'https://myservice.example.com');

client.destroy(); // on shutdown
```

## Full example

```typescript theme={null}
import { OculusClient } from '@oculus/sdk';
import { OculusAuthError, OculusAPIError, TokenRevokedException } from '@oculus/sdk';
import axios from 'axios';

const client = new OculusClient({
  clientId: process.env.AGENT_CLIENT_ID!,
  clientSecret: process.env.AGENT_CLIENT_SECRET!,
  baseUrl: process.env.ANTI_AI_URL ?? 'https://api.antiailabs.com',
  onTokenRevoked: (jti) => {
    console.error(`Token ${jti} was revoked — agent access terminated`);
  },
});

process.on('SIGTERM', () => client.destroy());
process.on('SIGINT', () => client.destroy());

async function callApi(url: string, scope: string): Promise<unknown> {
  let token: string;
  try {
    token = await client.getToken(scope);
  } catch (err) {
    if (err instanceof TokenRevokedException) {
      throw new Error('Agent access has been revoked. Contact your admin.');
    }
    if (err instanceof OculusAuthError) {
      throw new Error(`Authentication failed: ${err.message}`);
    }
    if (err instanceof OculusAPIError) {
      throw new Error(`Anti AI error (${err.statusCode}): ${err.message}`);
    }
    throw err;
  }
  const response = await axios.get(url, { headers: { Authorization: `Bearer ${token}` } });
  return response.data;
}
```

## Exception reference

| Exception               | When raised                                  | What to do                               |
| ----------------------- | -------------------------------------------- | ---------------------------------------- |
| `OculusAuthError`       | Invalid credentials, agent suspended/revoked | Check credentials; verify agent status   |
| `OculusAPIError`        | Any other API error                          | Check `err.statusCode` and `err.details` |
| `TokenRevokedException` | Cached token revoked                         | Alert your team — this is intentional    |
