Skip to main content

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.

Installation

npm install @oculus/sdk

Quick reference

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

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

ExceptionWhen raisedWhat to do
OculusAuthErrorInvalid credentials, agent suspended/revokedCheck credentials; verify agent status
OculusAPIErrorAny other API errorCheck err.statusCode and err.details
TokenRevokedExceptionCached token revokedAlert your team — this is intentional