@ethicalzen/sdk
Version:
Official EthicalZen SDK for Node.js - AI safety guardrails made simple
151 lines • 5.33 kB
TypeScript
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
/**
* Simple configuration for EthicalZen Proxy Client
*/
export interface ProxyClientConfig {
gatewayURL: string;
certificateId: string;
tenantId?: string;
apiKey?: string;
timeout?: number;
}
/**
* EthicalZen Proxy Client
*
* Initialize once with gateway URL and certificate, then make normal REST API calls.
* The SDK automatically adds certificate headers, and the gateway intercepts, validates,
* and forwards requests to their original destination.
*
* **How it works:**
* 1. Client calls normal URL: `https://api.openai.com/v1/chat/completions`
* 2. SDK adds `X-Certificate-ID` header automatically
* 3. Gateway intercepts request, validates input with guardrails
* 4. Gateway forwards to original URL if validation passes
* 5. Gateway intercepts response, validates output with guardrails
* 6. Gateway returns response to client if validation passes
*
* @example
* ```typescript
* // Initialize once with certificate
* const client = new EthicalZenProxyClient({
* gatewayURL: 'http://gateway:8080',
* certificateId: 'hipaa-compliant-llm-v1',
* apiKey: 'sk-openai-key'
* });
*
* // Make normal API calls - uses REAL URL, certificate added automatically
* const response = await client.post('https://api.openai.com/v1/chat/completions', {
* model: "gpt-4",
* messages: [{ role: "user", content: "Hello" }]
* });
*
* // Response is validated by gateway before reaching client
* console.log(response.data);
* ```
*/
export declare class EthicalZenProxyClient {
private gatewayURL;
private certificateId;
private tenantId;
private client;
constructor(config: ProxyClientConfig);
/**
* Make a POST request through the gateway
*
* @param url - Normal service URL (e.g., https://api.openai.com/v1/chat/completions)
* @param data - Request body
* @param config - Optional axios config
* @returns Response from target service (after gateway validation)
*
* **Note:** SDK automatically packages certificate and routes through gateway.
* You use the REAL service URL, not a proxy URL.
*
* @example
* ```typescript
* // Use REAL OpenAI URL - SDK handles gateway routing automatically
* const response = await client.post(
* 'https://api.openai.com/v1/chat/completions',
* {
* model: "gpt-4",
* messages: [{ role: "user", content: "Hello" }]
* }
* );
* ```
*/
post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
/**
* Make a GET request through the gateway
*
* @param url - Normal service URL
* @param config - Optional axios config
* @returns Response from target service (after gateway validation)
*
* @example
* ```typescript
* const response = await client.get('https://api.example.com/data');
* ```
*/
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
/**
* Make a PUT request through the gateway
*
* @param url - Normal service URL
* @param data - Request body
* @param config - Optional axios config
* @returns Response from target service (after gateway validation)
*/
put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
/**
* Make a PATCH request through the gateway
*
* @param url - Normal service URL
* @param data - Request body
* @param config - Optional axios config
* @returns Response from target service (after gateway validation)
*/
patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
/**
* Make a DELETE request through the gateway
*
* @param url - Normal service URL
* @param config - Optional axios config
* @returns Response from target service (after gateway validation)
*/
delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
/**
* Make a request with custom method through the gateway
*
* @param config - Axios request config with method and url
* @returns Response from target service (after gateway validation)
*/
request<T = any, R = AxiosResponse<T>>(config: AxiosRequestConfig): Promise<R>;
/**
* Get the current gateway URL
* @returns Gateway base URL
*/
getGatewayURL(): string;
/**
* Get the current certificate ID
* @returns Certificate ID
*/
getCertificateId(): string;
/**
* Get the current tenant ID
* @returns Tenant ID
*/
getTenantId(): string;
/**
* Get proxy URL for a specific target (for reference/debugging)
* Note: The actual routing uses /api/proxy with headers, not this URL format
*
* @param targetURL - Target service URL
* @returns Formatted proxy URL (for reference only)
*/
getProxyURL(targetURL: string): string;
/**
* Get the underlying axios instance for advanced usage
* @returns Axios instance with interceptors configured
*/
getAxiosInstance(): AxiosInstance;
}
//# sourceMappingURL=proxy-client.d.ts.map