typescript-sdk
comet-ml/opik/.agents/skills/typescript-sdk/SKILL.md
TypeScript SDK patterns for Opik. Use when working in sdks/typescript.
Skill22k starsChanged 2 months ago
What's in it
- TypeScript SDK
- Architecture
- Layer Flow
- Critical Gotchas
- Flush Before Exit
- Domain Objects Don't Do HTTP
- Never Leak restapi
- Batching Semantics
- Error Handling
- Integration Guidelines
- Reference Files
---
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
```typescript
// ✅ REQUIRED - especially in CLI/tests
await client.flush();
// or globally:
await flushAll();
```
### Domain Objects Don't Do HTTP
```typescript
// ✅ GOOD - domain objects enqueue, not HTTP
trace.update({ metadata: { key: 'value' } }); // Enqueues update
trace.end(); // Enqueues update
// ❌ BAD - don't call REST directly from domain
```
### Never Leak rest_api
```typescript
// ✅ GOOD - export from public API
export { Opik, track, flushAll } from 'opik';
// ❌ BAD - don't expose generated clients
import { TracesApi } from 'opik/rest_api'; // Internal!
```
## 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](testing.md) - Vitest patterns, mocking, flush timing
More agent context in comet-ml/opik
20 other files this repository gives its agents.
AGENTS.md
Copilot instructions
Skill
- add-code-quality-hook.agents/skills/add-code-quality-hook/SKILL.md
- analytics-instrumentation.agents/skills/analytics-instrumentation/SKILL.md
- debugging-e2e-tests.agents/skills/debugging-e2e-tests/SKILL.md
- diagram-generation.agents/skills/diagram-generation/SKILL.md
- documentation.agents/skills/documentation/SKILL.md
- explore-feature.agents/skills/explore-feature/SKILL.md
- local-dev.agents/skills/local-dev/SKILL.md
- metrics-instrumentation.agents/skills/metrics-instrumentation/SKILL.md
- opik-backend.agents/skills/opik-backend/SKILL.md
- opik-external-integrations.agents/skills/opik-external-integrations/SKILL.md
- opik-frontend.agents/skills/opik-frontend/SKILL.md
- opik-integrations.agents/skills/opik-integrations/SKILL.md
- playwright-pom-discovery.agents/skills/playwright-pom-discovery/SKILL.md
- python-sdk.agents/skills/python-sdk/SKILL.md
- query-performance.agents/skills/query-performance/SKILL.md
- write-docs.agents/skills/write-docs/SKILL.md
- writing-e2e-tests.agents/skills/writing-e2e-tests/SKILL.md
- writing-visual-tests.agents/skills/writing-visual-tests/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
Reports can't be read right now.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool registry_write, action report. How to connect one.

