Non-Blocking Client Wrapper (shdw.wrapClient) & Fail-Silent Guarantee

Getting Started & SDK
#wrapClient#sdk#openai#anthropic#gemini#sse#streaming#timeout#fail-silent#retry

Wrap OpenAI, Anthropic or Google Gemini clients in one line of code with a strict 1500ms AbortController timeout and automatic 5xx retry buffering.

How It Works Under the Hood
  • •shdw.wrapClient(client) uses a lightweight JavaScript Proxy to observe .create(), .stream(), and .generateContent() calls without mutating your AI SDK client.
  • •For standard responses and Server-Sent Events (SSE) streams, @shdwsdk/sdk normalizes input and output token counts in memory and queues an event on a non-blocking microtask.
  • •Background network flushes use an AbortController strictly clamped to <= 1500ms. If a 5xx server error or network outage occurs and buffer capacity permits (< 450 events), failed batches are automatically unshifted back onto the buffer for retry.
How to Use It Step-by-Step
  1. 1Create an API key in Settings → Developer Settings & API Keys.
  2. 2Install @shdwsdk/sdk via npm, pnpm, yarn, or bun.
  3. 3Wrap your AI client instance with shdw.wrapClient() and use it normally across your application.
src/lib/ai.ts — Wrapping OpenAI & Anthropic
import OpenAI from "openai";
import { ShdwTelemetryClient } from "@shdwsdk/sdk";

const shdw = new ShdwTelemetryClient({
  apiKey: process.env.SHDW_API_KEY!,
  endpoint: "https://www.shdwsdk.ai/api/v1/ingest-telemetry",
  defaultGridRegion: "eu-north-1", // or "us-west-2"
  defaultWorkloadName: "Enterprise Support Copilot",
  timeoutMs: 1500,
});

export const openai = shdw.wrapClient(new OpenAI());

Related guides