Overview
The admesh-weave-node SDK is a backend Node.js package that fetches personalized recommendations from AdMesh. Use it to retrieve recommendations that your LLM can naturally weave into responses. When to use this SDK:- You want to embed recommendations directly in LLM responses (Weave Ad Format)
- You need backend control over recommendation fetching
- You’re building a custom LLM integration
- You only need frontend recommendations (use admesh-ui-sdk instead)
- You want a separate recommendations panel (use Citation/Product Format with admesh-ui-sdk)
Quick Start
Install the package:Requirements
- Node.js 16.x or higher (LTS recommended)
- API key from AdMesh dashboard
- TypeScript support included
- Works with Express, Fastify, Next.js API routes, etc.
Installation Methods
npm (recommended):Core Concepts
AdMeshClient
The main client for fetching recommendations. Initialize once and reuse across your application.Session and Message IDs
AdMesh uses IDs to track user interactions:- Session ID: Unique identifier for a user’s conversation session
- Message ID: Unique identifier for each individual message/query
API Methods
getRecommendationsForWeave()
Fetches recommendations for a given query that can be woven into LLM responses.Integration Example
Here’s a complete example showing how to fetch recommendations and pass them to your LLM:Error Handling
Always wrap API calls in try-catch blocks:- result.found === false: No recommendations available for the query (not an error)
- Network errors: Retry with exponential backoff
- Invalid API key: Check environment variables
TypeScript Support
The SDK is written in TypeScript and includes full type definitions:Troubleshooting
No recommendations returned
Possible causes:- Query is too generic (try more specific queries)
- No active campaigns match the query
- API key is invalid
- Use more specific queries (e.g., “best CRM for startups” instead of “software”)
- Check that your AdMesh account has active campaigns
- Verify API key in environment variables
API key errors
Check:- ADMESH_API_KEY is set in environment variables
- API key is valid (check dashboard)
- No extra whitespace in the key value
TypeScript errors
Solution:- Ensure TypeScript 4.0 or higher
- Import types explicitly: import type from ‘@admesh/weave-node’
- Check tsconfig.json includes “moduleResolution”: “node”
Network/timeout errors
Check:- Server has internet access
- No firewall blocking outbound requests
- Network is stable
- Implement retry logic with exponential backoff
- Check server network configuration
Next Steps
Weave Ad Format Guide: Complete integration guide for embedding recommendations in LLM responses - /platforms/weave-ad-format Frontend SDK: Install admesh-ui-sdk to detect and track embedded links on the frontend - /ui-sdk/installationYou’re ready to start integrating.
Install @admesh/weave-node, fetch recommendations, and pass them to your LLM for natural weaving into responses.