You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When failOpen: true, all methods catch errors and return safe defaults (undefined) instead of throwing. Ideal for production where observability should never crash your app.
constclient=newAgentLensClient({url: 'http://localhost:3400',failOpen: true,onError: (err)=>myLogger.warn('AgentLens error:',err.message),});// This won't throw even if the server is downconstevents=awaitclient.queryEvents({agentId: 'my-agent'});
Error Handling
All errors extend AgentLensError:
import{AgentLensError,AuthenticationError,// 401NotFoundError,// 404ValidationError,// 400ConnectionError,// network/timeoutRateLimitError,// 429 (has .retryAfter)QuotaExceededError,// 402BackpressureError,// 503}from'@agentkitai/agentlens-sdk';try{awaitclient.getEvent('bad-id');}catch(err){if(errinstanceofNotFoundError){console.log('Event not found');}elseif(errinstanceofRateLimitError){console.log(`Retry after ${err.retryAfter}s`);}}
Drop-in instrumentation (#123)
Capture every model call with one init() — no manual logLlmCall. Each
capture computes per-call cost at capture time (@agentkitai/pricing), is
hash-chained via /api/events, and — when an AgentGate agentToken is supplied
— carries a server-verifiedverifiedAgentId. Captures are fail-safe: a
capture error never breaks your provider call.
import{init,shutdown}from'@agentkitai/agentlens-sdk';init({url: 'http://localhost:3400',apiKey: process.env.AGENTLENS_API_KEY,agentId: 'my-agent',agentToken: process.env.AGENTLENS_AGENT_TOKEN,// → verified identity});// ... run your agent ...awaitshutdown();// flush in-flight captures before exit
OpenAI Node SDK
importOpenAIfrom'openai';import{instrumentOpenAI}from'@agentkitai/agentlens-sdk/openai';constopenai=instrumentOpenAI(newOpenAI());awaitopenai.chat.completions.create({model: 'gpt-4o',messages: [...]});// streaming is captured too (set stream_options: { include_usage: true } for token cost)
Vercel AI SDK
import{wrapLanguageModel}from'ai';import{openai}from'@ai-sdk/openai';import{agentlensMiddleware}from'@agentkitai/agentlens-sdk/vercel';constmodel=wrapLanguageModel({model: openai('gpt-4o'),middleware: agentlensMiddleware()});// generateText / streamText against `model` are captured (cost + identity)
Wrappers are duck-typed — no openai/ai peer dependency. generateText,
streamText, and tool calls are captured; streams pass through unchanged.