SDK Guide
@agentscrimmage/observe — auto-batching, retry, and one-line wrappers for Anthropic and OpenAI.
Install
npm install @agentscrimmage/observeInitialize
TypeScript
import { observe } from '@agentscrimmage/observe'
const client = observe({
apiKey: 'as_live_your_key_here',
// Optional:
// baseUrl: 'https://agentscrimmage.com', // default
// batchSize: 25, // flush after N traces
// flushIntervalMs: 5000, // flush every 5s
// debug: false, // log to console
// onError: (err, traces) => { ... }, // called on flush failure
})Wrap Anthropic calls
TypeScript
import { observe, wrapAnthropicCall } from '@agentscrimmage/observe'
import Anthropic from '@anthropic-ai/sdk'
const client = observe({ apiKey: 'as_live_xxx' })
const anthropic = new Anthropic()
// One line — latency + tokens traced automatically
const response = await wrapAnthropicCall(
client,
() => anthropic.messages.create({
model: 'claude-sonnet-4',
messages: [{ role: 'user', content: 'Hello' }],
max_tokens: 1024,
}),
{ sessionId: 'conv-123', userId: 'user-456' }
)
// response is the normal Anthropic Message object — use it as usualWrap OpenAI calls
TypeScript
import { observe, wrapOpenAICall } from '@agentscrimmage/observe'
import OpenAI from 'openai'
const client = observe({ apiKey: 'as_live_xxx' })
const openai = new OpenAI()
const response = await wrapOpenAICall(
client,
() => openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello' }],
}),
{ sessionId: 'conv-123', userId: 'user-456' }
)Send traces manually
TypeScript
// Any trace type
client.sendTrace({
traceId: crypto.randomUUID(),
sessionId: 'conv-123',
userId: 'user-456',
type: 'agent_response',
llm: {
provider: 'anthropic',
model: 'claude-sonnet-4',
outputMessage: 'Your order shipped on July 5th.',
inputTokens: 32,
outputTokens: 15,
latencyMs: 650,
},
})
// Tool calls
import { sendToolTrace } from '@agentscrimmage/observe'
sendToolTrace(client, {
name: 'search_orders',
arguments: { orderId: '1234' },
result: { status: 'shipped' },
success: true,
latencyMs: 120,
}, { sessionId: 'conv-123' })
// User messages
import { sendUserMessage } from '@agentscrimmage/observe'
sendUserMessage(client, 'Where is my order?', { sessionId: 'conv-123', userId: 'user-456' })Shutdown
Call shutdown() before your process exits to flush any remaining traces:
await client.shutdown() // flushes remaining traces + stops timerHow batching works
- Traces are queued in memory and flushed when the batch is full (default: 25) or the timer fires (default: every 5 seconds)
sendTrace()never blocks — errors go toonErrorcallback- Server errors (5xx) retry up to 2 times with 1-second backoff
- The flush timer uses
unref()so it doesn't keep Node.js alive