| name | typescript-sdk |
| description | TypeScript SDK patterns for Opik. Use when working in sdks/typescript. |
TypeScript SDK
Architecture
- Layered, non-blocking by default
- Data buffered and flushed async to backend
- Node >= 18, ESM + CJS builds
Layer Flow
Public API → OpikClient → Domain (Trace/Span) → BatchQueues → REST Client → Backend
Critical Gotchas
- When changing dependencies or minimum versions, update and verify version references in
README.md and integration README files in the same PR.
Flush Before Exit
await client.flush();
await flushAll();
Domain Objects Don't Do HTTP
trace.update({ metadata: { key: 'value' } });
trace.end();
Never Leak rest_api
export { Opik, track, flushAll } from 'opik';
import { TracesApi } from 'opik/rest_api';
Batching Semantics
- Updates wait for pending creates
- Deletes wait for creates and updates
flush() flushes all queues in order
- Debounce window configurable via
OpikConfig
Error Handling
- HTTP failures:
OpikApiError, OpikApiTimeoutError
- 404s translate to domain errors:
DatasetNotFoundError, ExperimentNotFoundError
- Never swallow errors, include context in logs
Integration Guidelines
- Integrations wrap public API only
- Keep adapters thin, non-blocking
- Provide
flush() escape hatch if needed
Reference Files
- testing.md - Vitest patterns, mocking, flush timing