Skip to main content

Usage

Learn how to use the Mentiora SDK to send traces and interact with the platform.

Basic Setup

import { MentioraClient } from '@mentiora.ai/sdk';

const client = new MentioraClient({
apiKey: process.env.MENTIORA_API_KEY,
});

Async/Sync Patterns

The TypeScript SDK uses an async-only API. All methods return Promises and must be awaited:

// All tracing methods are async
const result = await client.tracing.sendTrace(event);
await client.tracing.flush();

Why async-only?

The TypeScript SDK is designed exclusively for asynchronous operations for several important reasons:

  • Native fetch() is async-only: Modern JavaScript/TypeScript has no synchronous HTTP equivalent
  • Node.js ecosystem is async-first: Most Node.js libraries and frameworks use async patterns
  • Prevents blocking the event loop: Keeps your application responsive and performant
  • Consistency: All SDK methods follow the same async pattern, making the API predictable

Comparison with Python SDK

Unlike the Python SDK (which offers both sync and async APIs to support different Python ecosystems), the TypeScript SDK only provides async methods. This reflects the JavaScript/TypeScript ecosystem's strong preference for asynchronous operations.

// ✅ Always use await with TypeScript SDK
async function myHandler() {
const result = await client.tracing.sendTrace(event);
return result;
}

// ❌ No sync API available - this won't work correctly
function myHandler() {
const result = client.tracing.sendTrace(event); // Returns a Promise!
return result; // You'd be returning a Promise, not the result
}

Top-level await

In modern TypeScript/JavaScript environments (ES modules, Node.js 14.8+), you can use top-level await:

// ✅ Top-level await in ES modules
const result = await client.tracing.sendTrace(event);
console.log(result);

Resource Cleanup

While the TypeScript SDK doesn't require explicit cleanup (it uses stateless fetch()), a close() method is provided for API parity with the Python SDK:

// Optional cleanup (no-op but available for consistency)
client.close();

Note: Unlike Python's httpx client which maintains connection pools, the TypeScript SDK uses the native fetch() API which is stateless. The close() method is a no-op but is provided to maintain a consistent API surface across languages.

Next Steps

  • Tracing -- send traces for observability and debugging
  • Agents -- run and stream AI agents hosted on the platform
  • Plugins -- auto-trace OpenAI and LangChain calls
  • Streaming Helpers -- SSE utilities for web frontends