Medusa v2 plugin to generate AI-powered product descriptions via OpenRouter.
AI-powered product & category description generator plugin for MedusaJS v2.
This plugin uses AI (via OpenRouter) to generate SEO-optimized descriptions for products and categories in Spanish. It adds widgets on the product and category detail pages, plus a dedicated admin page for batch operations and cache management.
npm install medusa-plugin-product-description
Add the following to your Medusa project's file:
1OPENROUTER_API_KEY=sk-or-v1-your-key-here2OPENROUTER_MODEL=google/gemma-3-12b-it:free3OPENROUTER_SITE_URL=https://your-store.com4OPENROUTER_APP_NAME=Your Store Admin5STOREFRONT_URL=https://your-storefront.com6AI_DESCRIPTION_PROMPT=Genera una descripcion atractiva, natural y optimizada para SEO sobre el producto "{productTitle}". ...7AI_CATEGORY_PROMPT=Escribe una descripcion breve, natural y optimizada para SEO en Markdown sobre la categoria **{categoryName}**. ...
| Variable | Required | Default | Description |
|---|---|---|---|
| Yes | — | OpenRouter API key (sign up at openrouter.ai) | |
| No | Model to use. Browse models | ||
| No | — | Your site URL (sent as header) | |
| No | Your app name (sent as header) | ||
| No | — | Your storefront base URL for cache revalidation (e.g. ) | |
| No | Default prompt (see below) | Prompt template for products. Use as placeholder | |
| No | Default prompt (see below) | Prompt template for categories. Use as placeholder |
Default product prompt:
Default category prompt:
In your , register the plugin:
1import { defineConfig } from "@medusajs/framework/config"23export default defineConfig({4 plugins: [5 {6 resolve: "medusa-plugin-product-description",7 options: {},8 },9 ],10})
The plugin injects widgets directly into the Medusa admin:
Navigate to IA Descripciones in the sidebar for advanced operations:
Individual generation:
Batch generation:
Cache management:
If you're using a Next.js storefront, this plugin calls to revalidate the ISR cache. Add this endpoint:
1// frontend/src/app/api/revalidate/route.ts2import { revalidateTag } from "next/cache"3import { NextRequest, NextResponse } from "next/server"45export async function GET(request: NextRequest) {6 const tag = request.nextUrl.searchParams.get("tags") || "products"7 revalidateTag(tag)8 return NextResponse.json({ revalidated: true, tag })9}
Generate a product description.
Request:
{ "productId": "prod_01JABC...", "productTitle": "Paracetamol 650mg" }
Response:
{ "description": "## Paracetamol 650mg\n\nAlivia el dolor y la fiebre con..." }
Generate a category description. Optionally include sibling category names for context.
Request:
1{2 "categoryId": "pcat_01JABC...",3 "categoryName": "Analgesicos",4 "relatedCategories": ["Antiinflamatorios", "Antigripales"]5}
Response:
{ "description": "## Analgesicos\n\nEncuentra los mejores analgesicos..." }
Trigger cache revalidation on the storefront. Requires environment variable.
Request:
{ "tags": "products" }
Response:
{ "revalidated": true, "tags": "products" }
1# Install dependencies2npm install34# Build the plugin5npm run build67# Watch mode (for local plugin development)8npm run dev
1# From your plugin directory2npm run dev34# In your Medusa project directory:5npx medusa plugin:add ../path-to/medusa-plugin-product-description
1npx medusa plugin:build2npm publish
To publish an update:
1npm version patch # or minor / major2npx medusa plugin:build3npm publish
MIT