Overview
The admesh-weave-python SDK is a backend Python 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 with Python
- 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
- Python 3.8 or higher
- API key from AdMesh dashboard
- Full type hints included
- Works with FastAPI, Flask, Django, etc.
Installation Methods
pip (recommended):Core Concepts
AdMeshClient
The main client for fetching recommendations. Initialize once and reuse across your application.api_key(required): Your AdMesh API key from the dashboardapi_base_url(optional): Custom API endpoint (defaults to production)
Session and Message IDs
Every recommendation request requires:- session_id: Unique identifier for the user’s conversation session
- message_id: Unique identifier for each message in the conversation
- query: The user’s search query (required for contextual recommendations)
Basic Usage
Async Usage (Recommended)
Synchronous Usage
Integration Examples
FastAPI Example
Flask Example
Environment Variables
Store your API key securely using environment variables:API Reference
get_recommendations_for_weave()
Async method to fetch recommendations. Parameters:session_id(str, required): Session identifiermessage_id(str, required): Message identifierquery(str, required): User’s search querytimeout_ms(int, optional): Request timeout in milliseconds (default: 12000)
get_recommendations_for_weave_sync()
Synchronous version ofget_recommendations_for_weave(). Same parameters and return type.
Troubleshooting
No recommendations returned
Possible causes:- Query is too generic or vague
- 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_KEYis set in environment variables- API key is valid (check dashboard)
- No extra whitespace in the key value
Type errors
Solution:- Ensure Python 3.8 or higher
- Install type stubs if using mypy:
pip install types-httpx - Check that all required parameters are provided
Network/timeout errors
Check:- Server has internet access
- No firewall blocking outbound requests
- Network is stable
- Increase timeout:
timeout_ms=60000 - 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-python, fetch recommendations, and pass them to your LLM for natural weaving into responses.