Skip to main content

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
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

  • Python 3.8 or higher
  • API key from AdMesh dashboard
  • Full type hints included
  • Works with FastAPI, Flask, Django, etc.

Installation Methods

pip (recommended):
Poetry:
pipenv:

Core Concepts

AdMeshClient

The main client for fetching recommendations. Initialize once and reuse across your application.
Configuration options:
  • api_key (required): Your AdMesh API key from the dashboard
  • api_base_url (optional): Custom API endpoint (defaults to production)

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. These IDs must be provided by the frontend.

Basic Usage

Synchronous Usage


Integration Examples

FastAPI Example

Flask Example


Environment Variables

Store your API key securely using environment variables:

API Methods

get_recommendations_for_weave()

Fetches recommendations for a given query that can be woven into LLM responses.
Note: HTTP timeout is automatically calculated from latency_budget_ms when provided: max(latency_budget_ms * 3, 30000). This ensures the HTTP request doesn’t timeout before the auction completes. If latency_budget_ms is not provided, defaults to 30 seconds or timeout_ms if specified. Format Filtering: This method only returns recommendations with “weave” format. If the recommendation format is not “weave”, the method returns {"found": False, "error": "Preferred format is not weave"}. Example:
Returns:

get_recommendations_for_weave_sync()

Synchronous version of get_recommendations_for_weave(). Same parameters and return type.

Troubleshooting

No recommendations returned

Possible causes:
  • Query is too generic (try more specific queries)
  • No active campaigns match the query
  • API key is invalid
  • Format is not “weave” (SDK only returns “weave” format recommendations)
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
  • Note: If format is not “weave”, the SDK returns {"found": False, "error": "Preferred format is not weave"}

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:

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