---
updatedAt: 2026-03-30T12:47:51.000Z
agentTools:
  projectIndex: https://docs.getembed.ai/llms.txt
---

# Generate

Generate personalized onchain stories about market activity, significant bets, and price movements.

This endpoint creates narrative-driven content about Polymarket activity tailored to a specific user's wallet and interests. Stories are generated from multiple data sources:

**Story Types**:
- **New Markets** (`new_market`): Recently created prediction markets relevant to the user
- **Significant Bets** (`user_markets_bets`, `relevant_markets_bets`, `bet`): Large bets on markets the user participates in or related markets discovered via graph analysis
- **Price Changes** (`price_change`): Markets experiencing significant price movements, with optional AI-generated commentary explaining the change
- **Relevant Markets** (`relevant_market`): Markets related to user's activity without recent bet or price activity

**Engines**:
- **polymarket_v1**: Multi-source, modular story generation with granular control over each story type. Configure time windows, minimum bet amounts, and result counts independently for each source.
- **polymarket_v2**: Simplified, unified approach combining all signals into a single ranked story feed. Just specify `num_stories` and `new_market_hours`.

**Data Sources**:
- Elasticsearch: Market metadata, price changes, new markets
- Neo4j: Bet graph, user relationships, market connections
- DynamoDB: Market details, bet history, price change events


# OpenAPI definition

```json
{
  "openapi": "3.0.1",
  "info": {
    "title": "Studio APIs",
    "version": "1.0.0",
    "description": "The Studio APIs are the building-block services developers use to construct personalized feeds. Each endpoint handles one stage of the feed pipeline, and they are designed to be composed together:\n\n1. **Search** — Generate candidate items from Elasticsearch indices (Farcaster, Polymarket, Zora, Kalshi, Token) using filters, boosting, or semantic similarity.\n2. **Features** — Enrich candidates with ML-computed features (semantic similarity, topic matching, composite scores) based on a user profile.\n3. **Scoring** — Rerank candidates using trained ML models for personalized ordering.\n4. **Ranking** — Apply a 3-stage post-processing pipeline (sort, diversity, limits-by-field) to produce the final feed.\n5. **Stories** — Generate personalized narrative-driven content about market activity, bets, and price movements.\n\nThe typical flow is: **Search → Features → Scoring → Ranking**, with Stories as an optional parallel path for narrative content.\n\nThe [Algorithm DSL](https://www.npmjs.com/package/algo-dsl) wraps these endpoints with a fluent builder API, but you can also call them directly via REST.\n",
    "contact": {
      "name": "embed Team",
      "url": "https://www.mbd.xyz"
    },
    "license": {
      "name": "MIT"
    }
  },
  "servers": [
    {
      "url": "https://api.mbd.xyz/v3/studio",
      "description": "embed Studio API"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Stories",
      "description": "## Overview\n\nThe Stories service generates personalized narrative-driven content about Polymarket activity — new markets, significant bets, price movements, and relevant markets — tailored to a specific user's wallet.\n\n## Key Concepts\n\n- **Story Types**: `new_market` (recently created markets), `user_markets_bets` / `relevant_markets_bets` / `bet` (significant bets), `price_change` (markets with notable price movements, with optional AI commentary), `relevant_market` (markets related to user activity).\n- **Engines**: `polymarket_v1` provides multi-source modular generation with granular control over each story type. `polymarket_v2` provides a simplified unified approach combining all signals into a single ranked story feed.\n- **Data Sources**: Stories are assembled from Elasticsearch (market metadata, price changes), Neo4j (bet graph, user relationships), and DynamoDB (market details, bet history).\n\n## Usage\n\nChoose an engine and provide the user's wallet address plus engine-specific parameters. V1 gives you fine-grained control over each story type (time windows, minimum bet amounts, result counts). V2 provides a simpler interface with just `num_stories` and `new_market_hours`.\n"
    }
  ],
  "paths": {
    "/stories/generate": {
      "post": {
        "operationId": "generateStories",
        "tags": [
          "Stories"
        ],
        "summary": "Generate",
        "description": "Generate personalized onchain stories about market activity, significant bets, and price movements.\n\nThis endpoint creates narrative-driven content about Polymarket activity tailored to a specific user's wallet and interests. Stories are generated from multiple data sources:\n\n**Story Types**:\n- **New Markets** (`new_market`): Recently created prediction markets relevant to the user\n- **Significant Bets** (`user_markets_bets`, `relevant_markets_bets`, `bet`): Large bets on markets the user participates in or related markets discovered via graph analysis\n- **Price Changes** (`price_change`): Markets experiencing significant price movements, with optional AI-generated commentary explaining the change\n- **Relevant Markets** (`relevant_market`): Markets related to user's activity without recent bet or price activity\n\n**Engines**:\n- **polymarket_v1**: Multi-source, modular story generation with granular control over each story type. Configure time windows, minimum bet amounts, and result counts independently for each source.\n- **polymarket_v2**: Simplified, unified approach combining all signals into a single ranked story feed. Just specify `num_stories` and `new_market_hours`.\n\n**Data Sources**:\n- Elasticsearch: Market metadata, price changes, new markets\n- Neo4j: Bet graph, user relationships, market connections\n- DynamoDB: Market details, bet history, price change events\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StoriesGenerateRequest"
              },
              "examples": {
                "v1_comprehensive": {
                  "summary": "V1 engine with all story types enabled",
                  "value": {
                    "engine": "polymarket_v1",
                    "params": {
                      "wallet": "0xea80ca47759ef8af31229b360848c62d98ae35fb",
                      "new_markets": {
                        "hours": 24,
                        "size": 5
                      },
                      "user_markets_bets": {
                        "min_bet_amount": 100,
                        "hours": 24,
                        "size": 10
                      },
                      "relevant_markets_bets": {
                        "min_bet_amount": 100,
                        "hours": 24,
                        "size": 5
                      },
                      "relevant_markets_price_change": {
                        "threshold": 5,
                        "size": 3
                      }
                    }
                  }
                },
                "v2_simplified": {
                  "summary": "V2 engine with default personalized generation",
                  "value": {
                    "engine": "polymarket_v2",
                    "params": {
                      "wallet": "0x2222222222222222222222222222222222222222",
                      "num_stories": 25,
                      "new_market_hours": 24
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully generated personalized stories",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StoriesGenerateResponse"
                },
                "examples": {
                  "success_mixed": {
                    "summary": "Response with mixed story types",
                    "value": {
                      "stories": [
                        {
                          "type": "new_market",
                          "market": {
                            "item_id": "0x123abc",
                            "question": "Will Ethereum close above $2000?",
                            "outcomes": [
                              "YES",
                              "NO"
                            ],
                            "outcome_prices": [
                              0.65,
                              0.35
                            ],
                            "created_at": "2024-01-15T10:30:00Z"
                          }
                        },
                        {
                          "type": "user_markets_bets",
                          "market": {
                            "item_id": "0x456def",
                            "question": "Bitcoin spot ETF approval by June 2024?"
                          },
                          "bet": {
                            "amount": 1000,
                            "usdc": 1000,
                            "side": "BUY",
                            "timestamp": "2024-01-14T15:45:00Z"
                          }
                        },
                        {
                          "type": "price_change",
                          "market": {
                            "item_id": "0x789ghi",
                            "question": "Will Trump be elected in 2024?",
                            "outcome_prices": [
                              0.72,
                              0.28
                            ],
                            "one_hour_price_change": [
                              5.2,
                              -5.2
                            ]
                          },
                          "llm": "YES outcome price increased by 5.2% in the last hour, indicating stronger market confidence."
                        }
                      ],
                      "metrics": {
                        "newm_hits": 8,
                        "newm_took_es": 35,
                        "um_bets_count": 5,
                        "um_bets_took_neo4j": 120,
                        "took_backend": 850
                      },
                      "errors": []
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StoriesGenerateError"
                },
                "examples": {
                  "invalid_engine": {
                    "summary": "Invalid engine specified",
                    "value": {
                      "error": "Engine invalid_engine not found"
                    }
                  },
                  "missing_wallet": {
                    "summary": "Missing wallet in params",
                    "value": {
                      "error": "wallet is required"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - missing or invalid API token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StoriesGenerateError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "Console API key. Use `Bearer mbd-{your-api-key}`."
      }
    },
    "schemas": {
      "StoriesGenerateRequest": {
        "type": "object",
        "required": [
          "engine",
          "params"
        ],
        "description": "Request payload for the Stories generation endpoint. Choose an engine and provide engine-specific parameters.\n\n**polymarket_v1** (multi-source):\n- Granular control over each story type (new markets, bets, price changes)\n- Configure time windows, minimum bet amounts, and result counts independently\n\n**polymarket_v2** (simplified):\n- Unified approach combining all signals\n- Just specify `num_stories` and `new_market_hours`\n",
        "properties": {
          "engine": {
            "type": "string",
            "description": "Story generation engine to use.\n\n- `polymarket_v1`: Multi-source modular generation with granular control over each story type\n- `polymarket_v2`: Simplified unified approach combining all signals into a single ranked feed\n",
            "enum": [
              "polymarket_v1",
              "polymarket_v2"
            ],
            "example": "polymarket_v2"
          },
          "params": {
            "description": "Engine-specific parameters. Use `StoriesV1Params` for `polymarket_v1` or `StoriesV2Params` for `polymarket_v2`.",
            "oneOf": [
              {
                "$ref": "#/components/schemas/StoriesV1Params"
              },
              {
                "$ref": "#/components/schemas/StoriesV2Params"
              }
            ]
          }
        }
      },
      "StoriesV1Params": {
        "type": "object",
        "required": [
          "wallet"
        ],
        "description": "Parameters for the `polymarket_v1` engine. Provides granular control over each story source: new markets, user market bets, relevant market bets, and price changes.",
        "properties": {
          "wallet": {
            "type": "string",
            "description": "Wallet address for the user generating stories",
            "example": "0xea80ca47759ef8af31229b360848c62d98ae35fb"
          },
          "new_markets": {
            "type": "object",
            "description": "Configuration for discovering newly created markets",
            "required": [
              "hours",
              "size"
            ],
            "properties": {
              "hours": {
                "type": "integer",
                "description": "Look back window in hours",
                "minimum": 1,
                "example": 24
              },
              "size": {
                "type": "integer",
                "description": "Maximum number of new market stories to return (0 to disable)",
                "minimum": 0,
                "example": 5
              }
            }
          },
          "user_markets_bets": {
            "type": "object",
            "description": "Configuration for finding significant bets on markets where the user is active",
            "required": [
              "min_bet_amount",
              "hours",
              "size"
            ],
            "properties": {
              "min_bet_amount": {
                "type": "number",
                "description": "Minimum bet amount (USDC) to consider significant",
                "minimum": 0,
                "example": 100
              },
              "hours": {
                "type": "integer",
                "description": "Look back window in hours",
                "minimum": 1,
                "example": 24
              },
              "size": {
                "type": "integer",
                "description": "Maximum number of stories to return",
                "minimum": 0,
                "example": 10
              }
            }
          },
          "relevant_markets_bets": {
            "type": "object",
            "description": "Configuration for finding significant bets on relevant markets (discovered via graph analysis)",
            "required": [
              "min_bet_amount",
              "hours",
              "size"
            ],
            "properties": {
              "min_bet_amount": {
                "type": "number",
                "description": "Minimum bet amount (USDC) to consider significant",
                "minimum": 0,
                "example": 100
              },
              "hours": {
                "type": "integer",
                "description": "Look back window in hours",
                "minimum": 1,
                "example": 24
              },
              "size": {
                "type": "integer",
                "description": "Maximum number of stories to return",
                "minimum": 0,
                "example": 5
              }
            }
          },
          "relevant_markets_price_change": {
            "type": "object",
            "description": "Configuration for finding relevant markets with significant price changes",
            "required": [
              "threshold",
              "size"
            ],
            "properties": {
              "threshold": {
                "type": "number",
                "description": "Price change percentage threshold (e.g., 5.0 for 5%)",
                "minimum": 0,
                "example": 5
              },
              "size": {
                "type": "integer",
                "description": "Maximum number of stories to return",
                "minimum": 0,
                "example": 3
              }
            }
          }
        }
      },
      "StoriesV2Params": {
        "type": "object",
        "required": [
          "wallet"
        ],
        "description": "Parameters for the `polymarket_v2` engine. Simplified interface that combines all story signals into a single ranked feed.",
        "properties": {
          "wallet": {
            "type": "string",
            "description": "Wallet address for the user generating stories",
            "example": "0xea80ca47759ef8af31229b360848c62d98ae35fb"
          },
          "num_stories": {
            "type": "integer",
            "description": "Number of stories to generate",
            "default": 25,
            "minimum": 1,
            "maximum": 100,
            "example": 25
          },
          "new_market_hours": {
            "type": "integer",
            "description": "Look back window in hours for identifying new markets",
            "default": 24,
            "minimum": 1,
            "example": 24
          }
        }
      },
      "StoriesGenerateResponse": {
        "type": "object",
        "description": "Response containing generated stories, performance metrics, and any errors encountered during generation.",
        "properties": {
          "stories": {
            "type": "array",
            "description": "Generated onchain stories. Each story has a `type` field and type-specific data.",
            "items": {
              "oneOf": [
                {
                  "$ref": "#/components/schemas/StoryNewMarket"
                },
                {
                  "$ref": "#/components/schemas/StoryBet"
                },
                {
                  "$ref": "#/components/schemas/StoryPriceChange"
                },
                {
                  "$ref": "#/components/schemas/StoryRelevantMarket"
                }
              ]
            }
          },
          "metrics": {
            "type": "object",
            "description": "Performance metrics for story generation. Fields present depend on the engine used.",
            "additionalProperties": true,
            "properties": {
              "newm_hits": {
                "type": "integer",
                "description": "Total new market matches found (v1)",
                "example": 42
              },
              "newm_took_es": {
                "type": "integer",
                "description": "ES query time for new markets (ms, v1)",
                "example": 35
              },
              "newm_took_es_roundtrip": {
                "type": "integer",
                "description": "ES roundtrip time for new markets (ms, v1)",
                "example": 42
              },
              "um_bets_count": {
                "type": "integer",
                "description": "Significant bets found on user's markets (v1)",
                "example": 8
              },
              "um_bets_took_neo4j": {
                "type": "integer",
                "description": "Neo4j query time for user market bets (ms, v1)",
                "example": 120
              },
              "relm_bets_count": {
                "type": "integer",
                "description": "Significant bets found on relevant markets (v1)",
                "example": 12
              },
              "relm_bets_took_neo4j": {
                "type": "integer",
                "description": "Neo4j query time for relevant market bets (ms, v1)",
                "example": 150
              },
              "pc_hits": {
                "type": "integer",
                "description": "Markets with significant price changes (v1)",
                "example": 5
              },
              "pc_took_es": {
                "type": "integer",
                "description": "ES query time for price changes (ms, v1)",
                "example": 28
              },
              "pc_took_llm": {
                "type": "integer",
                "description": "Total LLM processing time for price change stories (ms, v1)",
                "example": 450
              },
              "pc_took_llm_per_story": {
                "type": "number",
                "description": "Average LLM time per price change story (ms, v1)",
                "example": 90
              },
              "hits": {
                "type": "integer",
                "description": "Total markets found (v2)",
                "example": 25
              },
              "took_es": {
                "type": "integer",
                "description": "ES query time (ms, v2)",
                "example": 45
              },
              "took_es_roundtrip": {
                "type": "integer",
                "description": "ES roundtrip time (ms, v2)",
                "example": 52
              },
              "took_dynamodb": {
                "type": "integer",
                "description": "DynamoDB fetch time (ms, v2)",
                "example": 200
              },
              "took_backend": {
                "type": "integer",
                "description": "Total end-to-end generation time (ms)",
                "example": 850
              }
            }
          },
          "errors": {
            "type": "array",
            "description": "Errors encountered during story generation (empty array on success)",
            "items": {
              "type": "string"
            },
            "example": []
          }
        }
      },
      "StoryNewMarket": {
        "type": "object",
        "required": [
          "type",
          "market"
        ],
        "description": "Story about a newly created prediction market.",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "new_market"
            ],
            "example": "new_market"
          },
          "market": {
            "type": "object",
            "description": "Market data from Elasticsearch/Polymarket",
            "additionalProperties": true,
            "properties": {
              "item_id": {
                "type": "string",
                "example": "0x123abc"
              },
              "question": {
                "type": "string",
                "example": "Will Ethereum close above $2000 by end of 2024?"
              },
              "description": {
                "type": "string"
              },
              "outcomes": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "example": [
                  "YES",
                  "NO"
                ]
              },
              "outcome_prices": {
                "type": "array",
                "items": {
                  "type": "number"
                },
                "example": [
                  0.65,
                  0.35
                ]
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      },
      "StoryBet": {
        "type": "object",
        "required": [
          "type",
          "market",
          "bet"
        ],
        "description": "Story about a significant bet on a market. The `type` field indicates the bet source:\n- `user_markets_bets`: Bet on a market the user participates in (v1)\n- `relevant_markets_bets`: Bet on a related market discovered via graph analysis (v1)\n- `bet`: Generic bet story (v2)\n",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "user_markets_bets",
              "relevant_markets_bets",
              "bet"
            ],
            "example": "user_markets_bets"
          },
          "market": {
            "type": "object",
            "description": "Market data",
            "additionalProperties": true
          },
          "bet": {
            "type": "object",
            "description": "Bet details",
            "additionalProperties": true,
            "properties": {
              "amount": {
                "type": "number",
                "description": "Bet amount in USDC",
                "example": 500
              },
              "usdc": {
                "type": "number",
                "description": "USDC value of the bet",
                "example": 500
              },
              "side": {
                "type": "string",
                "enum": [
                  "BUY",
                  "SELL"
                ],
                "description": "Bet direction",
                "example": "BUY"
              },
              "timestamp": {
                "type": "string",
                "format": "date-time",
                "description": "When the bet was placed"
              }
            }
          },
          "wallet": {
            "type": "object",
            "description": "Wallet/user who made the bet",
            "additionalProperties": true
          }
        }
      },
      "StoryPriceChange": {
        "type": "object",
        "required": [
          "type",
          "market"
        ],
        "description": "Story about a significant price change in a prediction market. May include AI-generated commentary (via the `llm` field) explaining the price movement.",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "price_change"
            ],
            "example": "price_change"
          },
          "market": {
            "type": "object",
            "description": "Market data including price change information",
            "additionalProperties": true,
            "properties": {
              "item_id": {
                "type": "string",
                "example": "0x456def"
              },
              "question": {
                "type": "string"
              },
              "outcome_prices": {
                "type": "array",
                "items": {
                  "type": "number"
                },
                "example": [
                  0.72,
                  0.28
                ]
              },
              "one_hour_price_change": {
                "type": "array",
                "items": {
                  "type": "number"
                },
                "description": "Price change percentage for each outcome in the last hour",
                "example": [
                  5.2,
                  -5.2
                ]
              }
            }
          },
          "price_change": {
            "type": "object",
            "description": "Price change event details (v2 engine)",
            "additionalProperties": true,
            "properties": {
              "timestamp": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "llm": {
            "type": "string",
            "description": "AI-generated commentary about the price change",
            "example": "YES outcome price increased significantly by 5.2%, indicating increased market confidence."
          }
        }
      },
      "StoryRelevantMarket": {
        "type": "object",
        "required": [
          "type",
          "market"
        ],
        "description": "Story about a relevant market related to user's activity without recent bet or price activity.",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "relevant_market"
            ],
            "example": "relevant_market"
          },
          "market": {
            "type": "object",
            "description": "Relevant market data",
            "additionalProperties": true
          }
        }
      },
      "StoriesGenerateError": {
        "type": "object",
        "description": "Error response from the Stories service.",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error description",
            "example": "wallet is required"
          }
        }
      }
    }
  }
}
```