Skip to main content

TypeScript SDK Installation

Technical guide for installing and configuring the AdMesh TypeScript SDK for Node.js applications and serverless functions.

Installation

NPM Installation

npm install admesh

Yarn Installation

yarn add admesh

PNPM Installation

pnpm add admesh

Basic Configuration

Environment Setup

// .env
ADMESH_API_KEY=your_api_key_here
ADMESH_BASE_URL=https://api.useadmesh.com

Client Initialization

import Admesh from 'admesh';

// Environment variable configuration (recommended)
const client = new Admesh({
apiKey: process.env.ADMESH_API_KEY
});

// Direct configuration
const client = new Admesh({
apiKey: 'your_api_key_here',
baseUrl: 'https://api.useadmesh.com'
});

Basic Usage

Get Recommendations

import Admesh from 'admesh';

const client = new Admesh({
apiKey: process.env.ADMESH_API_KEY
});

async function getRecommendations() {
try {
const response = await client.recommend.getRecommendations({
query: 'Enterprise CRM solutions',
format: 'auto'
});

console.log('Recommendations:', response.recommendations);
} catch (error) {
console.error('Error:', error);
}
}

Configuration Options

Client Configuration

interface AdmeshConfig {
apiKey: string;
baseUrl?: string;
timeout?: number;
retries?: number;
}

const client = new Admesh({
apiKey: process.env.ADMESH_API_KEY,
baseUrl: 'https://api.useadmesh.com',
timeout: 30000,
retries: 3
});

Error Handling

import Admesh, { AdmeshError, AuthenticationError } from 'admesh';

try {
const response = await client.recommend.getRecommendations({
query: 'CRM software'
});
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Authentication failed:', error.message);
} else if (error instanceof AdmeshError) {
console.error('AdMesh API error:', error.message);
} else {
console.error('Unexpected error:', error);
}
}

Next Steps