JavaScript / TypeScript
Install and configure @visgate_ai/client for Node.js, browsers, and frameworks.
Installation
Works in Node.js (18+), browsers, and with React, Vite, Next.js, and vanilla JS.
Basic Usage
Configuration
Browser / Proxy Mode
For browser apps, use a server proxy to keep your API key secure:
No apiKey needed — the proxy injects the key on the server. See Server Proxy for setup.
Session Auth
When using session tokens (e.g. Firebase), pass a getToken function:
If you use httpOnly cookies, do not use getToken. Use Client({ proxyUrl: "/api/visgate" }) and ensure requests send credentials so the cookie is included.
AsyncClient
For API parity with the Python SDK, AsyncClient is also exported with the same interface:
Features
- Promise-based API — all methods return Promises; use
async/awaitor.then() - Automatic retries — transient errors (429, 5xx) retried with exponential backoff
- Typed exceptions — catch
AuthenticationError,RateLimitError,ProviderError, etc. - Full TypeScript support — type definitions included
- Framework-agnostic — works in vanilla JS, React, Vite, Next.js