Skip to main content

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
When NOT to use this SDK:
  • You only need frontend recommendations (use admesh-ui-sdk instead)
  • You want a separate recommendations panel (use Tail/Product Format with admesh-ui-sdk)

Quick Start

Install the package:
Initialize the client:
Fetch recommendations:

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):
Yarn:
pnpm:

Core Concepts

AdMeshClient

The main client for fetching recommendations. Initialize once and reuse across your application.
Security: Never hardcode your API key. Always use environment variables or a secrets manager.

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
Your backend is responsible for generating and managing session and message IDs. The SDK accepts these IDs but does not generate them.

API Methods

getRecommendationsForWeave()

Fetches recommendations for a given query that can be woven into LLM responses.
Example:

Integration Example

Here’s a complete example showing how to fetch recommendations and pass them to your LLM:
Complete Integration: This example shows backend integration only. For frontend integration to detect and track the embedded links, see the Weave Ad Format guide.

Error Handling

Always wrap API calls in try-catch blocks:
Common scenarios:
  • 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:
All methods and interfaces are fully typed for the best developer experience.

Troubleshooting

No recommendations returned

Possible causes:
  • Query is too generic (try more specific queries)
  • No active campaigns match the query
  • API key is invalid
Solution:
  • 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
Example:

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
Solution:
  • 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/installation
You’re ready to start integrating.
Install @admesh/weave-node, fetch recommendations, and pass them to your LLM for natural weaving into responses.