TypeScript SDK Installation
Install Package
The SDK (v0.2.73) ships as dual ESM + CJS. Both import and require work out of the box.
Requirements
| Requirement | Minimum |
|---|
| TypeScript | 5.0+ |
| Node.js | 18+ |
| Bun | 1.1+ |
TypeScript Configuration
The SDK requires TypeScript 5.0+ for full type support.
// tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true
}
}
Initialize Client
The SDK auto-reads the MUTAGENT_API_KEY environment variable if no explicit credentials are provided.
import { Mutagent } from '@mutagent/sdk';
// Option 1: Auto-read from MUTAGENT_API_KEY env var (recommended)
const client = new Mutagent();
// Option 2: Explicit API key
const client = new Mutagent({
security: { apiKey: process.env.MUTAGENT_API_KEY },
});
// Option 3: Bearer auth (OAuth flows)
const client = new Mutagent({
security: { bearerAuth: 'your-oauth-token' },
});
Verify Setup
// Test your connection
const prompts = await client.prompt.listPrompts({ limit: 1 });
for await (const page of prompts) {
console.log('Connection successful!');
console.log('Found', page.data?.length ?? 0, 'prompts');
}
What’s Exported
Main entry point
import {
Mutagent, // Main client class
SDKOptions, // Client configuration type
HTTPClient, // Custom HTTP client interface
} from '@mutagent/sdk';
Error types
import {
MutagentError, // Base error class for all HTTP errors
SDKError, // Fallback error (unmatched status codes)
SDKValidationError, // Request validation errors
ResponseValidationError, // Response validation errors
} from '@mutagent/sdk/models/errors';
Tracing (separate subpath export)
import {
initTracing,
shutdownTracing,
trace,
withTrace,
startSpan,
endSpan,
} from '@mutagent/sdk/tracing';
Models and operations
import * as models from '@mutagent/sdk/models';
import * as operations from '@mutagent/sdk/models/operations';